From 0f76321b8e42c65eb3bb16f17d9fed67b4391f2e Mon Sep 17 00:00:00 2001 From: Rahul Yadav Date: Thu, 5 Sep 2024 00:24:06 +0530 Subject: [PATCH] feat: build and deploy project --- src/components/workspace/ABIUi/TactABIUi.tsx | 51 +++---- .../workspace/BuildProject/BuildProject.tsx | 139 +++++++++--------- src/components/workspace/Editor/Editor.tsx | 5 +- .../workspace/ExecuteFile/ExecuteFile.tsx | 14 +- .../workspace/WorkSpace/WorkSpace.tsx | 60 +++++--- .../project/ManageProject/ManageProject.tsx | 11 +- .../workspace/tree/FileTree/FileTree.tsx | 12 +- src/hooks/file.hooks.ts | 2 +- src/hooks/fileTabs.hooks.ts | 8 +- src/hooks/project.hooks.ts | 23 +-- src/hooks/projectV2.hooks.ts | 131 +++++++++++++---- src/interfaces/workspace.interface.ts | 18 ++- src/lib/fs.ts | 2 + src/state/IDE.context.tsx | 20 ++- src/utility/eventEmitter.ts | 1 + 15 files changed, 312 insertions(+), 185 deletions(-) diff --git a/src/components/workspace/ABIUi/TactABIUi.tsx b/src/components/workspace/ABIUi/TactABIUi.tsx index affde5f..3590a91 100644 --- a/src/components/workspace/ABIUi/TactABIUi.tsx +++ b/src/components/workspace/ABIUi/TactABIUi.tsx @@ -1,7 +1,7 @@ import AppIcon from '@/components/ui/icon'; import { UserContract, useContractAction } from '@/hooks/contract.hooks'; import { useLogActivity } from '@/hooks/logActivity.hooks'; -import { useWorkspaceActions } from '@/hooks/workspace.hooks'; +import { useProject } from '@/hooks/projectV2.hooks'; import { LogType } from '@/interfaces/log.interface'; import { TactABIField, @@ -17,7 +17,6 @@ import { SandboxContract } from '@ton/sandbox'; import { Button, Form, Input, Popover, Select, Switch } from 'antd'; import { Rule, RuleObject } from 'antd/es/form'; import { useForm } from 'antd/lib/form/Form'; -import { useRouter } from 'next/router'; import { FC, Fragment, useEffect, useState } from 'react'; import { ABIUiProps } from './ABIUi'; import s from './ABIUi.module.scss'; @@ -317,16 +316,7 @@ const TactABIUi: FC = ({ const { callGetter, callSetter } = useContractAction(); const { createLog } = useLogActivity(); const [form] = useForm(); - const { - projectFiles, - getAllFilesWithContent, - updateABIInputValues, - getABIInputValues, - project, - } = useWorkspaceActions(); - const router = useRouter(); - const { id: projectId } = router.query; - const activeProject = project(projectId as string); + const { projectFiles, readdirTree, activeProject } = useProject(); const getItemHeading = (item: TactType) => { if (item.type?.kind === 'simple') { @@ -348,15 +338,22 @@ const TactABIUi: FC = ({ const onSubmit = async (formValues: TactInputFields, fieldName: string) => { try { - let tsProjectFiles = {}; + const tsProjectFiles: Record = {}; if (isIncludesTypeCellOrSlice(formValues)) { - tsProjectFiles = await getAllFilesWithContent( - projectId as string, + const fileCollection = await readdirTree( + `/${activeProject?.path}`, + { + basePath: null, + content: true, + }, (file) => !file.path.startsWith('dist') && file.name.endsWith('.ts') && !file.name.endsWith('.spec.ts'), ); + fileCollection.forEach((file) => { + tsProjectFiles[file.path!] = file.content ?? ''; + }); } const parsedInputsValues = Object.values( await parseInputs(formValues, tsProjectFiles), @@ -386,10 +383,10 @@ const TactABIUi: FC = ({ } else { createLog(JSON.stringify(response, null, 2)); } - updateABIInputValues( - { key: abiType.name, value: formValues, type: type }, - projectId as string, - ); + // updateABIInputValues( + // { key: abiType.name, value: formValues, type: type }, + // activeProject as string, + // ); } catch (error) { if ((error as Error).message.includes('no healthy nodes for')) { createLog( @@ -409,13 +406,13 @@ const TactABIUi: FC = ({ useEffect(() => { if (!activeProject) return; - const abiFields = getABIInputValues( - projectId as string, - abiType.name, - type, - ); - if (!abiFields) return; - form.setFieldsValue(abiFields); + // const abiFields = getABIInputValues( + // projectId as string, + // abiType.name, + // type, + // ); + // if (!abiFields) return; + // form.setFieldsValue(abiFields); }, []); return ( @@ -434,7 +431,7 @@ const TactABIUi: FC = ({ {renderField( field as TactABIField, - projectFiles(projectId as string), + projectFiles, [], type === 'Setter' ? -1 : 0, )} diff --git a/src/components/workspace/BuildProject/BuildProject.tsx b/src/components/workspace/BuildProject/BuildProject.tsx index 3caa25f..67b4f5d 100644 --- a/src/components/workspace/BuildProject/BuildProject.tsx +++ b/src/components/workspace/BuildProject/BuildProject.tsx @@ -7,6 +7,7 @@ import { CellABI, NetworkEnvironment, Project, + ProjectSetting, TactABIField, TactInputFields, } from '@/interfaces/workspace.interface'; @@ -30,8 +31,11 @@ import ExecuteFile from '../ExecuteFile/ExecuteFile'; import s from './BuildProject.module.scss'; import AppIcon from '@/components/ui/icon'; +import { useFile } from '@/hooks'; +import { useProject } from '@/hooks/projectV2.hooks'; import { useSettingAction } from '@/hooks/setting.hooks'; import { ABIParser, parseInputs } from '@/utility/abi'; +import EventEmitter from '@/utility/eventEmitter'; import { Maybe } from '@ton/core/dist/utils/maybe'; import { TonClient } from '@ton/ton'; import { useForm } from 'antd/lib/form/Form'; @@ -72,6 +76,9 @@ const BuildProject: FC = ({ projectId, contract, updateContract }) => { ); const { isAutoBuildAndDeployEnabled } = useSettingAction(); + const { projectFiles, readdirTree, activeProject, updateProjectSetting } = + useProject(); + const { getFile } = useFile(); const [tonConnector] = useTonConnectUI(); const chain = tonConnector.wallet?.account.chain; @@ -85,25 +92,13 @@ const BuildProject: FC = ({ projectId, contract, updateContract }) => { const [deployForm] = useForm(); - const { - projectFiles, - getFileByPath, - updateProjectById, - project, - activeFile, - getAllFilesWithContent, - updateABIInputValues, - getABIInputValues, - } = useWorkspaceActions(); - - const currentActiveFile = activeFile(projectId as string); + const { updateProjectById, updateABIInputValues, getABIInputValues } = + useWorkspaceActions(); const { deployContract } = useContractAction(); - const activeProject = project(projectId); - const contractsToDeploy = () => { - return projectFiles(projectId) + return projectFiles .filter((f) => { const _fileExtension = getFileExtension(f.name || ''); return ( @@ -170,26 +165,30 @@ const BuildProject: FC = ({ projectId, contract, updateContract }) => { allowClear > {_contractsToDeploy.map((f) => ( - + {f.name} ))} {cellBuilder('Update initial contract state in ')} -
- {selectedContract && - contractABI.initParams?.map((item) => { - return ( - - {renderField( - item as unknown as TactABIField, - projectFiles(projectId), - )} - - ); - })} -
+ {selectedContract && + contractABI.initParams && + contractABI.initParams.length > 0 && ( +
+ {contractABI.initParams.map((item) => { + return ( + + {renderField( + item as unknown as TactABIField, + projectFiles, + )} + + ); + })} +
+ )} +