From 7a72b121c5f502d3049383789de9bda744324ac2 Mon Sep 17 00:00:00 2001 From: Victor Baranov Date: Mon, 23 Nov 2020 19:09:13 +0300 Subject: [PATCH] Fix call to fallback function and call of GnosisProxy contract methods --- CHANGELOG.md | 2 ++ .../assets/js/lib/smart_contract/functions.js | 30 +++++++++++-------- apps/explorer/lib/explorer/chain.ex | 3 +- 3 files changed, 21 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8ab56a96fe..721295d160 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ - [#3462](https://github.com/poanetwork/blockscout/pull/3462) - Display price for bridged tokens ### Fixes +- [#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 fallback function - [#3476](https://github.com/poanetwork/blockscout/pull/3476) - Fix contract verification of precompiled contracts - [#3467](https://github.com/poanetwork/blockscout/pull/3467) - Fix Firefox styles - [#3464](https://github.com/poanetwork/blockscout/pull/3464) - Fix display of token transfers list at token page (fix unique identifier of a tile) 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 6f860c02a5..52cc4d7d00 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 @@ -133,30 +133,33 @@ function callMethod (isWalletEnabled, $functionInputs, explorerChainId, $form, f const { chainId: walletChainIdHex } = window.ethereum compareChainIDs(explorerChainId, walletChainIdHex) .then(currentAccount => { - let methodToCall - if (functionName) { const TargetContract = new window.web3.eth.Contract(contractAbi, contractAddress) - methodToCall = TargetContract.methods[functionName](...args).send({ from: currentAccount, value: txValue || 0 }) + const methodToCall = TargetContract.methods[functionName](...args).send({ from: currentAccount, value: txValue || 0 }) + methodToCall + .on('error', function (error) { + openErrorModal(`Error in sending transaction for method "${functionName}"`, formatError(error), false) + }) + .on('transactionHash', function (txHash) { + onTransactionHash(txHash, $element, functionName) + }) } else { const txParams = { from: currentAccount, to: contractAddress, value: txValue || 0 } - methodToCall = window.ethereum.request({ + window.ethereum.request({ method: 'eth_sendTransaction', params: [txParams] }) + .then(function (txHash) { + onTransactionHash(txHash, $element, functionName) + }) + .catch(function (error) { + openErrorModal('Error in sending transaction for fallback method', formatError(error), false) + }) } - - methodToCall - .on('error', function (error) { - openErrorModal(`Error in sending transaction for method "${functionName}"`, formatError(error), false) - }) - .on('transactionHash', function (txHash) { - onTransactionHash(txHash, $element, functionName) - }) }) .catch(error => { openWarningModal('Unauthorized', formatError(error)) @@ -167,7 +170,8 @@ function getTxValue ($functionInputs) { const WEI_MULTIPLIER = 10 ** 18 const $txValue = $functionInputs.filter('[tx-value]:first') const txValue = $txValue && $txValue.val() && parseFloat($txValue.val()) * WEI_MULTIPLIER - return txValue + const txValueStr = txValue && txValue.toString(16) + return txValueStr } function getContractABI ($form) { diff --git a/apps/explorer/lib/explorer/chain.ex b/apps/explorer/lib/explorer/chain.ex index 1f7e79ba3e..d3a7f2a403 100644 --- a/apps/explorer/lib/explorer/chain.ex +++ b/apps/explorer/lib/explorer/chain.ex @@ -5525,7 +5525,8 @@ defmodule Explorer.Chain do implementation_method_abi = abi |> Enum.find(fn method -> - Map.get(method, "name") == "implementation" + Map.get(method, "name") == "implementation" || + master_copy_pattern?(method) end) if implementation_method_abi do