Browsers' Intl.supportedValuesOf('currency') includes long-withdrawn codes
(ATS, DEM, ...). Use a hand-maintained ACTIVE_CURRENCIES list in core instead,
which also drops recently replaced ones (BGN, HRK, ANG, ZWL, SLL, CUC) and
non-cash units (XDR, XSU). A withdrawn currency already in use stays selectable.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HA82gVKYyo9BHLHPW4qr4x
38 lines
1.4 KiB
Svelte
38 lines
1.4 KiB
Svelte
<script lang="ts">
|
|
import { currencyList } from '../lib/rates.ts';
|
|
import { currencyName } from '../lib/format.ts';
|
|
import { t } from '../lib/settings.svelte.ts';
|
|
|
|
let { value = $bindable(), disabled = false, id }: { value: string; disabled?: boolean; id?: string } = $props();
|
|
let lists = $state<{ rated: string[]; other: string[] }>({ rated: [], other: [] });
|
|
currencyList().then((l) => (lists = l));
|
|
|
|
const recent = (() => {
|
|
try {
|
|
return JSON.parse(localStorage.getItem('oweme.recentCurrencies') ?? '[]') as string[];
|
|
} catch {
|
|
return [];
|
|
}
|
|
})();
|
|
// Keep the current value selectable even before the lists load, or if
|
|
// it's a code that is no longer in circulation (e.g. an old group in BGN).
|
|
const rated = $derived(
|
|
[...lists.rated, ...lists.other, ...recent].includes(value) ? lists.rated : [value, ...lists.rated],
|
|
);
|
|
</script>
|
|
|
|
<select bind:value {disabled} {id}>
|
|
{#if recent.length}
|
|
<optgroup label="★">
|
|
{#each recent as c}<option value={c}>{c} · {currencyName(c)}</option>{/each}
|
|
</optgroup>
|
|
{/if}
|
|
<optgroup label={t('currencies_rated')}>
|
|
{#each rated as c}<option value={c}>{c} · {currencyName(c)}</option>{/each}
|
|
</optgroup>
|
|
{#if lists.other.length}
|
|
<optgroup label={t('currencies_manual')}>
|
|
{#each lists.other as c}<option value={c}>{c} · {currencyName(c)}</option>{/each}
|
|
</optgroup>
|
|
{/if}
|
|
</select>
|