From ffd54b4b14f3f643003b392a66451e2712a6f6f9 Mon Sep 17 00:00:00 2001 From: Aniket-Engg Date: Wed, 28 Jun 2023 15:54:22 +0530 Subject: [PATCH] common method --- apps/etherscan/src/app/views/VerifyView.tsx | 35 +++++++++------------ 1 file changed, 15 insertions(+), 20 deletions(-) diff --git a/apps/etherscan/src/app/views/VerifyView.tsx b/apps/etherscan/src/app/views/VerifyView.tsx index 5e4323e940..35f5fce803 100644 --- a/apps/etherscan/src/app/views/VerifyView.tsx +++ b/apps/etherscan/src/app/views/VerifyView.tsx @@ -52,20 +52,22 @@ export const VerifyView: React.FC = ({ }, [client]) useEffect(() => { - if (contracts.includes(selectedContract)) { - client.call("compilerArtefacts" as any, "getArtefactsByContractName", selectedContract).then((result) => { - const { artefact } = result - if (artefact && artefact.abi && artefact.abi[0] && artefact.abi[0].type && artefact.abi[0].type === 'constructor' && artefact.abi[0].inputs.length > 0) { - setConstructorInputs(artefact.abi[0].inputs) - setShowConstructorArgs(true) - } else { - setConstructorInputs([]) - setShowConstructorArgs(false) - } - }) - } + if (contracts.includes(selectedContract)) updateConsFields(selectedContract) }, [contracts]) + const updateConsFields = (contractName) => { + client.call("compilerArtefacts" as any, "getArtefactsByContractName", contractName).then((result) => { + const { artefact } = result + if (artefact && artefact.abi && artefact.abi[0] && artefact.abi[0].type && artefact.abi[0].type === 'constructor' && artefact.abi[0].inputs.length > 0) { + setConstructorInputs(artefact.abi[0].inputs) + setShowConstructorArgs(true) + } else { + setConstructorInputs([]) + setShowConstructorArgs(false) + } + }) + } + const onVerifyContract = async (values: FormValues) => { const compilationResult = (await client.call( "solidity", @@ -156,14 +158,7 @@ export const VerifyView: React.FC = ({ onChange={async (e) => { handleChange(e) setSelectedContract(e.target.value) - const {artefact} = await client.call("compilerArtefacts" as any, "getArtefactsByContractName", e.target.value) - if (artefact && artefact.abi && artefact.abi[0] && artefact.abi[0].type && artefact.abi[0].type === 'constructor' && artefact.abi[0].inputs.length > 0) { - setConstructorInputs(artefact.abi[0].inputs) - setShowConstructorArgs(true) - } else { - setConstructorInputs([]) - setShowConstructorArgs(false) - } + updateConsFields(e.target.value) }} >