From e6742ec5b333e5b3b7d174eae9f79c7d63b4b4e9 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Tue, 12 Nov 2024 15:55:47 -0800 Subject: bolt --- src/components/Balance.svelte | 2 +- src/components/Numpad.svelte | 13 ++++++++-- src/lib/utils.ts | 30 +++++++++++----------- .../(app)/[username]/(profile)/+layout.svelte | 8 +++--- 4 files changed, 32 insertions(+), 21 deletions(-) (limited to 'src') diff --git a/src/components/Balance.svelte b/src/components/Balance.svelte index 74cb2939..0129d1ab 100644 --- a/src/components/Balance.svelte +++ b/src/components/Balance.svelte @@ -34,7 +34,7 @@ {#if isNaN(rate)}
—
{:else} - {fiat(balance, rate).toFixed(2)} {user.currency} + {f(fiat(balance, rate))} {user.currency} {/if} {/if} diff --git a/src/components/Numpad.svelte b/src/components/Numpad.svelte index 1cd59abe..bbafc196 100644 --- a/src/components/Numpad.svelte +++ b/src/components/Numpad.svelte @@ -203,7 +203,10 @@ class="text-5xl md:text-6xl font-semibold tracking-widest flex justify-center" >
- {$fiat ? symbol : "⚡️"} + {#if $fiat}{symbol}{:else} + + {/if}
- {$fiat ? "⚡️" + s(amount) : f(amountFiat, currency)} + {#if $fiat} + + {s(amount)} + {:else} + {f(amountFiat, currency)} {currency} + {/if}
diff --git a/src/lib/utils.ts b/src/lib/utils.ts index 2779e34a..9830844a 100644 --- a/src/lib/utils.ts +++ b/src/lib/utils.ts @@ -200,25 +200,23 @@ export const fd = async (req: Request): Promise => { return obj; }; -export const f = (s: number, currency: string): string => { - try { - return new Intl.NumberFormat("en-US", { - style: "currency", - currency, - }) - .format(s) - .replace("CA", ""); - } catch (e) { - return ""; - } -}; +export const f = (s: number): string => + new Intl.NumberFormat("en-US", { + style: "decimal", + minimumFractionDigits: 2, + maximumFractionDigits: 2, + }).format(s); export const s = (s: number): string => new Intl.NumberFormat("en-US", { maximumFractionDigits: 0 }).format(s); export const sat = (s: number): string => `${si(Math.abs(s)).toString()}`; -export const si = (n: number, minimumFractionDigits = 1, maximumFractionDigits = 2) => { +export const si = ( + n: number, + minimumFractionDigits = 1, + maximumFractionDigits = 2, +) => { const units = ["", "K", "M", "G", "T", "P", "E", "Z"]; let s = n; @@ -229,8 +227,10 @@ export const si = (n: number, minimumFractionDigits = 1, maximumFractionDigits = } return ( - new Intl.NumberFormat("en-US", { minimumFractionDigits, maximumFractionDigits }).format(s) + - units[d] + new Intl.NumberFormat("en-US", { + minimumFractionDigits, + maximumFractionDigits, + }).format(s) + units[d] ); }; diff --git a/src/routes/(app)/[username]/(profile)/+layout.svelte b/src/routes/(app)/[username]/(profile)/+layout.svelte index 2be99adc..b039f5cc 100644 --- a/src/routes/(app)/[username]/(profile)/+layout.svelte +++ b/src/routes/(app)/[username]/(profile)/+layout.svelte @@ -283,9 +283,11 @@
= {f(rates[currency], currency)}
-
-
⚡️{s((1 * sats) / rates[currency])} =
-
{f(1, currency)}
+
+ + {s((1 * sats) / rates[currency])} = + {f(1, currency)} {currency}
-- cgit v1.2.3