From 857bb8602532fbddddca48d03e4f9ef3933d9dc0 Mon Sep 17 00:00:00 2001 From: ankushKun Date: Mon, 8 Jan 2024 13:43:57 +0530 Subject: [PATCH] deployable testing --- app/.eslintrc.cjs | 1 + app/src/assets/arweave/ecosystem.svg | 40 ++++++++++++ app/src/components/cloud.tsx | 4 +- app/src/components/deploy.tsx | 26 ++++---- app/src/components/home.tsx | 38 ++++++++++- app/src/components/settings.tsx | 12 +++- app/src/components/showcase.tsx | 4 +- app/src/components/test.tsx | 98 ++++++++++++++++++++++++++-- app/src/hooks/useDeployments.ts | 8 ++- app/src/ide.tsx | 7 +- 10 files changed, 206 insertions(+), 32 deletions(-) create mode 100644 app/src/assets/arweave/ecosystem.svg diff --git a/app/.eslintrc.cjs b/app/.eslintrc.cjs index d6c9537..ee7d88e 100644 --- a/app/.eslintrc.cjs +++ b/app/.eslintrc.cjs @@ -14,5 +14,6 @@ module.exports = { 'warn', { allowConstantExport: true }, ], + '@typescript-eslint/no-unused-vars': ['warn', { argsIgnorePattern: '^_' }], }, } diff --git a/app/src/assets/arweave/ecosystem.svg b/app/src/assets/arweave/ecosystem.svg new file mode 100644 index 0000000..e5da0dc --- /dev/null +++ b/app/src/assets/arweave/ecosystem.svg @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/components/cloud.tsx b/app/src/components/cloud.tsx index f31b6f6..7f3d986 100644 --- a/app/src/components/cloud.tsx +++ b/app/src/components/cloud.tsx @@ -1,5 +1,5 @@ export default function Cloud() { - return
- Cloud + return
+
Cloud is a work in progress in this version of the IDE
} \ No newline at end of file diff --git a/app/src/components/deploy.tsx b/app/src/components/deploy.tsx index 7a1f5a8..9354859 100644 --- a/app/src/components/deploy.tsx +++ b/app/src/components/deploy.tsx @@ -20,18 +20,18 @@ const commercialUses = [ "Allowed-With-Credit" ] -// function extractFunctionsFromSwitchCase(src: string) { -// // const functionRegex = /function\s+([^\s(]+)\s*\(([^)]*)\)\s*{([^}]*)}/g; -// const functionRegex = /case\s+"([^"]+)"/g; -// const matches = src.matchAll(functionRegex); -// const functions = []; - -// for (const match of matches) { -// if (match[1] == "handle") continue -// functions.push(match[1]) -// } -// return functions -// } +function extractFunctionsFromSwitchCase(src: string) { + // const functionRegex = /function\s+([^\s(]+)\s*\(([^)]*)\)\s*{([^}]*)}/g; + const functionRegex = /case\s+"([^"]+)"/g; + const matches = src.matchAll(functionRegex); + const functions = []; + + for (const match of matches) { + if (match[1] == "handle") continue + functions.push(match[1]) + } + return functions +} interface DeployState { @@ -137,7 +137,7 @@ export default function Deploy({ contracts, target, test }: { contracts: contrac dispatch({ type: "set_deploy_success", payload: true }) dispatch({ type: "set_contract_id", payload: contract.contractTxId }) dispatch({ type: "set_result", payload: "Deployed successfully!\nID: " + contract.contractTxId }) - newDeployment(state.contractName, contract.contractTxId, state.deployEnv) + newDeployment(state.contractName, contract.contractTxId, state.deployEnv, extractFunctionsFromSwitchCase(contracts[state.contractName]["contract.js"])) dispatch({ type: "is_error", payload: false }) } catch (e) { console.log(e) diff --git a/app/src/components/home.tsx b/app/src/components/home.tsx index 94d856e..4abcef2 100644 --- a/app/src/components/home.tsx +++ b/app/src/components/home.tsx @@ -1,6 +1,40 @@ export default function Home() { - return
+ function ContractCard(){ + return
+
Contract name
+ +
+ } + + return
Welcome to BetterIDE! 🚀
Your one stop solution for developing smart contracts on Arweave
+ +
+
+
Recently opened contracts
+
+ + + + +
+
+
+
Explore contract templates
+
+ + + + +
+ +
+
+ +
-} \ No newline at end of file +} diff --git a/app/src/components/settings.tsx b/app/src/components/settings.tsx index 4e460fc..ecb0bfa 100644 --- a/app/src/components/settings.tsx +++ b/app/src/components/settings.tsx @@ -1,5 +1,13 @@ +import areco from "../assets/arweave/ecosystem.svg" + export default function Settings() { - return
- Settings + return
+ + +
+ +
View source
on Github
+
+
} \ No newline at end of file diff --git a/app/src/components/showcase.tsx b/app/src/components/showcase.tsx index 1f9d257..8aa8619 100644 --- a/app/src/components/showcase.tsx +++ b/app/src/components/showcase.tsx @@ -1,5 +1,5 @@ export default function Showcase() { - return
- Showcase + return
+
Showcase is a work in progress in this version of the IDE
} \ No newline at end of file diff --git a/app/src/components/test.tsx b/app/src/components/test.tsx index 8046f90..78ba1d1 100644 --- a/app/src/components/test.tsx +++ b/app/src/components/test.tsx @@ -1,6 +1,7 @@ import { useState, useEffect } from "react" import useDeployments, { deployment } from "../hooks/useDeployments" import useContracts from "../hooks/useContracts" +import { viewContractState, writeContract } from "arweavekit/contract" export default function Test({ target }: { target: string }) { const [activeDeployment, setActiveDeployment] = useState() @@ -8,6 +9,9 @@ export default function Test({ target }: { target: string }) { const [functionName, setFunctionName] = useState("") const { deployments, removeDeployment } = useDeployments() const { contracts, setContracts } = useContracts() + const [success, setSuccess] = useState(false) + const [latestState, setLatestState] = useState("") + const [result, setResult] = useState("") useEffect(() => { setContracts({ @@ -22,6 +26,89 @@ export default function Test({ target }: { target: string }) { setActiveDeployment(target) }, []) + useEffect(() => { + setFunctionName("") + setCallType("read") + }, [activeDeployment]) + + useEffect(() => { + if (!activeDeployment) return + if (functionName.toLowerCase().startsWith("get")) + setCallType("read") + else if (functionName.toLowerCase().startsWith("set")) + setCallType("write") + }, [functionName, activeDeployment]) + + async function run() { + if (!activeDeployment) return + if (!functionName) return + if (!callType) return + if (!contracts) return + const contract = contracts[activeDeployment] + if (!contract) return + const input = JSON.parse(contracts["input"]["state.json"]) + if (!input) return + + if (callType == "read") { + try { + const res = await viewContractState({ + contractTxId: deployments[activeDeployment].txid, + environment: deployments[activeDeployment].env, + strategy: "arweave", + options: { + function: functionName, + ...input + } + }) + console.log(res) + if (res.result.status == 200) { + setSuccess(true) + setResult(JSON.stringify({ result: res.viewContract.result }, null, 2)) + setLatestState(JSON.stringify(res.viewContract.state, null, 2)) + + } else { + setResult(`error: ${res.result.status} +${res.result.statusText} + +${res.viewContract.errorMessage}`) + } + } catch (e) { + console.log(e) + setResult(`error: ${e}`) + } + } else if (callType == "write") { + try { + const res = await writeContract({ + contractTxId: deployments[activeDeployment].txid, + environment: deployments[activeDeployment].env, + wallet: "use_wallet", + strategy: "arweave", + options: { + function: functionName, + ...input + }, + cacheOptions: { + inMemory: true + } + }) + console.log(res) + if (res.result.status == 200) { + setSuccess(true) + setResult(`TXID: ${res.writeContract.originalTxId}`) + setLatestState(JSON.stringify(res.state, null, 2)) + } else { + setResult(`error: ${res.result.status} +${res.result.statusText} + +${res.writeContract.errorMessage}`) + } + } catch (e) { + console.log(e) + setResult(`error: ${e}`) + } + } + } + return
@@ -50,20 +137,19 @@ export default function Test({ target }: { target: string }) {
Function Name
{/* input json */} -