diff options
Improve display of crypto currencies when selected as the 'Current Conversion'
Diffstat (limited to 'ui')
-rw-r--r-- | ui/app/components/balance-component.js | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/ui/app/components/balance-component.js b/ui/app/components/balance-component.js index 22f5920a6..67e84bd5a 100644 --- a/ui/app/components/balance-component.js +++ b/ui/app/components/balance-component.js @@ -5,6 +5,7 @@ const inherits = require('util').inherits const TokenBalance = require('./token-balance') const Identicon = require('./identicon') const currencyFormatter = require('currency-formatter') +const currencies = require('currency-formatter/currencies'); const { formatBalance, generateBalanceObject } = require('../util') @@ -98,9 +99,13 @@ BalanceComponent.prototype.renderFiatAmount = function (fiatDisplayNumber, fiatS const shouldNotRenderFiat = fiatDisplayNumber === 'N/A' || Number(fiatDisplayNumber) === 0 if (shouldNotRenderFiat) return null - const display = currencyFormatter.format(Number(fiatDisplayNumber), { - code: fiatSuffix.toUpperCase(), - }) + const upperCaseFiatSuffix = fiatSuffix.toUpperCase() + + const display = currencies.find(currency => currency.code === upperCaseFiatSuffix) + ? currencyFormatter.format(Number(fiatDisplayNumber), { + code: upperCaseFiatSuffix, + }) + : `${fiatPrefix}${fiatDisplayNumber} ${upperCaseFiatSuffix}` return h('div.fiat-amount', { style: {}, @@ -122,5 +127,9 @@ BalanceComponent.prototype.getFiatDisplayNumber = function (formattedBalance, co const splitBalance = formattedBalance.split(' ') - return (Number(splitBalance[0]) * conversionRate).toFixed(2) + const convertedNumber = (Number(splitBalance[0]) * conversionRate) + const wholePart = Math.floor(convertedNumber) + const decimalPart = convertedNumber - wholePart + + return wholePart + Number(decimalPart.toPrecision(2)) } |