aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWhymarrh Whitby <whymarrh.whitby@gmail.com>2018-07-18 00:46:13 +0800
committerGitHub <noreply@github.com>2018-07-18 00:46:13 +0800
commit9a098a28e08d97a8cd94086ddd59bb19ccbcef54 (patch)
treef5b283d3fc5dd157ffca83418208ca6fd23bfb3e
parentdb4469794e3e843f3cb08222d0a9b568c7816a85 (diff)
parentdcf8e0ed12de61bf58b4d27010b5b8b6d93bd7dd (diff)
downloadtangerine-wallet-browser-9a098a28e08d97a8cd94086ddd59bb19ccbcef54.tar.gz
tangerine-wallet-browser-9a098a28e08d97a8cd94086ddd59bb19ccbcef54.tar.zst
tangerine-wallet-browser-9a098a28e08d97a8cd94086ddd59bb19ccbcef54.zip
Merge pull request #4777 from MetaMask/i4661-currencyConversionBug
Fixes conversion status for tokens without conversion rates (#4661)
-rw-r--r--app/_locales/en/messages.json3
-rw-r--r--ui/app/components/send/currency-display/currency-display.js39
2 files changed, 31 insertions, 11 deletions
diff --git a/app/_locales/en/messages.json b/app/_locales/en/messages.json
index 35e28c087..03f62424c 100644
--- a/app/_locales/en/messages.json
+++ b/app/_locales/en/messages.json
@@ -584,6 +584,9 @@
"noDeposits": {
"message": "No deposits received"
},
+ "noConversionRateAvailable":{
+ "message": "No Conversion Rate Available"
+ },
"noTransactionHistory": {
"message": "No transaction history."
},
diff --git a/ui/app/components/send/currency-display/currency-display.js b/ui/app/components/send/currency-display/currency-display.js
index 1b9f7738c..2b8eaa41f 100644
--- a/ui/app/components/send/currency-display/currency-display.js
+++ b/ui/app/components/send/currency-display/currency-display.js
@@ -6,6 +6,11 @@ const { removeLeadingZeroes } = require('../send.utils')
const currencyFormatter = require('currency-formatter')
const currencies = require('currency-formatter/currencies')
const ethUtil = require('ethereumjs-util')
+const PropTypes = require('prop-types')
+
+CurrencyDisplay.contextTypes = {
+ t: PropTypes.func,
+}
module.exports = CurrencyDisplay
@@ -75,6 +80,12 @@ CurrencyDisplay.prototype.getValueToRender = function ({ selectedToken, conversi
CurrencyDisplay.prototype.getConvertedValueToRender = function (nonFormattedValue) {
const { primaryCurrency, convertedCurrency, conversionRate } = this.props
+ if (conversionRate === 0 || conversionRate === null || conversionRate === undefined) {
+ if (nonFormattedValue !== 0) {
+ return null
+ }
+ }
+
let convertedValue = conversionUtil(nonFormattedValue, {
fromNumericBase: 'dec',
fromCurrency: primaryCurrency,
@@ -82,16 +93,15 @@ CurrencyDisplay.prototype.getConvertedValueToRender = function (nonFormattedValu
numberOfDecimals: 2,
conversionRate,
})
- convertedValue = Number(convertedValue).toFixed(2)
+ convertedValue = Number(convertedValue).toFixed(2)
const upperCaseCurrencyCode = convertedCurrency.toUpperCase()
-
return currencies.find(currency => currency.code === upperCaseCurrencyCode)
? currencyFormatter.format(Number(convertedValue), {
code: upperCaseCurrencyCode,
})
- : convertedValue
-}
+ : convertedValue
+ }
CurrencyDisplay.prototype.handleChange = function (newVal) {
this.setState({ valueToRender: removeLeadingZeroes(newVal) })
@@ -105,13 +115,24 @@ CurrencyDisplay.prototype.getInputWidth = function (valueToRender, readOnly) {
return (valueLength + decimalPointDeficit + 0.75) + 'ch'
}
+CurrencyDisplay.prototype.onlyRenderConversions = function (convertedValueToRender) {
+ const {
+ convertedBalanceClassName = 'currency-display__converted-value',
+ convertedCurrency,
+ } = this.props
+ return h('div', {
+ className: convertedBalanceClassName,
+ }, convertedValueToRender == null
+ ? this.context.t('noConversionRateAvailable')
+ : `${convertedValueToRender} ${convertedCurrency.toUpperCase()}`
+)
+ }
+
CurrencyDisplay.prototype.render = function () {
const {
className = 'currency-display',
primaryBalanceClassName = 'currency-display__input',
- convertedBalanceClassName = 'currency-display__converted-value',
primaryCurrency,
- convertedCurrency,
readOnly = false,
inError = false,
onBlur,
@@ -157,11 +178,7 @@ CurrencyDisplay.prototype.render = function () {
]),
- ]),
-
- h('div', {
- className: convertedBalanceClassName,
- }, `${convertedValueToRender} ${convertedCurrency.toUpperCase()}`),
+ ]), this.onlyRenderConversions(convertedValueToRender),
])