diff options
| author | Adam Soltys <[email protected]> | 2024-11-28 08:20:19 -0800 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2024-11-28 08:20:19 -0800 |
| commit | e294a1793e3e884ed3f6c095f4978ccd44255a16 (patch) | |
| tree | fa5b1c20c7d7007956bdd82b5d1f225dd9b61450 | |
| parent | ba0e41bfaa79faf01bb586a4a0e27ca915855bb8 (diff) | |
| download | coinos-ui-e294a1793e3e884ed3f6c095f4978ccd44255a16.tar.gz coinos-ui-e294a1793e3e884ed3f6c095f4978ccd44255a16.zip | |
handle undefined
| -rw-r--r-- | src/lib/utils.ts | 6 | ||||
| -rw-r--r-- | src/routes/(app)/[username]/(profile)/+layout.svelte | 18 |
2 files changed, 20 insertions, 4 deletions
diff --git a/src/lib/utils.ts b/src/lib/utils.ts index 641cec31..60e30fe5 100644 --- a/src/lib/utils.ts +++ b/src/lib/utils.ts @@ -274,7 +274,11 @@ const map = { IRR: "fa-IR", }; -export const loc = ({ currency: c, language: l }) => map[l]?.[c] || map[c]; +export const loc = (user) => { + if (!user) return; + const { currency: c, language: l } = user; + return map[l]?.[c] || map[c]; +}; export const f = (s: number, currency: string, locale = "en-US") => new Intl.NumberFormat(locale, { diff --git a/src/routes/(app)/[username]/(profile)/+layout.svelte b/src/routes/(app)/[username]/(profile)/+layout.svelte index 55ea9f2d..2ce8aa7a 100644 --- a/src/routes/(app)/[username]/(profile)/+layout.svelte +++ b/src/routes/(app)/[username]/(profile)/+layout.svelte @@ -2,7 +2,18 @@ import { invalidate } from "$app/navigation"; import { browser } from "$app/environment"; import { hexToUint8Array } from "uint8array-extras"; - import { copy, f, get, post, s, sats, success, fail, si } from "$lib/utils"; + import { + copy, + f, + loc, + get, + post, + s, + sats, + success, + fail, + si, + } from "$lib/utils"; import { t } from "$lib/translations"; import { sign, send } from "$lib/nostr"; import { bech32m } from "@scure/base"; @@ -25,6 +36,7 @@ } = $derived(data); let { currency, npub, username: n, display } = $derived(subject); + let locale = loc(user); let list = $state([]); let follow = async () => { @@ -280,14 +292,14 @@ <div class="my-auto mr-1">1</div> <img src="/images/bitcoin.svg" class="w-5 my-auto" alt="Bitcoin" /> </div> - <div>= {f(rates[currency], currency)}</div> + <div>= {f(rates[currency], currency, locale)}</div> </div> <div class="text-secondary flex ml-auto"> <div class="flex items-center"> <iconify-icon icon="ph:lightning-fill" class="text-yellow-300" ></iconify-icon> {s((1 * sats) / rates[currency])} = - {f(1, currency)} + {f(1, currency, locale)} </div> </div> </div> |
