Revert to the withdrawn-currency exclusion list, extend it
Reverts the allowlist approach back to WITHDRAWN_CURRENCY_CODES per request, and adds the codes actually reported: AFA, ALK, AOK, AON, AOR, plus the full set of pre-euro legacy currencies (ATS, BEF, DEM, FRF, ITL, ESP, GRD, PTE, NLG, IEP, and the rest), which are exactly the kind of long-withdrawn code an ICU currency dataset would still carry. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FXcrACM5sok3M1KQJ8kByy
This commit is contained in:
@@ -13,35 +13,53 @@ private fun jsCurrencyDisplayName(code: String): String = js(
|
|||||||
)
|
)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Which currency codes `Intl.supportedValuesOf('currency')` returns is ICU-version-dependent, and
|
* `Intl.supportedValuesOf('currency')` includes a lot of codes for currencies that have actually
|
||||||
* some browsers' ICU data includes codes for currencies retired decades ago (AFA, ALK, AOK, AON,
|
* been withdrawn/superseded since — which ones depends on the browser's ICU data, so this list is
|
||||||
* AOR, ...) alongside genuinely current ones — a moving target, and not one an exclusion list can
|
* necessarily incomplete and grows over time as more turn up. Unlike JVM/Android/Apple, there's
|
||||||
* keep up with. So rather than trying to exclude every historical code some browser might expose,
|
* no web API to derive "currently assigned to some country" the way `java.util.Currency`/
|
||||||
* this allowlists the ones actually still in use instead: unlike JVM/Android/Apple, there's no web
|
* `NSLocale` do (see [localeCurrencyCode] below), so this is a manually maintained exclusion list
|
||||||
* API to derive "currently assigned to some country" the way `java.util.Currency`/`NSLocale` do
|
* instead. Needs a new entry whenever another currency is retired, or another old one turns up.
|
||||||
* (see [localeCurrencyCode] below), so this is a manually maintained list, taken directly from the
|
|
||||||
* JVM's own live-derived set (checked 2026-09-10). Needs a new entry whenever a currency changes.
|
|
||||||
*/
|
*/
|
||||||
private val ACTIVE_CURRENCY_CODES = setOf(
|
private val WITHDRAWN_CURRENCY_CODES = setOf(
|
||||||
"AED", "AFN", "ALL", "AMD", "AOA", "ARS", "AUD", "AWG", "AZN", "BAM", "BBD", "BDT", "BGN",
|
"ANG", // Netherlands Antillean Guilder — replaced by XCG (Caribbean Guilder), April 2025
|
||||||
"BHD", "BIF", "BMD", "BND", "BOB", "BRL", "BSD", "BTN", "BWP", "BYN", "BZD", "CAD", "CDF",
|
"CUC", // Cuban Convertible Peso — unified into CUP, January 2021
|
||||||
"CHF", "CLP", "CNY", "COP", "CRC", "CUP", "CVE", "CZK", "DJF", "DKK", "DOP", "DZD", "EGP",
|
"HRK", // Croatian Kuna — replaced by EUR, January 2023
|
||||||
"ERN", "ETB", "EUR", "FJD", "FKP", "GBP", "GEL", "GHS", "GIP", "GMD", "GNF", "GTQ", "GYD",
|
"SLL", // Sierra Leonean Leone (old) — redenominated to SLE, 2022
|
||||||
"HKD", "HNL", "HTG", "HUF", "IDR", "ILS", "INR", "IQD", "IRR", "ISK", "JMD", "JOD", "JPY",
|
"ZWL", // Zimbabwean Dollar (old) — replaced by ZWG (Zimbabwe Gold), April 2024
|
||||||
"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",
|
// Old Angolan Kwanza, through several redenominations — replaced by AOA
|
||||||
"MXN", "MYR", "MZN", "NAD", "NGN", "NIO", "NOK", "NPR", "NZD", "OMR", "PAB", "PEN", "PGK",
|
"AOK", "AON", "AOR",
|
||||||
"PHP", "PKR", "PLN", "PYG", "QAR", "RON", "RSD", "RUB", "RWF", "SAR", "SBD", "SCR", "SDG",
|
"AFA", // Afghan Afghani (old) — replaced by AFN
|
||||||
"SEK", "SGD", "SHP", "SLE", "SOS", "SRD", "SSP", "STN", "SVC", "SYP", "SZL", "THB", "TJS",
|
"ALK", // Albanian Lek (old) — replaced by ALL
|
||||||
"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",
|
// Pre-euro legacy currencies, withdrawn on adoption of the euro
|
||||||
) + PRECIOUS_METAL_CURRENCY_CODES
|
"ADP", // Andorran Peseta
|
||||||
|
"ATS", // Austrian Schilling
|
||||||
|
"BEF", // Belgian Franc
|
||||||
|
"CYP", // Cypriot Pound
|
||||||
|
"DEM", // Deutsche Mark
|
||||||
|
"EEK", // Estonian Kroon
|
||||||
|
"ESP", // Spanish Peseta
|
||||||
|
"FIM", // Finnish Markka
|
||||||
|
"FRF", // French Franc
|
||||||
|
"GRD", // Greek Drachma
|
||||||
|
"IEP", // Irish Pound
|
||||||
|
"ITL", // Italian Lira
|
||||||
|
"LTL", // Lithuanian Litas
|
||||||
|
"LUF", // Luxembourg Franc
|
||||||
|
"LVL", // Latvian Lats
|
||||||
|
"MTL", // Maltese Lira
|
||||||
|
"NLG", // Dutch Guilder
|
||||||
|
"PTE", // Portuguese Escudo
|
||||||
|
"SIT", // Slovenian Tolar
|
||||||
|
"SKK", // Slovak Koruna
|
||||||
|
)
|
||||||
|
|
||||||
actual fun systemCurrencies(): List<CurrencyInfo> =
|
actual fun systemCurrencies(): List<CurrencyInfo> =
|
||||||
jsSupportedCurrencyCodes()
|
jsSupportedCurrencyCodes()
|
||||||
.toList()
|
.toList()
|
||||||
.map { it.toString() }
|
.map { it.toString() }
|
||||||
.filter { it in ACTIVE_CURRENCY_CODES }
|
.filterNot { it in WITHDRAWN_CURRENCY_CODES }
|
||||||
.map { code -> CurrencyInfo(code, jsCurrencyDisplayName(code)) }
|
.map { code -> CurrencyInfo(code, jsCurrencyDisplayName(code)) }
|
||||||
.sortedBy { it.code }
|
.sortedBy { it.code }
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user