feat: currency helper (#3849)
This commit is contained in:
Vendored
+1
-1
File diff suppressed because one or more lines are too long
@@ -131,6 +131,22 @@ window._lnbitsUtils = {
|
|||||||
currency: currency || 'sat'
|
currency: currency || 'sat'
|
||||||
}).format(value)
|
}).format(value)
|
||||||
},
|
},
|
||||||
|
getCurrencySymbol(currency) {
|
||||||
|
const code = (currency || '').toUpperCase()
|
||||||
|
if (code === 'BTC' || code === 'XBT' || code === 'SAT' || code === 'SATS') {
|
||||||
|
return '₿'
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
const parts = new Intl.NumberFormat(window.i18n.global.locale, {
|
||||||
|
style: 'currency',
|
||||||
|
currency: code
|
||||||
|
}).formatToParts(0)
|
||||||
|
const symbolPart = parts.find(part => part.type === 'currency')
|
||||||
|
return symbolPart?.value || code || '¤'
|
||||||
|
} catch (e) {
|
||||||
|
return code || '¤'
|
||||||
|
}
|
||||||
|
},
|
||||||
formatSat(value) {
|
formatSat(value) {
|
||||||
return new Intl.NumberFormat(window.i18n.global.locale).format(value)
|
return new Intl.NumberFormat(window.i18n.global.locale).format(value)
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user