aboutsummaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
authorDan <danjm.com@gmail.com>2017-09-15 20:31:25 +0800
committerChi Kei Chan <chikeichan@gmail.com>2017-09-16 07:16:41 +0800
commit095d327140fe4bb2b4a131a66e2774bdfeb8ce37 (patch)
tree559c3d59d438c25a0015cac707767d7b5779170e /ui
parentab77142c90a532a775636cf20a7e23191ff47f8f (diff)
downloadtangerine-wallet-browser-095d327140fe4bb2b4a131a66e2774bdfeb8ce37.tar.gz
tangerine-wallet-browser-095d327140fe4bb2b4a131a66e2774bdfeb8ce37.tar.zst
tangerine-wallet-browser-095d327140fe4bb2b4a131a66e2774bdfeb8ce37.zip
Adds USD to token list.
Diffstat (limited to 'ui')
-rw-r--r--ui/app/components/token-cell.js40
-rw-r--r--ui/app/conversion-util.js4
2 files changed, 41 insertions, 3 deletions
diff --git a/ui/app/components/token-cell.js b/ui/app/components/token-cell.js
index a6fe8fc61..dc1c7f46f 100644
--- a/ui/app/components/token-cell.js
+++ b/ui/app/components/token-cell.js
@@ -6,18 +6,22 @@ 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')
function mapStateToProps (state) {
return {
network: state.metamask.network,
selectedTokenAddress: state.metamask.selectedTokenAddress,
userAddress: selectors.getSelectedAddress(state),
+ tokenExchangeRates: state.metamask.tokenExchangeRates,
+ ethToUSDRate: state.metamask.conversionRate,
}
}
function mapDispatchToProps (dispatch) {
return {
setSelectedToken: address => dispatch(actions.setSelectedToken(address)),
+ updateTokenExchangeRate: token => dispatch(actions.updateTokenExchangeRate(token)),
}
}
@@ -28,6 +32,15 @@ function TokenCell () {
Component.call(this)
}
+TokenCell.prototype.componentWillMount = function () {
+ const {
+ updateTokenExchangeRate,
+ symbol,
+ } = this.props
+
+ updateTokenExchangeRate(symbol)
+}
+
TokenCell.prototype.render = function () {
const props = this.props
const {
@@ -37,8 +50,29 @@ TokenCell.prototype.render = function () {
network,
setSelectedToken,
selectedTokenAddress,
+ tokenExchangeRates,
+ ethToUSDRate,
// userAddress,
} = props
+
+ const pair = `${symbol.toLowerCase()}_eth`;
+
+ let currentTokenToEthRate;
+ let currentTokenInUSD;
+ let formattedUSD = ''
+
+ if (tokenExchangeRates[pair]) {
+ currentTokenToEthRate = tokenExchangeRates[pair].rate;
+ currentTokenInUSD = conversionUtil(string, {
+ fromNumericBase: 'dec',
+ fromCurrency: symbol,
+ toCurrency: 'USD',
+ numberOfDecimals: 2,
+ conversionRate: currentTokenToEthRate,
+ ethToUSDRate,
+ })
+ formattedUSD = `$${currentTokenInUSD} USD`;
+ }
return (
h('div.token-list-item', {
@@ -58,9 +92,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', {
- // style: {},
- // }, '210 FPO'),
+ h('div.token-list-item__fiat-amount', {
+ style: {},
+ }, formattedUSD),
]),
/*
diff --git a/ui/app/conversion-util.js b/ui/app/conversion-util.js
index 5e1125194..847650758 100644
--- a/ui/app/conversion-util.js
+++ b/ui/app/conversion-util.js
@@ -13,6 +13,7 @@
* @param {string} [options.fromDenomination = 'WEI'] The denomination of the passed value
* @param {number} [options.numberOfDecimals] The desired number of in the result
* @param {number} [options.conversionRate] The rate to use to make the fromCurrency -> toCurrency conversion
+* @param {number} [options.ethToUSDRate] If present, a second conversion - at ethToUSDRate - happens after conversionRate is applied.
* @returns {(number | string | BN)}
*
* The utility passes value along with the options as a single object to the `converter` function.
@@ -80,6 +81,7 @@ const converter = R.pipe(
whenPropApplySetterMap('fromNumericBase', toBigNumber),
whenPropApplySetterMap('fromDenomination', toNormalizedDenomination),
whenPredSetWithPropAndSetter(fromAndToCurrencyPropsNotEqual, 'conversionRate', convert),
+ whenPredSetWithPropAndSetter(R.prop('ethToUSDRate'), 'ethToUSDRate', convert),
whenPredSetWithPropAndSetter(R.prop('numberOfDecimals'), 'numberOfDecimals', round),
whenPropApplySetterMap('toNumericBase', baseChange),
R.view(R.lensProp('value'))
@@ -93,6 +95,7 @@ const conversionUtil = (value, {
fromDenomination,
numberOfDecimals,
conversionRate,
+ ethToUSDRate,
}) => converter({
fromCurrency,
toCurrency,
@@ -101,6 +104,7 @@ const conversionUtil = (value, {
fromDenomination,
numberOfDecimals,
conversionRate,
+ ethToUSDRate,
value,
});