aboutsummaryrefslogtreecommitdiffstats
path: root/ui/app/components/tx-list-item.js
diff options
context:
space:
mode:
authorDan J Miller <danjm.com@gmail.com>2017-10-27 13:55:34 +0800
committerDaniel Tsui <szehungdanieltsui@gmail.com>2017-10-27 13:55:34 +0800
commit3d53716f4366212ed7a51b49ce747584b13fd1ce (patch)
tree25b5449b236ba7502dd0d481e27e65c40a7cafe8 /ui/app/components/tx-list-item.js
parent0ed1add110ec630ed358aa44af030623bab1ad92 (diff)
downloadtangerine-wallet-browser-3d53716f4366212ed7a51b49ce747584b13fd1ce.tar.gz
tangerine-wallet-browser-3d53716f4366212ed7a51b49ce747584b13fd1ce.tar.zst
tangerine-wallet-browser-3d53716f4366212ed7a51b49ce747584b13fd1ce.zip
Correct rendering of conversions when conversion rate is a token. (#2498)
Diffstat (limited to 'ui/app/components/tx-list-item.js')
-rw-r--r--ui/app/components/tx-list-item.js33
1 files changed, 30 insertions, 3 deletions
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),
]),
]),