From 1b290aa5fe76326898078ad4f4b712cfbd17411a Mon Sep 17 00:00:00 2001 From: "sweep-ai[bot]" <128439645+sweep-ai[bot]@users.noreply.github.com> Date: Tue, 31 Oct 2023 23:31:01 +0000 Subject: [PATCH 1/6] feat: Updated plugin/src/features/Deployment/index --- plugin/src/features/Deployment/index.tsx | 180 +++++++++++++++++++++++ 1 file changed, 180 insertions(+) diff --git a/plugin/src/features/Deployment/index.tsx b/plugin/src/features/Deployment/index.tsx index ed7ba4f4..b9ca7d86 100644 --- a/plugin/src/features/Deployment/index.tsx +++ b/plugin/src/features/Deployment/index.tsx @@ -21,6 +21,9 @@ import { envAtom } from '../../atoms/environment' import useAccount from '../../hooks/useAccount' import useProvider from '../../hooks/useProvider' import useRemixClient from '../../hooks/useRemixClient' +import { Modal } from 'react-bootstrap'; +import { FELT } from '../../utils/types'; +import { getClassByHash, getClassHashAt } from '../../utils/rpc'; import { constructorInputsAtom, deployStatusAtom, deploymentAtom, isDeployingAtom, notEnoughInputsAtom } from '../../atoms/deployment' interface DeploymentProps { setActiveTab: (tab: AccordianTabs) => void @@ -411,6 +414,183 @@ const Deployment: React.FC = ({ setActiveTab }) => { ) + const [showModal, setShowModal] = useState(false); + const [inputValue, setInputValue] = useState(''); + + const handleOpenModal = () => { + setShowModal(true); + }; + + const handleCloseModal = () => { + setShowModal(false); + }; + + const handleInputChange = (event: React.ChangeEvent) => { + setInputValue(event.target.value); + }; + + const handleInputSubmit = async () => { + const isClassHash = FELT.test(inputValue); + if (isClassHash) { + const classData = await getClassByHash(inputValue); + // handle class data + } else { + const classHash = await getClassHashAt(inputValue); + const classData = await getClassByHash(classHash); + // handle class data + } + handleCloseModal(); + }; + + return ( + <> + + + + + Enter Class Hash or Contract Address + + + + + + + + + {contracts.length > 0 && selectedContract != null + ? ( +
+ +
+ {constructorInputs.map((input, index) => { + return ( +
+ + +
+ ) + })} + +
+ {account != null && + selectedContract.deployedInfo.some( + (info) => + info.address === account.address && info.chainId === chainId + ) && ( +
+ +
+ )} + {notEnoughInputs && ( + + )} +
+ ) + : ( +

No contracts ready for deployment yet, compile a cairo contract

+ )} +
+ + ) } export default Deployment From ce389f22f1d99ba747ab334639c8293a1d1b07f8 Mon Sep 17 00:00:00 2001 From: "sweep-ai[bot]" <128439645+sweep-ai[bot]@users.noreply.github.com> Date: Tue, 31 Oct 2023 23:31:25 +0000 Subject: [PATCH 2/6] Sandbox run plugin/src/features/Deployment/index.tsx --- plugin/src/features/Deployment/index.tsx | 566 ++++++++++++----------- 1 file changed, 285 insertions(+), 281 deletions(-) diff --git a/plugin/src/features/Deployment/index.tsx b/plugin/src/features/Deployment/index.tsx index b9ca7d86..cded0d60 100644 --- a/plugin/src/features/Deployment/index.tsx +++ b/plugin/src/features/Deployment/index.tsx @@ -16,15 +16,24 @@ import { useAtom, useAtomValue, useSetAtom } from 'jotai' import transactionsAtom from '../../atoms/transactions' import './styles.css' -import { compiledContractsAtom, selectedCompiledContract } from '../../atoms/compiledContracts' +import { + compiledContractsAtom, + selectedCompiledContract +} from '../../atoms/compiledContracts' import { envAtom } from '../../atoms/environment' import useAccount from '../../hooks/useAccount' import useProvider from '../../hooks/useProvider' import useRemixClient from '../../hooks/useRemixClient' -import { Modal } from 'react-bootstrap'; -import { FELT } from '../../utils/types'; -import { getClassByHash, getClassHashAt } from '../../utils/rpc'; -import { constructorInputsAtom, deployStatusAtom, deploymentAtom, isDeployingAtom, notEnoughInputsAtom } from '../../atoms/deployment' +import { Modal } from 'react-bootstrap' +import { FELT } from '../../utils/types' +import { getClassByHash, getClassHashAt } from '../../utils/rpc' +import { + constructorInputsAtom, + deployStatusAtom, + deploymentAtom, + isDeployingAtom, + notEnoughInputsAtom +} from '../../atoms/deployment' interface DeploymentProps { setActiveTab: (tab: AccordianTabs) => void } @@ -35,17 +44,15 @@ const Deployment: React.FC = ({ setActiveTab }) => { const { provider } = useProvider() const [contracts, setContracts] = useAtom(compiledContractsAtom) - const [selectedContract, setSelectedContract] = useAtom(selectedCompiledContract) + const [selectedContract, setSelectedContract] = useAtom( + selectedCompiledContract + ) const [constructorCalldata, setConstructorCalldata] = useState({}) - const { - isDeploying, - deployStatus, - constructorInputs, - notEnoughInputs - } = useAtomValue(deploymentAtom) + const { isDeploying, deployStatus, constructorInputs, notEnoughInputs } = + useAtomValue(deploymentAtom) const setIsDeploying = useSetAtom(isDeployingAtom) const setDeployStatus = useSetAtom(deployStatusAtom) @@ -137,18 +144,19 @@ const Deployment: React.FC = ({ setActiveTab }) => { value: error.message, type: 'error' }) - throw new Error(error.message + '\n Aborting deployment... Couldn\'t get declare infomation') + throw new Error( + error.message + + "\n Aborting deployment... Couldn't get declare infomation" + ) } } setDeployStatus('Deploying...') - const deployResponse = await account.deployContract( - { - classHash: classHash ?? selectedContract.classHash, - constructorCalldata: calldata - } - ) + const deployResponse = await account.deployContract({ + classHash: classHash ?? selectedContract.classHash, + constructorCalldata: calldata + }) await remixClient.call('terminal', 'log', { value: JSON.stringify(deployResponse, null, 2), type: 'info' @@ -280,56 +288,36 @@ const Deployment: React.FC = ({ setActiveTab }) => { return ( <> - {contracts.length > 0 && selectedContract != null - ? ( -
- -
- {constructorInputs.map((input, index) => { - return ( -
- - -
- ) - })} - -
- {account != null && - selectedContract.deployedInfo.some( - (info) => - info.address === account.address && info.chainId === chainId - ) && ( -
- + ? 'not-allowed' + : 'pointer' + }` + }} + disabled={ + isDeploying || + account == null || + selectedContract.deployedInfo.some( + (info) => + info.address === account.address && + info.chainId === chainId + ) + } + aria-disabled={ + isDeploying || + account == null || + selectedContract.deployedInfo.some( + (info) => + info.address === account.address && + info.chainId === chainId + ) + } + type="submit" + > +
+
+ {isDeploying ? ( + <> + + + {deployStatus} + + + ) : ( +
+ {account != null && + selectedContract.deployedInfo.some( + (info) => + info.address === account.address && + info.chainId === chainId + ) ? ( + + {' '} + Deployed {' '} + {selectedContract.name} + + ) : ( + Deploy {selectedContract.name} + )} +
+ )}
+
+ + + {account != null && + selectedContract.deployedInfo.some( + (info) => + info.address === account.address && info.chainId === chainId + ) && ( +
+ +
)} - {notEnoughInputs && ( - - )} -
- ) - : ( -

No contracts ready for deployment yet, compile a cairo contract

+ {notEnoughInputs && ( + )} +
+ ) : ( +

No contracts ready for deployment yet, compile a cairo contract

+ )}
) - const [showModal, setShowModal] = useState(false); - const [inputValue, setInputValue] = useState(''); - + const [showModal, setShowModal] = useState(false) + const [inputValue, setInputValue] = useState('') + const handleOpenModal = () => { - setShowModal(true); - }; - + setShowModal(true) + } + const handleCloseModal = () => { - setShowModal(false); - }; - + setShowModal(false) + } + const handleInputChange = (event: React.ChangeEvent) => { - setInputValue(event.target.value); - }; - + setInputValue(event.target.value) + } + const handleInputSubmit = async () => { - const isClassHash = FELT.test(inputValue); + const isClassHash = FELT.test(inputValue) if (isClassHash) { - const classData = await getClassByHash(inputValue); + const classData = await getClassByHash(inputValue) // handle class data } else { - const classHash = await getClassHashAt(inputValue); - const classData = await getClassByHash(classHash); + const classHash = await getClassHashAt(inputValue) + const classData = await getClassByHash(classHash) // handle class data } - handleCloseModal(); - }; - + handleCloseModal() + } + return ( <> @@ -451,62 +455,46 @@ const Deployment: React.FC = ({ setActiveTab }) => { Enter Class Hash or Contract Address - + - {contracts.length > 0 && selectedContract != null - ? ( -
- -
- {constructorInputs.map((input, index) => { - return ( -
- - -
- ) - })} - -
- {account != null && - selectedContract.deployedInfo.some( - (info) => - info.address === account.address && info.chainId === chainId - ) && ( -
- + ? 'not-allowed' + : 'pointer' + }` + }} + disabled={ + isDeploying || + account == null || + selectedContract.deployedInfo.some( + (info) => + info.address === account.address && + info.chainId === chainId + ) + } + aria-disabled={ + isDeploying || + account == null || + selectedContract.deployedInfo.some( + (info) => + info.address === account.address && + info.chainId === chainId + ) + } + type="submit" + > +
+
+ {isDeploying ? ( + <> + + + {deployStatus} + + + ) : ( +
+ {account != null && + selectedContract.deployedInfo.some( + (info) => + info.address === account.address && + info.chainId === chainId + ) ? ( + + {' '} + Deployed {' '} + {selectedContract.name} + + ) : ( + Deploy {selectedContract.name} + )} +
+ )}
+
+ + + {account != null && + selectedContract.deployedInfo.some( + (info) => + info.address === account.address && info.chainId === chainId + ) && ( +
+ +
)} - {notEnoughInputs && ( - - )} -
- ) - : ( -

No contracts ready for deployment yet, compile a cairo contract

+ {notEnoughInputs && ( + )} +
+ ) : ( +

No contracts ready for deployment yet, compile a cairo contract

+ )}
) From a7d3dc03ec84e400fac4f3065c6a9eff53d0d542 Mon Sep 17 00:00:00 2001 From: "sweep-ai[bot]" <128439645+sweep-ai[bot]@users.noreply.github.com> Date: Tue, 31 Oct 2023 23:31:52 +0000 Subject: [PATCH 3/6] feat: Add functions to fetch contract class by has --- plugin/src/utils/fetchContract.ts | 45 +++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 plugin/src/utils/fetchContract.ts diff --git a/plugin/src/utils/fetchContract.ts b/plugin/src/utils/fetchContract.ts new file mode 100644 index 00000000..01938537 --- /dev/null +++ b/plugin/src/utils/fetchContract.ts @@ -0,0 +1,45 @@ +import fetch from 'node-fetch'; + +const RPC_ENDPOINT = 'https://starknet-devnet2.io'; + +async function fetchClass(classHash: string) { + const response = await fetch(`${RPC_ENDPOINT}/starknet_getClass`, { + method: 'POST', + headers: { + 'Content-Type': 'application/json' + }, + body: JSON.stringify({ + class_hash: classHash + }) + }); + + if (!response.ok) { + throw new Error(`HTTP error! status: ${response.status}`); + } + + const data = await response.json(); + return data.result; +} + +async function fetchAddress(contractAddress: string) { + const response = await fetch(`${RPC_ENDPOINT}/starknet_getClassHashAt`, { + method: 'POST', + headers: { + 'Content-Type': 'application/json' + }, + body: JSON.stringify({ + contract_address: contractAddress + }) + }); + + if (!response.ok) { + throw new Error(`HTTP error! status: ${response.status}`); + } + + const data = await response.json(); + const classHash = data.result; + const contractClass = await fetchClass(classHash); + return contractClass; +} + +export { fetchClass, fetchAddress }; From 87c34dd74be36b45ba8281efbe6e2c38e3f3987a Mon Sep 17 00:00:00 2001 From: "sweep-ai[bot]" <128439645+sweep-ai[bot]@users.noreply.github.com> Date: Tue, 31 Oct 2023 23:32:15 +0000 Subject: [PATCH 4/6] Sandbox run plugin/src/utils/fetchContract.ts --- plugin/src/utils/fetchContract.ts | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/plugin/src/utils/fetchContract.ts b/plugin/src/utils/fetchContract.ts index 01938537..9976a363 100644 --- a/plugin/src/utils/fetchContract.ts +++ b/plugin/src/utils/fetchContract.ts @@ -1,6 +1,6 @@ -import fetch from 'node-fetch'; +import fetch from 'node-fetch' -const RPC_ENDPOINT = 'https://starknet-devnet2.io'; +const RPC_ENDPOINT = 'https://starknet-devnet2.io' async function fetchClass(classHash: string) { const response = await fetch(`${RPC_ENDPOINT}/starknet_getClass`, { @@ -11,14 +11,14 @@ async function fetchClass(classHash: string) { body: JSON.stringify({ class_hash: classHash }) - }); + }) if (!response.ok) { - throw new Error(`HTTP error! status: ${response.status}`); + throw new Error(`HTTP error! status: ${response.status}`) } - const data = await response.json(); - return data.result; + const data = await response.json() + return data.result } async function fetchAddress(contractAddress: string) { @@ -30,16 +30,16 @@ async function fetchAddress(contractAddress: string) { body: JSON.stringify({ contract_address: contractAddress }) - }); + }) if (!response.ok) { - throw new Error(`HTTP error! status: ${response.status}`); + throw new Error(`HTTP error! status: ${response.status}`) } - const data = await response.json(); - const classHash = data.result; - const contractClass = await fetchClass(classHash); - return contractClass; + const data = await response.json() + const classHash = data.result + const contractClass = await fetchClass(classHash) + return contractClass } -export { fetchClass, fetchAddress }; +export { fetchClass, fetchAddress } From 3ab24278a60c3c79e8ce3401982ef88c9246f1ee Mon Sep 17 00:00:00 2001 From: "sweep-ai[bot]" <128439645+sweep-ai[bot]@users.noreply.github.com> Date: Tue, 31 Oct 2023 23:34:10 +0000 Subject: [PATCH 5/6] feat: Updated plugin/src/features/Deployment/index --- plugin/src/features/Deployment/index.tsx | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/plugin/src/features/Deployment/index.tsx b/plugin/src/features/Deployment/index.tsx index cded0d60..1b11fd38 100644 --- a/plugin/src/features/Deployment/index.tsx +++ b/plugin/src/features/Deployment/index.tsx @@ -26,7 +26,7 @@ import useProvider from '../../hooks/useProvider' import useRemixClient from '../../hooks/useRemixClient' import { Modal } from 'react-bootstrap' import { FELT } from '../../utils/types' -import { getClassByHash, getClassHashAt } from '../../utils/rpc' +import { fetchClass, fetchAddress } from '../../utils/fetchContract' import { constructorInputsAtom, deployStatusAtom, @@ -108,8 +108,8 @@ const Deployment: React.FC = ({ setActiveTab }) => { setDeployStatus('Declaring...') try { try { - await account.getClassByHash(selectedContract.sierraClassHash) - await remixClient.call( + const classData = await fetchClass(selectedContract.sierraClassHash) + // handle class data 'notification' as any, 'toast', `ℹ️ Contract with classHash: ${selectedContract.sierraClassHash} already has been declared, proceeding to deployment...` @@ -436,7 +436,11 @@ const Deployment: React.FC = ({ setActiveTab }) => { const handleInputSubmit = async () => { const isClassHash = FELT.test(inputValue) if (isClassHash) { - const classData = await getClassByHash(inputValue) + const classData = await fetchClass(inputValue) + // handle class data + } else { + const classHash = await fetchAddress(inputValue) + const classData = await fetchClass(classHash) // handle class data } else { const classHash = await getClassHashAt(inputValue) From 48441ac315347da7694761f07d2179da3af592f3 Mon Sep 17 00:00:00 2001 From: "sweep-ai[bot]" <128439645+sweep-ai[bot]@users.noreply.github.com> Date: Tue, 31 Oct 2023 23:35:55 +0000 Subject: [PATCH 6/6] feat: Updated plugin/src/features/Deployment/index --- plugin/src/features/Deployment/index.tsx | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/plugin/src/features/Deployment/index.tsx b/plugin/src/features/Deployment/index.tsx index 1b11fd38..28da57aa 100644 --- a/plugin/src/features/Deployment/index.tsx +++ b/plugin/src/features/Deployment/index.tsx @@ -442,11 +442,10 @@ const Deployment: React.FC = ({ setActiveTab }) => { const classHash = await fetchAddress(inputValue) const classData = await fetchClass(classHash) // handle class data - } else { - const classHash = await getClassHashAt(inputValue) - const classData = await getClassByHash(classHash) - // handle class data } + const classHash = await getClassHashAt(inputValue) + const classData = await getClassByHash(classHash) + // handle class data handleCloseModal() }