mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Internationalize converted value in currency-input.js
This commit is contained in:
parent
4011dac6f6
commit
1382de2cda
@ -3,6 +3,8 @@ const h = require('react-hyperscript')
|
|||||||
const inherits = require('util').inherits
|
const inherits = require('util').inherits
|
||||||
const CurrencyInput = require('../currency-input')
|
const CurrencyInput = require('../currency-input')
|
||||||
const { conversionUtil, multiplyCurrencies } = require('../../conversion-util')
|
const { conversionUtil, multiplyCurrencies } = require('../../conversion-util')
|
||||||
|
const currencyFormatter = require('currency-formatter')
|
||||||
|
const currencies = require('currency-formatter/currencies');
|
||||||
|
|
||||||
module.exports = CurrencyDisplay
|
module.exports = CurrencyDisplay
|
||||||
|
|
||||||
@ -53,12 +55,32 @@ CurrencyDisplay.prototype.getValueToRender = function () {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CurrencyDisplay.prototype.getConvertedValueToRender = function (nonFormattedValue) {
|
||||||
|
const { primaryCurrency, convertedCurrency, conversionRate } = this.props
|
||||||
|
|
||||||
|
let convertedValue = conversionUtil(nonFormattedValue, {
|
||||||
|
fromNumericBase: 'dec',
|
||||||
|
fromCurrency: primaryCurrency,
|
||||||
|
toCurrency: convertedCurrency,
|
||||||
|
numberOfDecimals: 2,
|
||||||
|
conversionRate,
|
||||||
|
})
|
||||||
|
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.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',
|
convertedBalanceClassName = 'currency-display__converted-value',
|
||||||
conversionRate,
|
|
||||||
primaryCurrency,
|
primaryCurrency,
|
||||||
convertedCurrency,
|
convertedCurrency,
|
||||||
readOnly = false,
|
readOnly = false,
|
||||||
@ -68,14 +90,7 @@ CurrencyDisplay.prototype.render = function () {
|
|||||||
|
|
||||||
const valueToRender = this.getValueToRender()
|
const valueToRender = this.getValueToRender()
|
||||||
|
|
||||||
let convertedValue = conversionUtil(valueToRender, {
|
const convertedValueToRender = this.getConvertedValueToRender(valueToRender)
|
||||||
fromNumericBase: 'dec',
|
|
||||||
fromCurrency: primaryCurrency,
|
|
||||||
toCurrency: convertedCurrency,
|
|
||||||
numberOfDecimals: 2,
|
|
||||||
conversionRate,
|
|
||||||
})
|
|
||||||
convertedValue = Number(convertedValue).toFixed(2)
|
|
||||||
|
|
||||||
return h('div', {
|
return h('div', {
|
||||||
className,
|
className,
|
||||||
@ -108,7 +123,7 @@ CurrencyDisplay.prototype.render = function () {
|
|||||||
|
|
||||||
h('div', {
|
h('div', {
|
||||||
className: convertedBalanceClassName,
|
className: convertedBalanceClassName,
|
||||||
}, `${convertedValue} ${convertedCurrency.toUpperCase()}`),
|
}, `${convertedValueToRender} ${convertedCurrency.toUpperCase()}`),
|
||||||
|
|
||||||
])
|
])
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user