Skip to content

Commit

Permalink
💵 Add some new currencies #1613 (#1618)
Browse files Browse the repository at this point in the history
  • Loading branch information
ithiame authored Dec 6, 2024
1 parent d422955 commit 690ce16
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 4 deletions.
9 changes: 8 additions & 1 deletion src/lib/stores/exchangeRate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,14 @@ export const defaultExchangeRate = {
CDF: 96_755_481,
XOF: 22_621_258,
XAF: 22_621_258,
SAT: SATOSHIS_PER_BTC
SAT: SATOSHIS_PER_BTC,
KES: 4_200_000,
UGX: 110_000_000,
GHS: 350_000,
NGN: 27_000_000,
TZS: 75_000_000,
MAD: 320_000,
CZK: 700_000
};

export type ExchangeRate = typeof defaultExchangeRate;
Expand Down
37 changes: 34 additions & 3 deletions src/lib/types/Currency.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,23 @@
import { error } from '@sveltejs/kit';

export const CURRENCIES = ['BTC', 'CHF', 'EUR', 'USD', 'ZAR', 'SAT', 'XOF', 'XAF', 'CDF'] as const;
export const CURRENCIES = [
'BTC',
'CHF',
'EUR',
'USD',
'ZAR',
'SAT',
'XOF',
'XAF',
'CDF',
'KES',
'UGX',
'GHS',
'NGN',
'TZS',
'MAD',
'CZK'
] as const;
export type Currency = (typeof CURRENCIES)[number];

export const SATOSHIS_PER_BTC = 100_000_000;
Expand All @@ -14,7 +31,14 @@ export const FRACTION_DIGITS_PER_CURRENCY = Object.freeze({
XOF: 2,
XAF: 2,
CDF: 2,
SAT: 0
SAT: 0,
KES: 2,
UGX: 2,
GHS: 2,
NGN: 2,
TZS: 2,
MAD: 2,
CZK: 2
}) satisfies Record<Currency, number>;

export const CURRENCY_UNIT = Object.freeze({
Expand All @@ -26,7 +50,14 @@ export const CURRENCY_UNIT = Object.freeze({
XOF: Math.pow(10, -FRACTION_DIGITS_PER_CURRENCY.XOF),
XAF: Math.pow(10, -FRACTION_DIGITS_PER_CURRENCY.XAF),
CDF: Math.pow(10, -FRACTION_DIGITS_PER_CURRENCY.CDF),
SAT: Math.pow(10, -FRACTION_DIGITS_PER_CURRENCY.SAT)
SAT: Math.pow(10, -FRACTION_DIGITS_PER_CURRENCY.SAT),
KES: Math.pow(10, -FRACTION_DIGITS_PER_CURRENCY.KES),
UGX: Math.pow(10, -FRACTION_DIGITS_PER_CURRENCY.UGX),
GHS: Math.pow(10, -FRACTION_DIGITS_PER_CURRENCY.GHS),
NGN: Math.pow(10, -FRACTION_DIGITS_PER_CURRENCY.NGN),
TZS: Math.pow(10, -FRACTION_DIGITS_PER_CURRENCY.TZS),
MAD: Math.pow(10, -FRACTION_DIGITS_PER_CURRENCY.MAD),
CZK: Math.pow(10, -FRACTION_DIGITS_PER_CURRENCY.CZK)
}) satisfies Record<Currency, number>;

export function parsePriceAmount(amount: string, currency: Currency): number {
Expand Down

0 comments on commit 690ce16

Please sign in to comment.