From 87594253f9f649019fac77fcf26ff7b08970cb06 Mon Sep 17 00:00:00 2001 From: mjkeaton Date: Tue, 21 Jan 2025 15:49:26 +0100 Subject: [PATCH] fix: display amounts in non-three-letter currency codes correctly --- src/boot/base.js | 17 +++++++++++------ src/stores/ui.ts | 17 +++++++++++------ 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/src/boot/base.js b/src/boot/base.js index c446e566..32f3914a 100644 --- a/src/boot/base.js +++ b/src/boot/base.js @@ -59,12 +59,17 @@ window.windowMixin = { if (currency == "msat") return this.fromMsat(value); if (currency == "usd") value = value / 100; if (currency == "eur") value = value / 100; - return new Intl.NumberFormat(window.LOCALE, { - style: "currency", - currency: currency, - }).format(value); - // + " " + - // currency.toUpperCase() + + if (currency.length !== 3) { + return new Intl.NumberFormat(navigator.language).format(value); + } else { + return new Intl.NumberFormat(window.LOCALE, { + style: "currency", + currency: currency, + }).format(value); + // + " " + + // currency.toUpperCase() + } }, formatSat: function (value) { // convert value to integer diff --git a/src/stores/ui.ts b/src/stores/ui.ts index 20c7b9dd..8437bce0 100644 --- a/src/stores/ui.ts +++ b/src/stores/ui.ts @@ -90,12 +90,17 @@ export const useUiStore = defineStore("ui", { if (currency == "msat") return this.fromMsat(value); if (currency == "usd") value = value / 100; if (currency == "eur") value = value / 100; - return new Intl.NumberFormat(navigator.language, { - style: "currency", - currency: currency, - }).format(value); - // + " " + - // currency.toUpperCase() + + if (currency.length !== 3) { + return new Intl.NumberFormat(navigator.language).format(value); + } else { + return new Intl.NumberFormat(navigator.language, { + style: "currency", + currency: currency, + }).format(value); + // + " " + + // currency.toUpperCase() + } }, toggleDebugConsole() { this.showDebugConsole = !this.showDebugConsole;