From 1b005d99daee42a51ae203266c4e09fd8d00eb4a Mon Sep 17 00:00:00 2001 From: Bohdan Ohorodnii Date: Tue, 7 Nov 2023 16:23:00 +0200 Subject: [PATCH] Fix problem with empty constructor --- plugin/src/features/Deployment/index.tsx | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/plugin/src/features/Deployment/index.tsx b/plugin/src/features/Deployment/index.tsx index 3d1e8133..0fcdf486 100644 --- a/plugin/src/features/Deployment/index.tsx +++ b/plugin/src/features/Deployment/index.tsx @@ -15,6 +15,7 @@ import { DeployedContractsContext } from '../../contexts/DeployedContractsContex import { type DeployedContract } from '../../types/contracts' import { type Transaction } from '../../types/transaction' import { ConnectionContext } from '../../contexts/ConnectionContext' +import { Contract } from 'ethers' interface DeploymentProps { setActiveTab: (tab: AccordianTabs) => void @@ -37,9 +38,16 @@ const Deployment: React.FC = ({ setActiveTab }) => { const [inputs, setInputs] = useState([]) useEffect(() => { - setInputs(new Array(selectedContract?.abi.find((abiElement) => { + const constructor = selectedContract?.abi.find((abiElement) => { return abiElement.type === 'constructor' - })?.inputs.length).fill('')) + }) + + if (constructor == undefined || constructor?.inputs == undefined) { + setInputs([]) + return + } + + setInputs(new Array(constructor?.inputs.length).fill('')) }, [selectedContract]) async function deploy () { @@ -76,7 +84,7 @@ const Deployment: React.FC = ({ setActiveTab }) => { ) try { - const contract = await factory.deploy(...inputs) + let contract: Contract = await factory.deploy(...inputs) remixClient.emit('statusChanged', { key: 'loading', @@ -127,6 +135,11 @@ const Deployment: React.FC = ({ setActiveTab }) => { setTransactions([transaction, ...transactions]) } catch (e) { + remixClient.terminal.log({ + value: `Error: ${(e as any).code}`, + type: 'error' + }) + remixClient.emit('statusChanged', { key: 'failed', type: 'error',