feat(@desktop/wallet): handle very small currency amounts

Fixes #9013
This commit is contained in:
Dario Gabriel Lipicar 2023-01-17 17:03:29 -03:00 committed by dlipicar
parent 0f1485fa4d
commit 1fc9dec4d4
1 changed files with 16 additions and 3 deletions

View File

@ -44,13 +44,26 @@ QtObject {
console.trace()
return NaN
}
var amountStr = numberToLocaleString(currencyAmount.amount, currencyAmount.displayDecimals, locale)
if (currencyAmount.stripTrailingZeroes) {
amountStr = stripTrailingZeroes(amountStr, locale)
var amountStr
let minAmount = 10**-currencyAmount.displayDecimals
if (currencyAmount.amount > 0 && currencyAmount.amount < minAmount && !(options && options.onlyAmount))
{
// Handle amounts smaller than resolution
amountStr = "<%1".arg(numberToLocaleString(minAmount, currencyAmount.displayDecimals, locale))
} else {
// Normal formatting
amountStr = numberToLocaleString(currencyAmount.amount, currencyAmount.displayDecimals, locale)
if (currencyAmount.stripTrailingZeroes) {
amountStr = stripTrailingZeroes(amountStr, locale)
}
}
// Add symbol
if (currencyAmount.symbol && !(options && options.onlyAmount)) {
amountStr = "%1 %2".arg(amountStr).arg(currencyAmount.symbol)
}
return amountStr
}