Fix no selectedContractFileAndName on load

pull/5285/head
Kaan Uzdoğan 5 months ago committed by Aniket
parent 23293a6b85
commit 6b77a0a348
  1. 16
      apps/contract-verification/src/app/components/ContractDropdown.tsx

@ -18,13 +18,15 @@ export const ContractDropdown: React.FC<ContractDropdownProps> = ({label, id}) =
useEffect(() => { useEffect(() => {
console.log('CompiilationOutput chainged', compilationOutput) console.log('CompiilationOutput chainged', compilationOutput)
if (!compilationOutput) return if (!compilationOutput) return
const isOnlyOneFileCompiled = Object.keys(compilationOutput).length === 1 // Otherwise select the first by default
if (isOnlyOneFileCompiled) { const triggerFilePath = Object.keys(compilationOutput)[0]
const onlyFileName = Object.keys(compilationOutput)[0] const contracts = compilationOutput[triggerFilePath]?.data?.contracts
const isOnlyOneContractCompiled = Object.keys(compilationOutput[onlyFileName].data.contracts[onlyFileName]).length === 1 if (contracts && Object.keys(contracts).length) {
if (isOnlyOneContractCompiled) { const firstFilePath = Object.keys(contracts)[0]
const onlyContractName = Object.keys(compilationOutput[onlyFileName].data.contracts[onlyFileName])[0] const contractsInFile = contracts[firstFilePath]
setSelectedContractFileAndName(onlyFileName + ':' + onlyContractName) if (contractsInFile && Object.keys(contractsInFile).length) {
const firstContractName = Object.keys(contractsInFile)[0]
setSelectedContractFileAndName(triggerFilePath + ':' + firstFilePath + ':' + firstContractName)
} }
} }
}, [compilationOutput]) }, [compilationOutput])

Loading…
Cancel
Save