(Fix) Transaction List not loading and handle DCD token (#539)

* Handle DCD token

- treat DCD particularly and hardcode `symbol` and `decimal` values
- for those ALTERNATIVE_TOKEN_ABI contracts, we were converting the `symbol` to ascii, and we had to convert from hex to string instead
- the `incoming-transactions` endpoint is returning the `executionDate`, so no request for that value to the blockchain is required

* remove condition
This commit is contained in:
Fernando 2020-02-10 10:29:54 -03:00 committed by GitHub
parent 30f3483119
commit b938d456c1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 16 additions and 9 deletions

View File

@ -204,10 +204,8 @@ export const buildIncomingTransactionFrom = async (tx: IncomingTxServiceModel) =
let symbol = 'ETH' let symbol = 'ETH'
let decimals = 18 let decimals = 18
const whenExecutionDate = web3.eth.getBlock(tx.blockNumber) const fee = await web3.eth.getTransaction(tx.transactionHash)
.then(({ timestamp }) => new Date(timestamp * 1000).toISOString()) .then(({ gas, gasPrice }) => bn(gas).div(gasPrice).toFixed())
const whenFee = web3.eth.getTransaction(tx.transactionHash).then((t) => bn(t.gas).div(t.gasPrice).toFixed())
const [executionDate, fee] = await Promise.all([whenExecutionDate, whenFee])
if (tx.tokenAddress) { if (tx.tokenAddress) {
try { try {
@ -217,10 +215,20 @@ export const buildIncomingTransactionFrom = async (tx: IncomingTxServiceModel) =
symbol = tokenSymbol symbol = tokenSymbol
decimals = tokenDecimals decimals = tokenDecimals
} catch (err) { } catch (err) {
const { methods } = new web3.eth.Contract(ALTERNATIVE_TOKEN_ABI, tx.tokenAddress) try {
const [tokenSymbol, tokenDecimals] = await Promise.all([methods.symbol, methods.decimals].map((m) => m().call())) const { methods } = new web3.eth.Contract(ALTERNATIVE_TOKEN_ABI, tx.tokenAddress)
symbol = web3.utils.toAscii(tokenSymbol) const [tokenSymbol, tokenDecimals] = await Promise.all([methods.symbol, methods.decimals].map((m) => m()
decimals = tokenDecimals .call()))
symbol = web3.utils.hexToString(tokenSymbol)
decimals = tokenDecimals
} catch (e) {
// this is a particular treatment for the DCD token, as it seems to lack of symbol and decimal methods
if (tx.tokenAddress && tx.tokenAddress.toLowerCase() === '0xe0b7927c4af23765cb51314a0e0521a9645f0e2a') {
symbol = 'DCD'
decimals = 9
}
// if it's not DCD, then we fall to the default values
}
} }
} }
@ -231,7 +239,6 @@ export const buildIncomingTransactionFrom = async (tx: IncomingTxServiceModel) =
symbol, symbol,
decimals, decimals,
fee, fee,
executionDate,
executionTxHash: transactionHash, executionTxHash: transactionHash,
safeTxHash: transactionHash, safeTxHash: transactionHash,
}) })