From 3d53716f4366212ed7a51b49ce747584b13fd1ce Mon Sep 17 00:00:00 2001 From: Dan J Miller Date: Fri, 27 Oct 2017 03:25:34 -0230 Subject: Correct rendering of conversions when conversion rate is a token. (#2498) --- ui/app/components/tx-list-item.js | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) (limited to 'ui/app/components/tx-list-item.js') diff --git a/ui/app/components/tx-list-item.js b/ui/app/components/tx-list-item.js index 3bb9a2eda..84026700b 100644 --- a/ui/app/components/tx-list-item.js +++ b/ui/app/components/tx-list-item.js @@ -9,7 +9,7 @@ abiDecoder.addABI(abi) const prefixForNetwork = require('../../lib/etherscan-prefix-for-network') const Identicon = require('./identicon') -const { conversionUtil } = require('../conversion-util') +const { conversionUtil, multiplyCurrencies } = require('../conversion-util') const { getCurrentCurrency } = require('../selectors') @@ -19,6 +19,7 @@ function mapStateToProps (state) { return { tokens: state.metamask.tokens, currentCurrency: getCurrentCurrency(state), + tokenExchangeRates: state.metamask.tokenExchangeRates, } } @@ -88,6 +89,9 @@ TxListItem.prototype.getSendTokenTotal = function () { const { txParams = {}, tokens, + conversionRate, + tokenExchangeRates, + currentCurrency, } = this.props const toAddress = txParams.to @@ -95,12 +99,35 @@ TxListItem.prototype.getSendTokenTotal = function () { const { params = [] } = decodedData || {} const { value } = params[1] || {} const { decimals, symbol } = tokens.filter(({ address }) => address === toAddress)[0] || {} - const multiplier = Math.pow(10, Number(decimals || 0)) const total = Number(value / multiplier) + const pair = symbol && `${symbol.toLowerCase()}_eth`; + + let tokenToFiatRate + let totalInFiat + + if (tokenExchangeRates[pair]) { + tokenToFiatRate = multiplyCurrencies( + tokenExchangeRates[pair].rate, + conversionRate + ) + + totalInFiat = conversionUtil(total, { + fromNumericBase: 'dec', + toNumericBase: 'dec', + fromCurrency: symbol, + toCurrency: currentCurrency, + numberOfDecimals: 2, + conversionRate: tokenToFiatRate, + }) + } + + const showFiat = Boolean(totalInFiat) && currentCurrency.toUpperCase() !== symbol + return { total: `${total} ${symbol}`, + fiatTotal: showFiat && `${totalInFiat} ${currentCurrency.toUpperCase()}`, } } @@ -182,7 +209,7 @@ TxListItem.prototype.render = function () { }), }, total), - h('span.tx-list-fiat-value', fiatTotal), + fiatTotal && h('span.tx-list-fiat-value', fiatTotal), ]), ]), -- cgit