diff --git a/apps/web/src/components/CurrencySelect.svelte b/apps/web/src/components/CurrencySelect.svelte index e289571..a50aef7 100644 --- a/apps/web/src/components/CurrencySelect.svelte +++ b/apps/web/src/components/CurrencySelect.svelte @@ -1,9 +1,10 @@ @@ -26,11 +27,11 @@ {#each recent as c}{/each} {/if} - - {#each ecb as c}{/each} + + {#each rated as c}{/each} {#if lists.other.length} - + {#each lists.other as c}{/each} {/if} diff --git a/packages/core/src/currencies.ts b/packages/core/src/currencies.ts new file mode 100644 index 0000000..d7cc409 --- /dev/null +++ b/packages/core/src/currencies.ts @@ -0,0 +1,32 @@ +// Currencies offered in the picker. Hardcoded rather than read from +// Intl.supportedValuesOf('currency'), which in browsers also returns +// historical codes (ATS, DEM, YUM, …) that nobody can spend any more. + +/** + * ISO 4217 currencies in circulation today. Excludes fund codes (CLF, USN, …), + * precious metals and other non-cash units (XAU, XDR, XSU), and codes that + * have been replaced: ANG → XCG (2025), BGN → EUR (2026), CUC (2021), + * HRK → EUR (2023), SLL → SLE (2024), ZWL → ZWG (2024). + * Update this list when ISO 4217 changes. + */ +export const ACTIVE_CURRENCIES: readonly string[] = [ + 'AED', 'AFN', 'ALL', 'AMD', 'AOA', 'ARS', 'AUD', 'AWG', 'AZN', 'BAM', 'BBD', 'BDT', + 'BHD', 'BIF', 'BMD', 'BND', 'BOB', 'BRL', 'BSD', 'BTN', 'BWP', 'BYN', 'BZD', 'CAD', + 'CDF', 'CHF', 'CLP', 'CNY', 'COP', 'CRC', 'CUP', 'CVE', 'CZK', 'DJF', 'DKK', 'DOP', + 'DZD', 'EGP', 'ERN', 'ETB', 'EUR', 'FJD', 'FKP', 'GBP', 'GEL', 'GHS', 'GIP', 'GMD', + 'GNF', 'GTQ', 'GYD', 'HKD', 'HNL', 'HTG', 'HUF', 'IDR', 'ILS', 'INR', 'IQD', 'IRR', + 'ISK', 'JMD', 'JOD', 'JPY', 'KES', 'KGS', 'KHR', 'KMF', 'KPW', 'KRW', 'KWD', 'KYD', + 'KZT', 'LAK', 'LBP', 'LKR', 'LRD', 'LSL', 'LYD', 'MAD', 'MDL', 'MGA', 'MKD', 'MMK', + 'MNT', 'MOP', 'MRU', 'MUR', 'MVR', 'MWK', 'MXN', 'MYR', 'MZN', 'NAD', 'NGN', 'NIO', + 'NOK', 'NPR', 'NZD', 'OMR', 'PAB', 'PEN', 'PGK', 'PHP', 'PKR', 'PLN', 'PYG', 'QAR', + 'RON', 'RSD', 'RUB', 'RWF', 'SAR', 'SBD', 'SCR', 'SDG', 'SEK', 'SGD', 'SHP', 'SLE', + 'SOS', 'SRD', 'SSP', 'STN', 'SVC', 'SYP', 'SZL', 'THB', 'TJS', 'TMT', 'TND', 'TOP', + 'TRY', 'TTD', 'TWD', 'TZS', 'UAH', 'UGX', 'USD', 'UYU', 'UZS', 'VES', 'VND', 'VUV', + 'WST', 'XAF', 'XCD', 'XCG', 'XOF', 'XPF', 'YER', 'ZAR', 'ZMW', 'ZWG', +]; + +const ACTIVE = new Set(ACTIVE_CURRENCIES); + +export function isActiveCurrency(code: string): boolean { + return ACTIVE.has(code); +} diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index 77e1e1b..8b1ce45 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -6,3 +6,4 @@ export * from './settle.ts'; export * from './recurring.ts'; export * from './stats.ts'; export * from './csv.ts'; +export * from './currencies.ts'; diff --git a/packages/core/test/core.test.ts b/packages/core/test/core.test.ts index dc56547..8d8e003 100644 --- a/packages/core/test/core.test.ts +++ b/packages/core/test/core.test.ts @@ -1,4 +1,5 @@ import { describe, expect, it } from 'vitest'; +import { ACTIVE_CURRENCIES, isActiveCurrency } from '../src/index.ts'; import { allocate, balances, convert, dueOccurrences, expensesCsv, inBase, logOrder, nthOccurrence, occurrenceId, parseAmount, rateToString, replay, settleUp, toDecimalString, computeStats, @@ -230,3 +231,13 @@ describe('stats and csv', () => { expect(expensesCsv(state)).toContain(`"'=HYPERLINK(""x"")"`); }); }); + +describe('ACTIVE_CURRENCIES', () => { + it('is sorted, unique ISO codes without replaced currencies', () => { + expect([...ACTIVE_CURRENCIES].sort()).toEqual(ACTIVE_CURRENCIES); + expect(new Set(ACTIVE_CURRENCIES).size).toBe(ACTIVE_CURRENCIES.length); + expect(ACTIVE_CURRENCIES.every((c) => /^[A-Z]{3}$/.test(c))).toBe(true); + for (const gone of ['ANG', 'BGN', 'CUC', 'HRK', 'SLL', 'ZWL', 'DEM', 'XDR']) expect(isActiveCurrency(gone)).toBe(false); + for (const c of ['ALL', 'CZK', 'EUR', 'XCG', 'ZWG']) expect(isActiveCurrency(c)).toBe(true); + }); +});