decode erc20 params for tx list

This commit is contained in:
mmv 2019-07-10 15:54:13 +04:00
parent a199b0588a
commit d7ef87b0bf
1 changed files with 15 additions and 2 deletions

View File

@ -9,12 +9,15 @@ import { makeConfirmation } from '~/routes/safe/store/models/confirmation'
import { loadSafeSubjects } from '~/utils/storage/transactions' import { loadSafeSubjects } from '~/utils/storage/transactions'
import { buildTxServiceUrl, type TxServiceType } from '~/logic/safe/transactions/txHistory' import { buildTxServiceUrl, type TxServiceType } from '~/logic/safe/transactions/txHistory'
import { getOwners } from '~/logic/safe/utils' import { getOwners } from '~/logic/safe/utils'
import { getWeb3 } from '~/logic/wallets/getWeb3'
import { EMPTY_DATA } from '~/logic/wallets/ethTransactions' import { EMPTY_DATA } from '~/logic/wallets/ethTransactions'
import { addTransactions } from './addTransactions' import { addTransactions } from './addTransactions'
import { getHumanFriendlyToken } from '~/logic/tokens/store/actions/fetchTokens' import { getHumanFriendlyToken } from '~/logic/tokens/store/actions/fetchTokens'
import { isAddressAToken } from '~/logic/tokens/utils/tokenHelpers' import { isAddressAToken } from '~/logic/tokens/utils/tokenHelpers'
import { TX_TYPE_EXECUTION, TX_TYPE_CONFIRMATION } from '~/logic/safe/transactions/send' import { TX_TYPE_EXECUTION, TX_TYPE_CONFIRMATION } from '~/logic/safe/transactions/send'
let web3
type ConfirmationServiceModel = { type ConfirmationServiceModel = {
owner: string, owner: string,
submissionDate: Date, submissionDate: Date,
@ -59,19 +62,27 @@ const buildTransactionFrom = async (safeAddress: string, tx: TxServiceModel, saf
} }
let symbol = 'ETH' let symbol = 'ETH'
let recipient = tx.to
let value = tx.value.toString()
if (isToken) { if (isToken) {
const tokenContract = await getHumanFriendlyToken() const tokenContract = await getHumanFriendlyToken()
const tokenInstance = await tokenContract.at(tx.to) const tokenInstance = await tokenContract.at(tx.to)
symbol = await tokenInstance.symbol() symbol = await tokenInstance.symbol()
const decodedParams = web3.eth.abi.decodeParameters(['address', 'uint256'], tx.data.slice(10))
/* eslint-disable */
recipient = decodedParams[0]
value = decodedParams[1]
/* eslint-enable */
} }
return makeTransaction({ return makeTransaction({
name, name,
symbol, symbol,
nonce: tx.nonce, nonce: tx.nonce,
value: tx.value.toString(), value,
confirmations, confirmations,
recipient: tx.to, recipient,
data: tx.data ? tx.data : EMPTY_DATA, data: tx.data ? tx.data : EMPTY_DATA,
isExecuted: tx.isExecuted, isExecuted: tx.isExecuted,
submissionDate: tx.submissionDate, submissionDate: tx.submissionDate,
@ -82,6 +93,8 @@ const buildTransactionFrom = async (safeAddress: string, tx: TxServiceModel, saf
} }
export const loadSafeTransactions = async (safeAddress: string) => { export const loadSafeTransactions = async (safeAddress: string) => {
web3 = await getWeb3()
const url = buildTxServiceUrl(safeAddress) const url = buildTxServiceUrl(safeAddress)
const response = await axios.get(url) const response = await axios.get(url)
const transactions: TxServiceModel[] = response.data.results const transactions: TxServiceModel[] = response.data.results