diff --git a/public/html/tonweb.html b/public/html/tonweb.html index fe0ebe8..6a40f0a 100644 --- a/public/html/tonweb.html +++ b/public/html/tonweb.html @@ -31,7 +31,7 @@ let contractName = event.data?.contractName; _code = `async function main() { ${event.data.code} - const contractInit = await TactCounter.fromInit(${event.data.initParams}); + const contractInit = await ${contractName}.fromInit(${event.data.initParams}); window.contractInit = contractInit; return contractInit; } main()`; diff --git a/src/components/shared/Layout/Layout.tsx b/src/components/shared/Layout/Layout.tsx index c8d6329..ea12bee 100644 --- a/src/components/shared/Layout/Layout.tsx +++ b/src/components/shared/Layout/Layout.tsx @@ -1,6 +1,5 @@ import { useUserOnboardingAction } from '@/hooks/userOnboarding.hooks'; import { FC, useEffect, useState } from 'react'; -import UserOnboardingWizard from '../UserOnboardingWizard'; import s from './Layout.module.scss'; interface Props { @@ -19,7 +18,7 @@ export const Layout: FC = ({ className = '', children }) => { } return ( <> - + {/* */}
| null; language?: ContractLanguage; + type: 'Getter' | 'Setter'; } const ABIUi: FC = ({ abi, @@ -25,6 +26,7 @@ const ABIUi: FC = ({ network, contract = null, language = 'func', + type, }) => { const possiblesTypes = abi.parameters.map((item) => { if (['cell', 'slice'].includes(item.type)) { @@ -36,17 +38,25 @@ const ABIUi: FC = ({ const [isLoading, setIsLoading] = useState(false); const { createLog } = useLogActivity(); - const { callGetter } = useContractAction(); + const { callGetter, callSetter } = useContractAction(); const onSubmit = async (formValues: any) => { let stack = Object.values(formValues).map((param: any) => { - const { type, value } = Object.values(param)[0] as any; - return { type: type, value: value }; + const formField: any = Object.entries(param); + const { type, value } = formField[0][1]; + if (language === 'tact') { + return { type, value, name: formField[0][0] }; + } else { + const { type, value } = Object.values(param)[0] as any; + return { type: type, value: value }; + } }); try { setIsLoading(true); - const getterReponse = await callGetter( + const callableFunction = type === 'Getter' ? callGetter : callSetter; + + const getterReponse = await callableFunction( contractAddress, abi.name, contract as any, diff --git a/src/components/workspace/BuildProject/BuildProject.tsx b/src/components/workspace/BuildProject/BuildProject.tsx index 830db2e..2cf068c 100644 --- a/src/components/workspace/BuildProject/BuildProject.tsx +++ b/src/components/workspace/BuildProject/BuildProject.tsx @@ -86,6 +86,7 @@ const BuildProject: FC = ({ await createStateInitCell(initParams); } catch (error: any) { setIsLoading(''); + console.log(error, 'error'); if (typeof error === 'string') { createLog(error, 'error'); return; @@ -162,6 +163,10 @@ const BuildProject: FC = ({ let jsOutout = [{ code: '' }]; if (activeProject?.language == 'tact') { + const contractScript = activeProject?.contractScript?.toString(); + if (!contractScript || typeof contractScript !== 'string') { + throw 'Build project built first'; + } jsOutout = await buildTs( { 'tact.ts': activeProject?.contractScript?.toString(), @@ -191,6 +196,20 @@ const BuildProject: FC = ({ .replace(/}\s+from\s.+/, '} = window.TonCore;') .replace(/^\s*export\s+\{[^}]*\};\s*/m, ''); + let contractName = activeProject?.contractName; + + if (activeProject?.language == 'tact') { + const _code = `async function main() { + ${finalJsoutput} + const contractInit = await ${contractName}.fromInit(${initParams}); + return contractInit; + } main()`; + const contractInit = await eval(_code); + (window as any).contractInit = contractInit; + deploy(); + return; + } + cellBuilderRef.current.contentWindow.postMessage( { name: 'nujan-ton-ide', @@ -203,14 +222,14 @@ const BuildProject: FC = ({ '*' ); } catch (error: any) { - // setIsLoading(''); - if (error.message.includes("'default' is not exported by ")) { + setIsLoading(''); + if (error?.message?.includes("'default' is not exported by ")) { throw "'default' is not exported by stateInit.cell.ts"; } - createLog( - 'Something went wrong. Check browser console for details.', - 'error' - ); + if (error?.message) { + createLog(error?.message, 'error'); + return; + } throw error; } }; @@ -348,8 +367,9 @@ const BuildProject: FC = ({ diff --git a/src/components/workspace/ContractInteraction/ContractInteraction.tsx b/src/components/workspace/ContractInteraction/ContractInteraction.tsx index 8be41ff..82973eb 100644 --- a/src/components/workspace/ContractInteraction/ContractInteraction.tsx +++ b/src/components/workspace/ContractInteraction/ContractInteraction.tsx @@ -176,13 +176,14 @@ const ContractInteraction: FC = ({ network={network} contract={contract} language={language} + type="Getter" /> ))} )}
-

Send internal message:

+

Send internal message: ({abi?.setters?.length || '-'})

{language !== 'tact' && ( <>

@@ -206,6 +207,21 @@ const ContractInteraction: FC = ({ )} + {abi && abi.setters.length > 0 && ( + <> + {abi.setters.map((item, i) => ( + + ))} + + )} ); }; diff --git a/src/hooks/contract.hooks.ts b/src/hooks/contract.hooks.ts index d281752..5e317b9 100644 --- a/src/hooks/contract.hooks.ts +++ b/src/hooks/contract.hooks.ts @@ -32,6 +32,7 @@ export function useContractAction() { return { deployContract, sendMessage, + callSetter, callGetter, }; async function deployContract( @@ -44,12 +45,10 @@ export function useContractAction() { let codeCell = Cell.fromBoc(Buffer.from(codeBOC, 'base64'))[0]; // Amount to send to contract. Gas fee - const value = toNano('0.002'); + const value = toNano('0.02'); let stateInit: StateInit = {}; - const cellBuilderRef = document.querySelector('.cell-builder-ref'); if (project.language === 'tact') { - const _contractInit = (cellBuilderRef as any)?.contentWindow - ?.contractInit; + const _contractInit = (window as any).contractInit; stateInit = { code: _contractInit.init.code, data: _contractInit.init.data, @@ -63,12 +62,8 @@ export function useContractAction() { if (network.toUpperCase() === 'SANDBOX' && sandboxBlockchain) { if (project.language === 'tact') { - const _contractInit = (cellBuilderRef as any)?.contentWindow - ?.contractInit; - + const _contractInit = (window as any).contractInit; const _userContract = sandboxBlockchain.openContract(_contractInit); - (window as any).userContract = _userContract; - // TODO: Handle last parameter i.e. message const sender = sandboxWallet!!.getSender(); const queryId = BigInt(0); @@ -88,24 +83,15 @@ export function useContractAction() { }; } } - const response = await _userContract.send( - sender, - { value: toNano(1) }, - messageParams - ); - const response1 = await _userContract.send( + const response = await _userContract.send( sender, - { value: toNano(1) }, { - $$type: 'Add', - queryId: BigInt(0), - amount: BigInt(5), - } + value, + }, + messageParams ); - const data = await _userContract.getCounter(); - return { address: _userContract.address.toString(), contract: _userContract, @@ -204,6 +190,42 @@ export function useContractAction() { } } + async function callSetter( + contractAddress: string, + methodName: string, + contract: SandboxContract | null = null, + language: ContractLanguage, + stack?: TupleItem[], + network?: Network | Partial + ) { + if (network === 'SANDBOX' && contract) { + const { sandboxWallet } = globalWorkspace; + + const sender = sandboxWallet!!.getSender(); + + let messageParams = { + $$type: methodName, + }; + stack?.forEach((item: any) => { + messageParams = { + ...messageParams, + [item.name]: BigInt(item.value), + }; + }); + + if (language === 'tact') { + const response = await (contract as any).send( + sender, + { value: toNano('0.02') }, + messageParams + ); + return { message: 'Message sent successfully' }; + } else { + } + return; + } + } + async function callGetter( contractAddress: string, methodName: string, @@ -235,7 +257,6 @@ export function useContractAction() { }; } }); - if (network === 'SANDBOX' && contract) { let responseValues = []; if (language === 'tact') { diff --git a/src/hooks/project.hooks.ts b/src/hooks/project.hooks.ts index 13bd9a7..aeb3608 100644 --- a/src/hooks/project.hooks.ts +++ b/src/hooks/project.hooks.ts @@ -212,19 +212,35 @@ export function useProjectActions() { return { name: parameter.name, type: parameter.type, + format: parameter.format, + optional: parameter.optional, }; }), }; }); - const setters = (output.abi as any)?.receivers?.map((item: any) => { - let fields = []; + let setters: any = []; + (output.abi as any)?.receivers?.forEach((item: any) => { + if (item.message.type === 'Deploy') { + return; + } if (item.message.type) { - fields = (output.abi as any).types.find( + const singleItem = (output.abi as any).types.find( (type: any) => type.name === item.message.type ); + const singleField = { + name: singleItem.name, + parameters: singleItem.fields.map((parameter: any) => { + return { + name: parameter.name, + type: parameter.type.type, + format: parameter.type.format, + optional: parameter.type.optional, + }; + }), + }; + setters.push(singleField); } - return fields; }); let ctx = new CompilerContext({ shared: {} });