|
|
@ -6,6 +6,11 @@ const { removeLeadingZeroes } = require('../send.utils') |
|
|
|
const currencyFormatter = require('currency-formatter') |
|
|
|
const currencyFormatter = require('currency-formatter') |
|
|
|
const currencies = require('currency-formatter/currencies') |
|
|
|
const currencies = require('currency-formatter/currencies') |
|
|
|
const ethUtil = require('ethereumjs-util') |
|
|
|
const ethUtil = require('ethereumjs-util') |
|
|
|
|
|
|
|
const PropTypes = require('prop-types') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CurrencyDisplay.contextTypes = { |
|
|
|
|
|
|
|
t: PropTypes.func, |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
module.exports = CurrencyDisplay |
|
|
|
module.exports = CurrencyDisplay |
|
|
|
|
|
|
|
|
|
|
@ -75,6 +80,12 @@ CurrencyDisplay.prototype.getValueToRender = function ({ selectedToken, conversi |
|
|
|
CurrencyDisplay.prototype.getConvertedValueToRender = function (nonFormattedValue) { |
|
|
|
CurrencyDisplay.prototype.getConvertedValueToRender = function (nonFormattedValue) { |
|
|
|
const { primaryCurrency, convertedCurrency, conversionRate } = this.props |
|
|
|
const { primaryCurrency, convertedCurrency, conversionRate } = this.props |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (conversionRate === 0 || conversionRate === null || conversionRate === undefined) { |
|
|
|
|
|
|
|
if (nonFormattedValue !== 0) { |
|
|
|
|
|
|
|
return null |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
let convertedValue = conversionUtil(nonFormattedValue, { |
|
|
|
let convertedValue = conversionUtil(nonFormattedValue, { |
|
|
|
fromNumericBase: 'dec', |
|
|
|
fromNumericBase: 'dec', |
|
|
|
fromCurrency: primaryCurrency, |
|
|
|
fromCurrency: primaryCurrency, |
|
|
@ -82,10 +93,9 @@ CurrencyDisplay.prototype.getConvertedValueToRender = function (nonFormattedValu |
|
|
|
numberOfDecimals: 2, |
|
|
|
numberOfDecimals: 2, |
|
|
|
conversionRate, |
|
|
|
conversionRate, |
|
|
|
}) |
|
|
|
}) |
|
|
|
convertedValue = Number(convertedValue).toFixed(2) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
convertedValue = Number(convertedValue).toFixed(2) |
|
|
|
const upperCaseCurrencyCode = convertedCurrency.toUpperCase() |
|
|
|
const upperCaseCurrencyCode = convertedCurrency.toUpperCase() |
|
|
|
|
|
|
|
|
|
|
|
return currencies.find(currency => currency.code === upperCaseCurrencyCode) |
|
|
|
return currencies.find(currency => currency.code === upperCaseCurrencyCode) |
|
|
|
? currencyFormatter.format(Number(convertedValue), { |
|
|
|
? currencyFormatter.format(Number(convertedValue), { |
|
|
|
code: upperCaseCurrencyCode, |
|
|
|
code: upperCaseCurrencyCode, |
|
|
@ -105,13 +115,24 @@ CurrencyDisplay.prototype.getInputWidth = function (valueToRender, readOnly) { |
|
|
|
return (valueLength + decimalPointDeficit + 0.75) + 'ch' |
|
|
|
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 () { |
|
|
|
CurrencyDisplay.prototype.render = function () { |
|
|
|
const { |
|
|
|
const { |
|
|
|
className = 'currency-display', |
|
|
|
className = 'currency-display', |
|
|
|
primaryBalanceClassName = 'currency-display__input', |
|
|
|
primaryBalanceClassName = 'currency-display__input', |
|
|
|
convertedBalanceClassName = 'currency-display__converted-value', |
|
|
|
|
|
|
|
primaryCurrency, |
|
|
|
primaryCurrency, |
|
|
|
convertedCurrency, |
|
|
|
|
|
|
|
readOnly = false, |
|
|
|
readOnly = false, |
|
|
|
inError = false, |
|
|
|
inError = false, |
|
|
|
onBlur, |
|
|
|
onBlur, |
|
|
@ -157,11 +178,7 @@ CurrencyDisplay.prototype.render = function () { |
|
|
|
|
|
|
|
|
|
|
|
]), |
|
|
|
]), |
|
|
|
|
|
|
|
|
|
|
|
]), |
|
|
|
]), this.onlyRenderConversions(convertedValueToRender), |
|
|
|
|
|
|
|
|
|
|
|
h('div', { |
|
|
|
|
|
|
|
className: convertedBalanceClassName, |
|
|
|
|
|
|
|
}, `${convertedValueToRender} ${convertedCurrency.toUpperCase()}`), |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
]) |
|
|
|
]) |
|
|
|
|
|
|
|
|
|
|
|