diff --git a/src/components/workspace/BuildProject/BuildProject.module.scss b/src/components/workspace/BuildProject/BuildProject.module.scss index 27fb925..e83e15e 100644 --- a/src/components/workspace/BuildProject/BuildProject.module.scss +++ b/src/components/workspace/BuildProject/BuildProject.module.scss @@ -41,5 +41,6 @@ } .info { margin-top: 1rem; + font-size: 0.9rem; } } diff --git a/src/components/workspace/BuildProject/BuildProject.tsx b/src/components/workspace/BuildProject/BuildProject.tsx index c95281b..6cca8f1 100644 --- a/src/components/workspace/BuildProject/BuildProject.tsx +++ b/src/components/workspace/BuildProject/BuildProject.tsx @@ -18,12 +18,22 @@ import { FC, useEffect, useRef, useState } from 'react'; import { Cell } from 'ton-core'; import ContractInteraction from '../ContractInteraction'; import ExecuteFile from '../ExecuteFile/ExecuteFile'; +import OpenFile from '../OpenFile/OpenFile'; import s from './BuildProject.module.scss'; interface Props { projectId: string; onCodeCompile: (codeBOC: string) => void; + sandboxBlockchain: Blockchain; + contract: any; + updateContract: (contractInstance: any) => void; } -const BuildProject: FC = ({ projectId, onCodeCompile }) => { +const BuildProject: FC = ({ + projectId, + onCodeCompile, + sandboxBlockchain, + contract, + updateContract, +}) => { const [isLoading, setIsLoading] = useState(''); const { createLog } = useLogActivity(); const [environment, setEnvironment] = useState('SANDBOX'); @@ -34,10 +44,7 @@ const BuildProject: FC = ({ projectId, onCodeCompile }) => { const cellBuilderRef = useRef(null); const [tonConnector] = useTonConnectUI(); const chain = tonConnector.wallet?.account.chain; - const [sandboxBlockchain, setSandboxBlockchain] = useState( - null - ); - const [contract, setContract] = useState(''); + const [sandboxWallet, setSandboxWallet] = useState>(); @@ -102,7 +109,7 @@ const BuildProject: FC = ({ projectId, onCodeCompile }) => { return; } if (contract) { - setContract(contract); + updateContract(contract); } updateProjectById( @@ -160,24 +167,29 @@ const BuildProject: FC = ({ projectId, onCodeCompile }) => { } }; - const createSandbox = async () => { - if (sandboxBlockchain) { - return; + const isContractInteraction = () => { + let isValid = + activeProject?.id && tonConnector && activeProject?.contractAddress + ? true + : false; + + if (environment === 'SANDBOX') { + isValid = isValid && sandboxBlockchain ? true : false; } - const blockchain = await Blockchain.create(); - const wallet = await blockchain.treasury('user'); - createLog( - `Sanbox account created. Address: ${wallet.address.toString()}`, - 'info', - false - ); - setSandboxWallet(wallet); - setSandboxBlockchain(blockchain); + return isValid; }; useEffect(() => { if (environment === 'SANDBOX') { - createSandbox(); + (async () => { + const wallet = await sandboxBlockchain.treasury('user'); + createLog( + `Sandbox account created. Address: ${wallet.address.toString()}`, + 'info', + false + ); + setSandboxWallet(wallet); + })(); } }, []); @@ -243,12 +255,21 @@ const BuildProject: FC = ({ projectId, onCodeCompile }) => { {environment !== 'SANDBOX' && } +

+ 1. Update initial contract state in{' '} + {' '} +

+
{ if (environment == 'SANDBOX') { @@ -284,7 +305,7 @@ const BuildProject: FC = ({ projectId, onCodeCompile }) => {
)} - {activeProject?.id && tonConnector && activeProject?.contractAddress && ( + {isContractInteraction() && (
{ const [activeMenu, setActiveMenu] = useState('code'); const [isLoaded, setIsLoaded] = useState(false); const [isLoading, setIsloading] = useState(false); + const [sandboxBlockchain, setSandboxBlockchain] = useState( + null + ); + const [contract, setContract] = useState(''); const { id: projectId, tab } = router.query; @@ -35,10 +40,19 @@ const WorkSpace: FC = () => { workspaceAction.createNewItem('', name, type, projectId as string); }; + const createSandbox = async () => { + if (sandboxBlockchain) { + return; + } + const blockchain = await Blockchain.create(); + setSandboxBlockchain(blockchain); + }; + useEffect(() => { if (activeProject) { createLog(`Project '${activeProject?.name}' is opened`); } + createSandbox(); document.addEventListener('keydown', (e) => { if ((e.ctrlKey || e.metaKey) && e.key === 's') { e.preventDefault(); @@ -60,6 +74,12 @@ const WorkSpace: FC = () => { console.log = originalConsoleLog; document.removeEventListener('keydown', () => {}); // workspaceAction.closeAllFile(); + workspaceAction.updateProjectById( + { + contractAddress: '', + }, + projectId as string + ); clearLog(); }; }, []); @@ -110,10 +130,15 @@ const WorkSpace: FC = () => {
)} - {activeMenu === 'build' && ( + {activeMenu === 'build' && sandboxBlockchain && ( {}} + sandboxBlockchain={sandboxBlockchain} + contract={contract} + updateContract={(contractInstance) => { + setContract(contractInstance); + }} /> )} {activeMenu === 'test-cases' && ( diff --git a/src/hooks/logActivity.hooks.ts b/src/hooks/logActivity.hooks.ts index 918d010..38a349b 100644 --- a/src/hooks/logActivity.hooks.ts +++ b/src/hooks/logActivity.hooks.ts @@ -39,7 +39,7 @@ export function useLogActivity() { return; } const logEntry: LogEntry = { - text: text.replace(/\n/g, '
').trim(), + text: text.trim(), type, timestamp: new Date().toISOString(), };