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:
commit
07f4e814f4
|
@ -4,3 +4,4 @@ build_storybook/
|
||||||
.DS_Store
|
.DS_Store
|
||||||
build/
|
build/
|
||||||
yarn-error.log
|
yarn-error.log
|
||||||
|
.env.*
|
|
@ -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',
|
||||||
|
},
|
||||||
|
]
|
|
@ -33,7 +33,8 @@ export const getTxAmount = (tx: Transaction) => {
|
||||||
let txAmount = 'n/a'
|
let txAmount = 'n/a'
|
||||||
|
|
||||||
if (tx.isTokenTransfer && tx.decodedParams) {
|
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) {
|
} else if (Number(tx.value) > 0) {
|
||||||
txAmount = `${fromWei(toBN(tx.value), 'ether')} ${tx.symbol}`
|
txAmount = `${fromWei(toBN(tx.value), 'ether')} ${tx.symbol}`
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,7 @@ import { getHumanFriendlyToken } from '~/logic/tokens/store/actions/fetchTokens'
|
||||||
import { isTokenTransfer } from '~/logic/tokens/utils/tokenHelpers'
|
import { isTokenTransfer } from '~/logic/tokens/utils/tokenHelpers'
|
||||||
import { TX_TYPE_EXECUTION } from '~/logic/safe/transactions'
|
import { TX_TYPE_EXECUTION } from '~/logic/safe/transactions'
|
||||||
import { decodeParamsFromSafeMethod } from '~/logic/contracts/methodIds'
|
import { decodeParamsFromSafeMethod } from '~/logic/contracts/methodIds'
|
||||||
|
import { ALTERNATIVE_TOKEN_ABI } from '~/logic/tokens/utils/alternativeAbi'
|
||||||
|
|
||||||
let web3
|
let web3
|
||||||
|
|
||||||
|
@ -59,8 +60,8 @@ export const buildTransactionFrom = async (
|
||||||
)
|
)
|
||||||
const modifySettingsTx = tx.to === safeAddress && Number(tx.value) === 0 && !!tx.data
|
const modifySettingsTx = tx.to === safeAddress && Number(tx.value) === 0 && !!tx.data
|
||||||
const cancellationTx = 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 isSendTokenTx = await isTokenTransfer(tx.data, tx.value)
|
||||||
|
const customTx = tx.to !== safeAddress && !!tx.data && !isSendTokenTx
|
||||||
|
|
||||||
let executionTxHash
|
let executionTxHash
|
||||||
const executionTx = confirmations.find((conf) => conf.type === TX_TYPE_EXECUTION)
|
const executionTx = confirmations.find((conf) => conf.type === TX_TYPE_EXECUTION)
|
||||||
|
@ -74,8 +75,19 @@ export const buildTransactionFrom = async (
|
||||||
let decodedParams
|
let decodedParams
|
||||||
if (isSendTokenTx) {
|
if (isSendTokenTx) {
|
||||||
const tokenContract = await getHumanFriendlyToken()
|
const tokenContract = await getHumanFriendlyToken()
|
||||||
const tokenInstance = await tokenContract.at(tx.to);
|
const tokenInstance = await tokenContract.at(tx.to)
|
||||||
|
try {
|
||||||
[symbol, decimals] = await Promise.all([tokenInstance.symbol(), tokenInstance.decimals()])
|
[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))
|
const params = web3.eth.abi.decodeParameters(['address', 'uint256'], tx.data.slice(10))
|
||||||
decodedParams = {
|
decodedParams = {
|
||||||
|
|
Loading…
Reference in New Issue