Skip to content

Commit

Permalink
feat: support Slice in receive and improve String handling
Browse files Browse the repository at this point in the history
  • Loading branch information
rahulyadav-57 committed Feb 24, 2025
1 parent 2c782ed commit 6dda15a
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 21 deletions.
18 changes: 4 additions & 14 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"@orbs-network/ton-access": "^2.3.0",
"@tact-lang/compiler": "^1.5.3",
"@ton-community/func-js": "^0.5.0",
"@ton/core": "^0.56.3",
"@ton/core": "^0.58.1",
"@ton/sandbox": "^0.20.0",
"@ton/ton": "^13.11.1",
"@tonconnect/ui-react": "1.0.0-beta.4",
Expand Down
4 changes: 4 additions & 0 deletions src/components/workspace/ABIUi/ABIUi.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -166,3 +166,7 @@
}
}
}

.sliceInput {
margin-bottom: 0.5rem;
}
6 changes: 5 additions & 1 deletion src/components/workspace/ABIUi/TactABIUi.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ function FieldItem(
{renderFilesForCell()}
</Select>
);
case 'any':
return (
<Input.TextArea className={s.sliceInput} placeholder={placeholder} />
);
default:
return (
<Input
Expand Down Expand Up @@ -328,7 +332,7 @@ const TactABIUi: FC<TactABI> = ({

const getItemHeading = (item: TactType) => {
if (item.type?.kind === 'simple') {
if (item.type.type === 'text') {
if (item.type.type === 'text' && item.name !== 'String') {
return `"${item.name}"`;
}
}
Expand Down
21 changes: 16 additions & 5 deletions src/utility/abi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
TactInputFields,
} from '@/interfaces/workspace.interface';
import { CompilerContext } from '@tact-lang/compiler/dist/context';
import { parseAndEvalExpression } from '@tact-lang/compiler/dist/interpreter';
import { getType } from '@tact-lang/compiler/dist/types/resolveDescriptors';

import {
Expand Down Expand Up @@ -92,8 +93,7 @@ export class ABIParser {
.filter(
(item) =>
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(item.message as any).type !== 'Deploy' &&
item.message.kind !== 'any',
(item.message as any).type !== 'Deploy',
)
.map((receiver) => {
let argumentName: string;
Expand All @@ -103,10 +103,10 @@ export class ABIParser {
argumentName = receiver.message.type;
break;
case 'text':
argumentName = receiver.message.text ?? '';
argumentName = receiver.message.text ?? 'String';
break;
case 'any':
argumentName = 'any';
argumentName = 'Slice';
break;
case 'empty':
argumentName = 'empty';
Expand All @@ -116,6 +116,8 @@ export class ABIParser {
break;
}

const nonDefaultArguments = ['String', 'Slice'];

if (receiver.message.kind !== 'typed') {
return {
name: argumentName,
Expand All @@ -130,7 +132,9 @@ export class ABIParser {
type: {
kind: 'simple',
type: receiver.message.kind,
defaultValue: argumentName,
defaultValue: nonDefaultArguments.includes(argumentName)
? null
: argumentName,
},
},
],
Expand Down Expand Up @@ -318,6 +322,13 @@ export async function parseInputs(
return value;
case 'text':
return value;
case 'any': {
const parsedExpression = parseAndEvalExpression(value as string);
if (parsedExpression.kind === 'ok') {
return parsedExpression.value;
}
throw new Error(parsedExpression.message);
}
case 'empty':
return null;
default:
Expand Down

0 comments on commit 6dda15a

Please sign in to comment.