diff --git a/.gitignore b/.gitignore index a75dc3eb..21b594e6 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,5 @@ build_webpack/ build_storybook/ .DS_Store build/ -yarn-error.log \ No newline at end of file +yarn-error.log +.env.* \ No newline at end of file diff --git a/src/logic/tokens/utils/alternativeAbi.js b/src/logic/tokens/utils/alternativeAbi.js new file mode 100644 index 00000000..c6a8abfb --- /dev/null +++ b/src/logic/tokens/utils/alternativeAbi.js @@ -0,0 +1,47 @@ +// @flow +// https://github.com/ethers-io/ethers.js/issues/527 + +export const ALTERNATIVE_TOKEN_ABI = [ + { + constant: true, + inputs: [], + name: 'name', + outputs: [ + { + name: '', + type: 'bytes32', + }, + ], + payable: false, + stateMutability: 'view', + type: 'function', + }, + { + constant: true, + inputs: [], + name: 'symbol', + outputs: [ + { + name: '', + type: 'bytes32', + }, + ], + payable: false, + stateMutability: 'view', + type: 'function', + }, + { + constant: true, + inputs: [], + name: 'decimals', + outputs: [ + { + name: '', + type: 'uint8', + }, + ], + payable: false, + stateMutability: 'view', + type: 'function', + }, +] diff --git a/src/routes/safe/components/Transactions/TxsTable/columns.js b/src/routes/safe/components/Transactions/TxsTable/columns.js index ca95438a..ff250cad 100644 --- a/src/routes/safe/components/Transactions/TxsTable/columns.js +++ b/src/routes/safe/components/Transactions/TxsTable/columns.js @@ -33,7 +33,8 @@ export const getTxAmount = (tx: Transaction) => { let txAmount = 'n/a' if (tx.isTokenTransfer && tx.decodedParams) { - txAmount = `${new BigNumber(tx.decodedParams.value).div(10 ** tx.decimals.toNumber()).toString()} ${tx.symbol}` + const tokenDecimals = tx.decimals.toNumber ? tx.decimals.toNumber() : tx.decimals + txAmount = `${new BigNumber(tx.decodedParams.value).div(10 ** tokenDecimals).toString()} ${tx.symbol}` } else if (Number(tx.value) > 0) { txAmount = `${fromWei(toBN(tx.value), 'ether')} ${tx.symbol}` } diff --git a/src/routes/safe/store/actions/fetchTransactions.js b/src/routes/safe/store/actions/fetchTransactions.js index cfe3dad5..cca5ac16 100644 --- a/src/routes/safe/store/actions/fetchTransactions.js +++ b/src/routes/safe/store/actions/fetchTransactions.js @@ -16,6 +16,7 @@ import { getHumanFriendlyToken } from '~/logic/tokens/store/actions/fetchTokens' import { isTokenTransfer } from '~/logic/tokens/utils/tokenHelpers' import { TX_TYPE_EXECUTION } from '~/logic/safe/transactions' import { decodeParamsFromSafeMethod } from '~/logic/contracts/methodIds' +import { ALTERNATIVE_TOKEN_ABI } from '~/logic/tokens/utils/alternativeAbi' let web3 @@ -59,8 +60,8 @@ export const buildTransactionFrom = async ( ) const modifySettingsTx = tx.to === safeAddress && Number(tx.value) === 0 && !!tx.data const cancellationTx = tx.to === safeAddress && Number(tx.value) === 0 && !tx.data - const customTx = tx.to !== safeAddress && !!tx.data const isSendTokenTx = await isTokenTransfer(tx.data, tx.value) + const customTx = tx.to !== safeAddress && !!tx.data && !isSendTokenTx let executionTxHash const executionTx = confirmations.find((conf) => conf.type === TX_TYPE_EXECUTION) @@ -74,8 +75,19 @@ export const buildTransactionFrom = async ( let decodedParams if (isSendTokenTx) { const tokenContract = await getHumanFriendlyToken() - const tokenInstance = await tokenContract.at(tx.to); - [symbol, decimals] = await Promise.all([tokenInstance.symbol(), tokenInstance.decimals()]) + const tokenInstance = await tokenContract.at(tx.to) + try { + [symbol, decimals] = await Promise.all([tokenInstance.symbol(), tokenInstance.decimals()]) + } catch (err) { + const alternativeTokenInstance = new web3.eth.Contract(ALTERNATIVE_TOKEN_ABI, tx.to); + const [tokenSymbol, tokenDecimals] = await Promise.all([ + alternativeTokenInstance.methods.symbol().call(), + alternativeTokenInstance.methods.decimals().call(), + ]) + + symbol = web3.utils.toAscii(tokenSymbol) + decimals = tokenDecimals + } const params = web3.eth.abi.decodeParameters(['address', 'uint256'], tx.data.slice(10)) decodedParams = {