Offer only ISO 4217 currencies in circulation in the picker
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
This commit is contained in:
parent
1c691cd54f
commit
6b0c80bb50
4 changed files with 52 additions and 7 deletions
|
|
@ -1,9 +1,10 @@
|
|||
<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<{ ecb: string[]; other: string[] }>({ ecb: [], other: [] });
|
||||
let lists = $state<{ rated: string[]; other: string[] }>({ rated: [], other: [] });
|
||||
currencyList().then((l) => (lists = l));
|
||||
|
||||
const recent = (() => {
|
||||
|
|
@ -14,9 +15,9 @@
|
|||
}
|
||||
})();
|
||||
// Keep the current value selectable even before the lists load, or if
|
||||
// it's a code this browser doesn't know.
|
||||
const ecb = $derived(
|
||||
[...lists.ecb, ...lists.other, ...recent].includes(value) ? lists.ecb : [value, ...lists.ecb],
|
||||
// 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>
|
||||
|
||||
|
|
@ -26,11 +27,11 @@
|
|||
{#each recent as c}<option value={c}>{c} · {currencyName(c)}</option>{/each}
|
||||
</optgroup>
|
||||
{/if}
|
||||
<optgroup label="ECB">
|
||||
{#each ecb as c}<option value={c}>{c} · {currencyName(c)}</option>{/each}
|
||||
<optgroup label={t('currencies_rated')}>
|
||||
{#each rated as c}<option value={c}>{c} · {currencyName(c)}</option>{/each}
|
||||
</optgroup>
|
||||
{#if lists.other.length}
|
||||
<optgroup label="…">
|
||||
<optgroup label={t('currencies_manual')}>
|
||||
{#each lists.other as c}<option value={c}>{c} · {currencyName(c)}</option>{/each}
|
||||
</optgroup>
|
||||
{/if}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue