aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSara Reynolds <sarareynolds@Saras-MacBook-Pro-2.local>2018-07-14 04:11:43 +0800
committerSara Reynolds <sarareynolds@Saras-MacBook-Pro-2.local>2018-07-17 04:03:23 +0800
commit4014b279d7f02dcf90a289d7ef5d3cd27d953ee4 (patch)
treeb32dca5477d476617ac4e177f61ffe15b223aaf9
parent8d8de0508ab3cb67870d0c00469ee39f3be06714 (diff)
downloadtangerine-wallet-browser-4014b279d7f02dcf90a289d7ef5d3cd27d953ee4.tar
tangerine-wallet-browser-4014b279d7f02dcf90a289d7ef5d3cd27d953ee4.tar.gz
tangerine-wallet-browser-4014b279d7f02dcf90a289d7ef5d3cd27d953ee4.tar.bz2
tangerine-wallet-browser-4014b279d7f02dcf90a289d7ef5d3cd27d953ee4.tar.lz
tangerine-wallet-browser-4014b279d7f02dcf90a289d7ef5d3cd27d953ee4.tar.xz
tangerine-wallet-browser-4014b279d7f02dcf90a289d7ef5d3cd27d953ee4.tar.zst
tangerine-wallet-browser-4014b279d7f02dcf90a289d7ef5d3cd27d953ee4.zip
Update onlyRenderConversions function to method and account for edge cases
-rw-r--r--ui/app/components/send/currency-display/currency-display.js50
1 files changed, 24 insertions, 26 deletions
diff --git a/ui/app/components/send/currency-display/currency-display.js b/ui/app/components/send/currency-display/currency-display.js
index 70fc9de70..12ddc3d53 100644
--- a/ui/app/components/send/currency-display/currency-display.js
+++ b/ui/app/components/send/currency-display/currency-display.js
@@ -75,6 +75,10 @@ CurrencyDisplay.prototype.getValueToRender = function ({ selectedToken, conversi
CurrencyDisplay.prototype.getConvertedValueToRender = function (nonFormattedValue) {
const { primaryCurrency, convertedCurrency, conversionRate } = this.props
+ if (conversionRate == 0 || conversionRate == null || converstionRate == undefined && nonFormattedValue != 0) {
+ return null
+ }
+
let convertedValue = conversionUtil(nonFormattedValue, {
fromNumericBase: 'dec',
fromCurrency: primaryCurrency,
@@ -83,19 +87,13 @@ CurrencyDisplay.prototype.getConvertedValueToRender = function (nonFormattedValu
conversionRate,
})
- if (conversionRate == 0 && nonFormattedValue != 0) {
- convertedValue = null
- return convertedValue
- }
- else {
- convertedValue == Number(convertedValue).toFixed(2)
- const upperCaseCurrencyCode = convertedCurrency.toUpperCase()
- return currencies.find(currency => currency.code === upperCaseCurrencyCode)
- ? currencyFormatter.format(Number(convertedValue), {
- code: upperCaseCurrencyCode,
- })
+ convertedValue == Number(convertedValue).toFixed(2)
+ const upperCaseCurrencyCode = convertedCurrency.toUpperCase()
+ return currencies.find(currency => currency.code === upperCaseCurrencyCode)
+ ? currencyFormatter.format(Number(convertedValue), {
+ code: upperCaseCurrencyCode,
+ })
: convertedValue
- }
}
CurrencyDisplay.prototype.handleChange = function (newVal) {
@@ -110,6 +108,19 @@ 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
+ ? 'No Conversion Rate'
+ : `${convertedValueToRender} ${convertedCurrency.toUpperCase()}`
+)
+ }
CurrencyDisplay.prototype.render = function () {
const {
@@ -127,19 +138,6 @@ CurrencyDisplay.prototype.render = function () {
const convertedValueToRender = this.getConvertedValueToRender(valueToRender)
- function onlyRenderConversions() {
- if (convertedValueToRender == null) {
- return h('div', {
- className: convertedBalanceClassName,
- }, 'No Conversion Rate')
- }
- else {
- return h('div', {
- className: convertedBalanceClassName,
- }, `${convertedValueToRender} ${convertedCurrency.toUpperCase()}`)
- }
- }
-
return h('div', {
className,
style: {
@@ -176,7 +174,7 @@ CurrencyDisplay.prototype.render = function () {
]),
- ]), onlyRenderConversions(),
+ ]), this.onlyRenderConversions(convertedValueToRender),
])