19 lines
1.0 KiB
TypeScript
19 lines
1.0 KiB
TypeScript
export type CurrencyCode = 'GBP' | 'USD' | 'EUR';
|
|
|
|
// Prices are stored as an integer in GBP pence — that's the canonical/base currency
|
|
// for this site. These rates are fixed approximations for customer-facing display
|
|
// only; they are NOT live exchange rates and are NOT used for actual payment
|
|
// amounts (checkout charges in GBP regardless of what's displayed here). Update
|
|
// them periodically if you want display prices to stay roughly current.
|
|
export const CURRENCIES: { code: CurrencyCode; symbol: string; rate: number; label: string }[] = [
|
|
{ code: 'GBP', symbol: '£', rate: 1, label: 'GBP — British Pound' },
|
|
{ code: 'USD', symbol: '$', rate: 1.27, label: 'USD — US Dollar' },
|
|
{ code: 'EUR', symbol: '€', rate: 1.17, label: 'EUR — Euro' },
|
|
];
|
|
|
|
export function formatPrice(basePenceGBP: number, currency: CurrencyCode): string {
|
|
const info = CURRENCIES.find((c) => c.code === currency) ?? CURRENCIES[0];
|
|
const converted = (basePenceGBP / 100) * info.rate;
|
|
return `${info.symbol}${converted.toFixed(2)}`;
|
|
}
|