mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Update onlyRenderConversions function to method and account for edge cases
This commit is contained in:
parent
8d8de0508a
commit
4014b279d7
@ -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),
|
||||
|
||||
])
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user