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) {
|
CurrencyDisplay.prototype.getConvertedValueToRender = function (nonFormattedValue) {
|
||||||
const { primaryCurrency, convertedCurrency, conversionRate } = this.props
|
const { primaryCurrency, convertedCurrency, conversionRate } = this.props
|
||||||
|
|
||||||
|
if (conversionRate == 0 || conversionRate == null || converstionRate == undefined && nonFormattedValue != 0) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
let convertedValue = conversionUtil(nonFormattedValue, {
|
let convertedValue = conversionUtil(nonFormattedValue, {
|
||||||
fromNumericBase: 'dec',
|
fromNumericBase: 'dec',
|
||||||
fromCurrency: primaryCurrency,
|
fromCurrency: primaryCurrency,
|
||||||
@ -83,11 +87,6 @@ CurrencyDisplay.prototype.getConvertedValueToRender = function (nonFormattedValu
|
|||||||
conversionRate,
|
conversionRate,
|
||||||
})
|
})
|
||||||
|
|
||||||
if (conversionRate == 0 && nonFormattedValue != 0) {
|
|
||||||
convertedValue = null
|
|
||||||
return convertedValue
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
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)
|
||||||
@ -96,7 +95,6 @@ CurrencyDisplay.prototype.getConvertedValueToRender = function (nonFormattedValu
|
|||||||
})
|
})
|
||||||
: convertedValue
|
: convertedValue
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
CurrencyDisplay.prototype.handleChange = function (newVal) {
|
CurrencyDisplay.prototype.handleChange = function (newVal) {
|
||||||
this.setState({ valueToRender: removeLeadingZeroes(newVal) })
|
this.setState({ valueToRender: removeLeadingZeroes(newVal) })
|
||||||
@ -110,6 +108,19 @@ 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
|
||||||
|
? 'No Conversion Rate'
|
||||||
|
: `${convertedValueToRender} ${convertedCurrency.toUpperCase()}`
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
CurrencyDisplay.prototype.render = function () {
|
CurrencyDisplay.prototype.render = function () {
|
||||||
const {
|
const {
|
||||||
@ -127,19 +138,6 @@ CurrencyDisplay.prototype.render = function () {
|
|||||||
|
|
||||||
const convertedValueToRender = this.getConvertedValueToRender(valueToRender)
|
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', {
|
return h('div', {
|
||||||
className,
|
className,
|
||||||
style: {
|
style: {
|
||||||
@ -176,7 +174,7 @@ CurrencyDisplay.prototype.render = function () {
|
|||||||
|
|
||||||
]),
|
]),
|
||||||
|
|
||||||
]), onlyRenderConversions(),
|
]), this.onlyRenderConversions(convertedValueToRender),
|
||||||
|
|
||||||
])
|
])
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user