From 6b77a0a3487f618dbac8987a1d0bc9ff341e1229 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kaan=20Uzdo=C4=9Fan?= Date: Thu, 20 Jun 2024 22:57:12 +0200 Subject: [PATCH] Fix no selectedContractFileAndName on load --- .../src/app/components/ContractDropdown.tsx | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/apps/contract-verification/src/app/components/ContractDropdown.tsx b/apps/contract-verification/src/app/components/ContractDropdown.tsx index c7ad090ac9..a379a26c1e 100644 --- a/apps/contract-verification/src/app/components/ContractDropdown.tsx +++ b/apps/contract-verification/src/app/components/ContractDropdown.tsx @@ -18,13 +18,15 @@ export const ContractDropdown: React.FC = ({label, id}) = useEffect(() => { console.log('CompiilationOutput chainged', compilationOutput) if (!compilationOutput) return - const isOnlyOneFileCompiled = Object.keys(compilationOutput).length === 1 - if (isOnlyOneFileCompiled) { - const onlyFileName = Object.keys(compilationOutput)[0] - const isOnlyOneContractCompiled = Object.keys(compilationOutput[onlyFileName].data.contracts[onlyFileName]).length === 1 - if (isOnlyOneContractCompiled) { - const onlyContractName = Object.keys(compilationOutput[onlyFileName].data.contracts[onlyFileName])[0] - setSelectedContractFileAndName(onlyFileName + ':' + onlyContractName) + // Otherwise select the first by default + const triggerFilePath = Object.keys(compilationOutput)[0] + const contracts = compilationOutput[triggerFilePath]?.data?.contracts + if (contracts && Object.keys(contracts).length) { + const firstFilePath = Object.keys(contracts)[0] + const contractsInFile = contracts[firstFilePath] + if (contractsInFile && Object.keys(contractsInFile).length) { + const firstContractName = Object.keys(contractsInFile)[0] + setSelectedContractFileAndName(triggerFilePath + ':' + firstFilePath + ':' + firstContractName) } } }, [compilationOutput])