aboutsummaryrefslogtreecommitdiffstats
path: root/ui/app/components
diff options
context:
space:
mode:
Diffstat (limited to 'ui/app/components')
-rw-r--r--ui/app/components/token-cell.js28
-rw-r--r--ui/app/components/tx-list-item.js33
2 files changed, 46 insertions, 15 deletions
diff --git a/ui/app/components/token-cell.js b/ui/app/components/token-cell.js
index 6bb42204e..f55e23f9e 100644
--- a/ui/app/components/token-cell.js
+++ b/ui/app/components/token-cell.js
@@ -6,7 +6,7 @@ const Identicon = require('./identicon')
const prefixForNetwork = require('../../lib/etherscan-prefix-for-network')
const selectors = require('../selectors')
const actions = require('../actions')
-const { conversionUtil } = require('../conversion-util')
+const { conversionUtil, multiplyCurrencies } = require('../conversion-util')
const TokenMenuDropdown = require('./dropdowns/token-menu-dropdown.js')
@@ -17,7 +17,7 @@ function mapStateToProps (state) {
selectedTokenAddress: state.metamask.selectedTokenAddress,
userAddress: selectors.getSelectedAddress(state),
tokenExchangeRates: state.metamask.tokenExchangeRates,
- ethToUSDRate: state.metamask.conversionRate,
+ conversionRate: state.metamask.conversionRate,
sidebarOpen: state.appState.sidebarOpen,
}
}
@@ -61,7 +61,7 @@ TokenCell.prototype.render = function () {
setSelectedToken,
selectedTokenAddress,
tokenExchangeRates,
- ethToUSDRate,
+ conversionRate,
hideSidebar,
sidebarOpen,
currentCurrency,
@@ -70,22 +70,26 @@ TokenCell.prototype.render = function () {
const pair = `${symbol.toLowerCase()}_eth`;
- let currentTokenToEthRate;
+ let currentTokenToFiatRate;
let currentTokenInFiat;
- let formattedUSD = ''
+ let formattedFiat = ''
if (tokenExchangeRates[pair]) {
- currentTokenToEthRate = tokenExchangeRates[pair].rate;
+ currentTokenToFiatRate = multiplyCurrencies(
+ tokenExchangeRates[pair].rate,
+ conversionRate
+ )
currentTokenInFiat = conversionUtil(string, {
fromNumericBase: 'dec',
fromCurrency: symbol,
- toCurrency: 'USD',
+ toCurrency: currentCurrency.toUpperCase(),
numberOfDecimals: 2,
- conversionRate: currentTokenToEthRate,
- ethToUSDRate,
+ conversionRate: currentTokenToFiatRate,
})
- formattedUSD = `${currentTokenInFiat} ${currentCurrency.toUpperCase()}`;
+ formattedFiat = `${currentTokenInFiat} ${currentCurrency.toUpperCase()}`;
}
+
+ const showFiat = Boolean(currentTokenInFiat) && currentCurrency.toUpperCase() !== symbol
return (
h('div.token-list-item', {
@@ -108,9 +112,9 @@ TokenCell.prototype.render = function () {
h('h.token-list-item__balance-wrapper', null, [
h('h3.token-list-item__token-balance', `${string || 0} ${symbol}`),
- h('div.token-list-item__fiat-amount', {
+ showFiat && h('div.token-list-item__fiat-amount', {
style: {},
- }, formattedUSD),
+ }, formattedFiat),
]),
h('i.fa.fa-ellipsis-h.fa-lg.token-list-item__ellipsis.cursor-pointer', {
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),
]),
]),