Skip to content

Commit

Permalink
feat: add support for cell data type
Browse files Browse the repository at this point in the history
* It depends on `@tact-lang/compiler` > v1.4.0
  • Loading branch information
rahulyadav-57 committed Aug 8, 2024
1 parent d473b20 commit 35fc6e1
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 13 deletions.
5 changes: 3 additions & 2 deletions src/components/workspace/ABIUi/TactABIUi.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
Tree,
} from '@/interfaces/workspace.interface';
import { parseInputs } from '@/utility/abi';
import { isIncludesTypeCell } from '@/utility/utils';
import { isIncludesTypeCellOrSlice } from '@/utility/utils';
import { MinusCircleOutlined } from '@ant-design/icons';
import { Address, TupleItem } from '@ton/core';
import { SandboxContract } from '@ton/sandbox';
Expand Down Expand Up @@ -95,6 +95,7 @@ function FieldItem(
case 'bool':
return <Switch />;
case 'cell':
case 'slice':
return (
<Select placeholder="Select a TS file" allowClear>
{renderFilesForCell()}
Expand Down Expand Up @@ -334,7 +335,7 @@ const TactABIUi: FC<TactABI> = ({
const onSubmit = async (formValues: TactInputFields, fieldName: string) => {
try {
let tsProjectFiles = {};
if (isIncludesTypeCell(formValues)) {
if (isIncludesTypeCellOrSlice(formValues)) {
tsProjectFiles = await getAllFilesWithContent(
projectId as string,
(file) =>
Expand Down
4 changes: 2 additions & 2 deletions src/components/workspace/BuildProject/BuildProject.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { buildTs } from '@/utility/typescriptHelper';
import {
delay,
getFileExtension,
isIncludesTypeCell,
isIncludesTypeCellOrSlice,
tonHttpEndpoint,
} from '@/utility/utils';
import { Network } from '@orbs-network/ton-access';
Expand Down Expand Up @@ -225,7 +225,7 @@ const BuildProject: FC<Props> = ({ projectId, contract, updateContract }) => {
delete tempFormValues.contract;

let tsProjectFiles = {};
if (isIncludesTypeCell(tempFormValues)) {
if (isIncludesTypeCellOrSlice(tempFormValues)) {
tsProjectFiles = await getAllFilesWithContent(
projectId,
(file) =>
Expand Down
8 changes: 2 additions & 6 deletions src/utility/abi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@ export async function parseInputs(
throw new Error(`Parsing failed for ${key}: ${value}`);
}
case 'cell':
case 'slice':
return await generateCell(value as string, files);
case 'address':
return Address.parse(value as string);
Expand Down Expand Up @@ -367,13 +368,9 @@ async function generateCell(
) {
files['ide__cell.ts'] = `
import exported__cell from "./${rootFilePath}"; window.exported__cell = exported__cell;`;
// files['ide__cell.ts'] = `import exported__cell from "./cellFile.ts";
// window.exported__cell = exported__cell;`;

let jsOutout: RenderedChunk[] | string = await buildTs(files, 'ide__cell.ts');

console.log('jsOutout', jsOutout);

jsOutout = (jsOutout as OutputChunk[])[0].code
.replace(/import\s*{/g, 'const {')
.replace(/}\s*from\s*'@ton\/core';/, '} = window.TonCore;')
Expand All @@ -385,6 +382,5 @@ async function generateCell(
return window.exported__cell
} return main()`;
// eslint-disable-next-line @typescript-eslint/no-implied-eval
const cell = await new Function(_code)();
return cell;
return new Function(_code)();
}
6 changes: 3 additions & 3 deletions src/utility/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,15 +194,15 @@ export const tonHttpEndpoint = ({ network }: Config) => {
* @returns boolean
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function isIncludesTypeCell(obj: Record<string, any>): boolean {
export function isIncludesTypeCellOrSlice(obj: Record<string, any>): boolean {
for (const key in obj) {
if (Object.prototype.hasOwnProperty.call(obj, key)) {
if (key === 'type' && obj[key] === 'cell') {
if (key === 'type' && (obj[key] === 'cell' || obj[key] === 'slice')) {
return true;
}

if (typeof obj[key] === 'object' && obj[key] !== null) {
if (isIncludesTypeCell(obj[key])) {
if (isIncludesTypeCellOrSlice(obj[key])) {
return true;
}
}
Expand Down

0 comments on commit 35fc6e1

Please sign in to comment.