Merge pull request #230 from gnosis/hotfix/dai-token-symbol-return

Hotfix: Transactions don't show up if there's DAI token tx
This commit is contained in:
Mikhail Mikheev 2019-10-23 17:20:00 +04:00 committed by GitHub
commit 07f4e814f4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 66 additions and 5 deletions

3
.gitignore vendored
View File

@ -3,4 +3,5 @@ build_webpack/
build_storybook/
.DS_Store
build/
yarn-error.log
yarn-error.log
.env.*

View File

@ -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',
},
]

View File

@ -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}`
}

View File

@ -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 = {