show ERC20 token amount in txs table col
This commit is contained in:
parent
ff49f3c6c2
commit
95105237c2
|
@ -28,18 +28,31 @@ type TxData = {
|
|||
|
||||
export const formatDate = (date: Date): string => format(date, 'MMM D, YYYY - HH:mm:ss')
|
||||
|
||||
export const getTxAmount = (tx: Transaction) => {
|
||||
let txAmount = 'n/a'
|
||||
|
||||
if (tx.isTokenTransfer && tx.decodedParams) {
|
||||
txAmount = `${fromWei(toBN(tx.decodedParams.value), 'ether')} ${tx.symbol}`
|
||||
} else if (Number(tx.value) > 0) {
|
||||
txAmount = `${fromWei(toBN(tx.value), 'ether')} ${tx.symbol}`
|
||||
}
|
||||
|
||||
return txAmount
|
||||
}
|
||||
|
||||
export type TransactionRow = SortRow<TxData>
|
||||
|
||||
export const getTxTableData = (transactions: List<Transaction>): List<TransactionRow> => {
|
||||
const rows = transactions.map((tx: Transaction) => {
|
||||
const txDate = tx.isExecuted ? tx.executionDate : tx.submissionDate
|
||||
|
||||
|
||||
return {
|
||||
[TX_TABLE_NONCE_ID]: tx.nonce,
|
||||
[TX_TABLE_TYPE_ID]: 'Outgoing transfer',
|
||||
[TX_TABLE_DATE_ID]: formatDate(tx.isExecuted ? tx.executionDate : tx.submissionDate),
|
||||
[buildOrderFieldFrom(TX_TABLE_DATE_ID)]: getTime(txDate),
|
||||
[TX_TABLE_AMOUNT_ID]: Number(tx.value) > 0 ? `${fromWei(toBN(tx.value), 'ether')} ${tx.symbol}` : 'n/a',
|
||||
[TX_TABLE_AMOUNT_ID]: getTxAmount(tx),
|
||||
[TX_TABLE_STATUS_ID]: tx.status,
|
||||
[TX_TABLE_RAW_TX_ID]: tx,
|
||||
}
|
||||
|
|
|
@ -51,7 +51,7 @@ const buildTransactionFrom = async (safeAddress: string, tx: TxServiceModel, saf
|
|||
})
|
||||
}),
|
||||
)
|
||||
const isToken = await isAddressAToken(tx.to)
|
||||
const isTokenTransfer = await isAddressAToken(tx.to)
|
||||
const creationTxHash = confirmations.findLast(conf => conf.type === TX_TYPE_CONFIRMATION).hash
|
||||
|
||||
let executionTxHash
|
||||
|
@ -63,7 +63,7 @@ const buildTransactionFrom = async (safeAddress: string, tx: TxServiceModel, saf
|
|||
|
||||
let symbol = 'ETH'
|
||||
let decodedParams
|
||||
if (isToken) {
|
||||
if (isTokenTransfer) {
|
||||
const tokenContract = await getHumanFriendlyToken()
|
||||
const tokenInstance = await tokenContract.at(tx.to)
|
||||
symbol = await tokenInstance.symbol()
|
||||
|
@ -88,7 +88,7 @@ const buildTransactionFrom = async (safeAddress: string, tx: TxServiceModel, saf
|
|||
executionDate: tx.executionDate,
|
||||
executionTxHash,
|
||||
creationTxHash,
|
||||
isToken,
|
||||
isTokenTransfer,
|
||||
decodedParams,
|
||||
})
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ export type TransactionProps = {
|
|||
executionTxHash?: string,
|
||||
cancelled?: boolean,
|
||||
status?: TransactionStatus,
|
||||
isToken: boolean,
|
||||
isTokenTransfer: boolean,
|
||||
decodedParams?: Object,
|
||||
}
|
||||
|
||||
|
@ -39,7 +39,7 @@ export const makeTransaction: RecordFactory<TransactionProps> = Record({
|
|||
creationTxHash: '',
|
||||
cancelled: false,
|
||||
status: 'awaiting',
|
||||
isToken: false,
|
||||
isTokenTransfer: false,
|
||||
decodedParams: {},
|
||||
})
|
||||
|
||||
|
|
Loading…
Reference in New Issue