Merge pull request #3517 from poanetwork/vb-fix-write-contract-input-array-data

Finalize fixing write contract array input data processing
pull/3525/head
Victor Baranov 4 years ago committed by GitHub
commit c778962836
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      CHANGELOG.md
  2. 33
      apps/block_scout_web/assets/js/lib/smart_contract/functions.js

@ -15,7 +15,7 @@
- [#3506](https://github.com/poanetwork/blockscout/pull/3506) - Fix token trasfer's tile styles: prevent overlapping of long names - [#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 - [#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 - [#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 - [#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 - [#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 - [#3477](https://github.com/poanetwork/blockscout/pull/3477) - Contracts interaction: fix broken call of GnosisProxy contract methods with parameters

@ -135,10 +135,14 @@ function callMethod (isWalletEnabled, $functionInputs, explorerChainId, $form, f
let preparedVal let preparedVal
if (isNonSpaceInputType(inputType)) { preparedVal = val.replace(/\s/g, '') } else { preparedVal = val } if (isNonSpaceInputType(inputType)) { preparedVal = val.replace(/\s/g, '') } else { preparedVal = val }
if (isArrayInputType(inputType)) { if (isArrayInputType(inputType)) {
if (preparedVal.startsWith('[') && preparedVal.endsWith(']')) { if (preparedVal === '') {
preparedVal = preparedVal.substring(1, preparedVal.length - 1) return [[]]
} else {
if (preparedVal.startsWith('[') && preparedVal.endsWith(']')) {
preparedVal = preparedVal.substring(1, preparedVal.length - 1)
}
return [preparedVal.split(',')]
} }
return preparedVal.split(',')
} else { return preparedVal } } else { return preparedVal }
}) })
@ -150,27 +154,8 @@ function callMethod (isWalletEnabled, $functionInputs, explorerChainId, $form, f
.then(currentAccount => { .then(currentAccount => {
if (functionName) { if (functionName) {
const TargetContract = new window.web3.eth.Contract(contractAbi, contractAddress) const TargetContract = new window.web3.eth.Contract(contractAbi, contractAddress)
const inputsCount = inputs && inputs.length
let methodToCall
const sendParams = { from: currentAccount, value: txValue || 0 } const sendParams = { from: currentAccount, value: txValue || 0 }
if (inputsCount > 1 || inputsCount === 0) { const methodToCall = TargetContract.methods[functionName](...args).send(sendParams)
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)
}
}
}
methodToCall methodToCall
.on('error', function (error) { .on('error', function (error) {
openErrorModal(`Error in sending transaction for method "${functionName}"`, formatError(error), false) 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) { function isArrayInputType (inputType) {
return inputType && inputType.includes('[]') return inputType && inputType.includes('[') && inputType.includes(']')
} }
function isNonSpaceInputType (inputType) { function isNonSpaceInputType (inputType) {

Loading…
Cancel
Save