DIY deck cost: allow only fiat + bitcoin (sats) in the currency picker
Coinbase's exchange-rates response includes crypto (BTC, ETH, USDT, …). Filter the picker to ISO-4217 fiat codes (FIAT_CODES) plus sats, so only real currencies and bitcoin are selectable.
This commit is contained in:
parent
ee55669625
commit
985801e19e
1 changed files with 20 additions and 1 deletions
|
|
@ -33,6 +33,23 @@ const CURRENCY_SYMBOLS: Record<string, string> = {
|
|||
ILS: '₪', PKR: '₨', BDT: '৳', LKR: 'Rs', NPR: 'Rs',
|
||||
};
|
||||
|
||||
/** ISO-4217 fiat codes — the only unit currencies we offer (plus `sats`). Keeps
|
||||
* crypto/stables (BTC, ETH, USDT, …) out of the picker. */
|
||||
const FIAT_CODES = new Set([
|
||||
'AED', 'AFN', 'ALL', 'AMD', 'ANG', 'AOA', 'ARS', 'AUD', 'AWG', 'AZN', 'BAM', 'BBD', 'BDT', 'BGN',
|
||||
'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', 'GGP', 'GHS', 'GIP', 'GMD', 'GNF', 'GTQ', 'GYD', 'HKD', 'HNL',
|
||||
'HRK', 'HTG', 'HUF', 'IDR', 'ILS', 'IMP', 'INR', 'IQD', 'IRR', 'ISK', 'JEP', 'JMD', 'JOD', 'JPY',
|
||||
'KES', 'KGS', 'KHR', 'KMF', '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', 'SLL', 'SOS',
|
||||
'SRD', 'SSP', 'STN', 'SYP', 'SZL', 'THB', 'TJS', 'TMT', 'TND', 'TOP', 'TRY', 'TTD', 'TWD', 'TZS',
|
||||
'UAH', 'UGX', 'USD', 'UYU', 'UZS', 'VES', 'VND', 'VUV', 'WST', 'XAF', 'XCD', 'XOF', 'XPF', 'YER',
|
||||
'ZAR', 'ZMW',
|
||||
]);
|
||||
|
||||
/** How a currency is shown: `$1.00`, `CHF 1.00`, `1,000 sats`. */
|
||||
function formatMoney(v: number, cur: string): string {
|
||||
if (cur === 'sats') return `${Math.round(v).toLocaleString()} sats`;
|
||||
|
|
@ -119,7 +136,9 @@ export function DeckCostCalculator() {
|
|||
const fmt = (n: number) => formatMoney(Number.isFinite(n) ? n : 0, cur);
|
||||
|
||||
const currencies = useMemo(() => {
|
||||
const fiat = rates ? Object.keys(rates).sort() : ['USD', 'EUR', 'GBP'];
|
||||
const fiat = rates
|
||||
? Object.keys(rates).filter((c) => FIAT_CODES.has(c)).sort()
|
||||
: ['USD', 'EUR', 'GBP'];
|
||||
return ['sats', ...fiat];
|
||||
}, [rates]);
|
||||
const filteredCurrencies = query
|
||||
|
|
|
|||
Loading…
Reference in a new issue