diff --git a/CHANGELOG.md b/CHANGELOG.md index f2171ccfc8..9f882dc123 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,7 +15,7 @@ - [#3506](https://github.com/poanetwork/blockscout/pull/3506) - Fix token trasfer's tile styles: prevent overlapping of long names - [#3505](https://github.com/poanetwork/blockscout/pull/3505) - Fix Staking DApp first loading - [#3433](https://github.com/poanetwork/blockscout/pull/3433) - Token balances and rewards tables deadlocks elimination -- [#3494](https://github.com/poanetwork/blockscout/pull/3494), [#3497](https://github.com/poanetwork/blockscout/pull/3497), [#3504](https://github.com/poanetwork/blockscout/pull/3504) - Contracts interaction: fix method call with array[] input +- [#3494](https://github.com/poanetwork/blockscout/pull/3494), [#3497](https://github.com/poanetwork/blockscout/pull/3497), [#3504](https://github.com/poanetwork/blockscout/pull/3504), [#3517](https://github.com/poanetwork/blockscout/pull/3517) - Contracts interaction: fix method call with array[] inputs - [#3494](https://github.com/poanetwork/blockscout/pull/3494), [#3495](https://github.com/poanetwork/blockscout/pull/3495) - Contracts interaction: fix tuple output display - [#3479](https://github.com/poanetwork/blockscout/pull/3479) - Fix working with big numbers in Staking DApp - [#3477](https://github.com/poanetwork/blockscout/pull/3477) - Contracts interaction: fix broken call of GnosisProxy contract methods with parameters diff --git a/apps/block_scout_web/assets/js/lib/smart_contract/functions.js b/apps/block_scout_web/assets/js/lib/smart_contract/functions.js index bea7eb12ae..9ac8fa4be8 100644 --- a/apps/block_scout_web/assets/js/lib/smart_contract/functions.js +++ b/apps/block_scout_web/assets/js/lib/smart_contract/functions.js @@ -135,10 +135,14 @@ function callMethod (isWalletEnabled, $functionInputs, explorerChainId, $form, f let preparedVal if (isNonSpaceInputType(inputType)) { preparedVal = val.replace(/\s/g, '') } else { preparedVal = val } if (isArrayInputType(inputType)) { - if (preparedVal.startsWith('[') && preparedVal.endsWith(']')) { - preparedVal = preparedVal.substring(1, preparedVal.length - 1) + if (preparedVal === '') { + return [[]] + } else { + if (preparedVal.startsWith('[') && preparedVal.endsWith(']')) { + preparedVal = preparedVal.substring(1, preparedVal.length - 1) + } + return [preparedVal.split(',')] } - return preparedVal.split(',') } else { return preparedVal } }) @@ -150,27 +154,8 @@ function callMethod (isWalletEnabled, $functionInputs, explorerChainId, $form, f .then(currentAccount => { if (functionName) { const TargetContract = new window.web3.eth.Contract(contractAbi, contractAddress) - const inputsCount = inputs && inputs.length - let methodToCall const sendParams = { from: currentAccount, value: txValue || 0 } - if (inputsCount > 1 || inputsCount === 0) { - methodToCall = TargetContract.methods[functionName](...args).send(sendParams) - } else { - const inputType = inputs[0] && inputs[0].type - if (Array.isArray(args) && args[0] === '') { - if (isArrayInputType(inputType)) { - methodToCall = TargetContract.methods[functionName]([]).send(sendParams) - } else { - methodToCall = TargetContract.methods[functionName]().send(sendParams) - } - } else { - if (isArrayInputType(inputType)) { - methodToCall = TargetContract.methods[functionName](args).send(sendParams) - } else { - methodToCall = TargetContract.methods[functionName](args[0]).send(sendParams) - } - } - } + const methodToCall = TargetContract.methods[functionName](...args).send(sendParams) methodToCall .on('error', function (error) { openErrorModal(`Error in sending transaction for method "${functionName}"`, formatError(error), false) @@ -202,7 +187,7 @@ function callMethod (isWalletEnabled, $functionInputs, explorerChainId, $form, f } function isArrayInputType (inputType) { - return inputType && inputType.includes('[]') + return inputType && inputType.includes('[') && inputType.includes(']') } function isNonSpaceInputType (inputType) {