Skip to content
This repository has been archived by the owner on Dec 6, 2024. It is now read-only.

Commit

Permalink
Fix problem with empty constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
varex83 committed Nov 7, 2023
1 parent 4f476fc commit 1b005d9
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions plugin/src/features/Deployment/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -37,9 +38,16 @@ const Deployment: React.FC<DeploymentProps> = ({ setActiveTab }) => {
const [inputs, setInputs] = useState<string[]>([])

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 () {
Expand Down Expand Up @@ -76,7 +84,7 @@ const Deployment: React.FC<DeploymentProps> = ({ setActiveTab }) => {
)

try {
const contract = await factory.deploy(...inputs)
let contract: Contract = await factory.deploy(...inputs)

remixClient.emit('statusChanged', {
key: 'loading',
Expand Down Expand Up @@ -127,6 +135,11 @@ const Deployment: React.FC<DeploymentProps> = ({ setActiveTab }) => {

setTransactions([transaction, ...transactions])
} catch (e) {
remixClient.terminal.log({
value: `Error: ${(e as any).code}`,
type: 'error'
})

remixClient.emit('statusChanged', {
key: 'failed',
type: 'error',
Expand Down

0 comments on commit 1b005d9

Please sign in to comment.