- Add goals feature (models, migrations, API, web pages) - Add reserved/centralized wallet balance service - Add wallet detail page and overview components - Add new UI components (progress, multi-select, FAB) - Remove stray empty -H/-d files from working tree
73 lines
3.1 KiB
TypeScript
Executable File
73 lines
3.1 KiB
TypeScript
Executable File
export const CURRENCIES = [
|
|
{ code: 'IDR', name: 'Indonesian Rupiah', symbol: 'Rp' },
|
|
{ code: 'USD', name: 'US Dollar', symbol: '$' },
|
|
{ code: 'EUR', name: 'Euro', symbol: '€' },
|
|
{ code: 'GBP', name: 'British Pound', symbol: '£' },
|
|
{ code: 'JPY', name: 'Japanese Yen', symbol: '¥' },
|
|
{ code: 'AUD', name: 'Australian Dollar', symbol: 'A$' },
|
|
{ code: 'CAD', name: 'Canadian Dollar', symbol: 'C$' },
|
|
{ code: 'CHF', name: 'Swiss Franc', symbol: 'CHF' },
|
|
{ code: 'CNY', name: 'Chinese Yuan', symbol: '¥' },
|
|
{ code: 'SGD', name: 'Singapore Dollar', symbol: 'S$' },
|
|
{ code: 'HKD', name: 'Hong Kong Dollar', symbol: 'HK$' },
|
|
{ code: 'MYR', name: 'Malaysian Ringgit', symbol: 'RM' },
|
|
{ code: 'THB', name: 'Thai Baht', symbol: '฿' },
|
|
{ code: 'KRW', name: 'South Korean Won', symbol: '₩' },
|
|
{ code: 'INR', name: 'Indian Rupee', symbol: '₹' },
|
|
{ code: 'PHP', name: 'Philippine Peso', symbol: '₱' },
|
|
{ code: 'NZD', name: 'New Zealand Dollar', symbol: 'NZ$' },
|
|
{ code: 'NOK', name: 'Norwegian Krone', symbol: 'kr' },
|
|
{ code: 'SEK', name: 'Swedish Krona', symbol: 'kr' },
|
|
{ code: 'DKK', name: 'Danish Krone', symbol: 'kr' },
|
|
{ code: 'PLN', name: 'Polish Zloty', symbol: 'zł' },
|
|
{ code: 'CZK', name: 'Czech Koruna', symbol: 'Kč' },
|
|
{ code: 'HUF', name: 'Hungarian Forint', symbol: 'Ft' },
|
|
{ code: 'BGN', name: 'Bulgarian Lev', symbol: 'лв' },
|
|
{ code: 'RON', name: 'Romanian Leu', symbol: 'lei' },
|
|
{ code: 'HRK', name: 'Croatian Kuna', symbol: 'kn' },
|
|
{ code: 'RUB', name: 'Russian Ruble', symbol: '₽' },
|
|
{ code: 'TRY', name: 'Turkish Lira', symbol: '₺' },
|
|
{ code: 'BRL', name: 'Brazilian Real', symbol: 'R$' },
|
|
{ code: 'MXN', name: 'Mexican Peso', symbol: '$' },
|
|
{ code: 'ZAR', name: 'South African Rand', symbol: 'R' },
|
|
{ code: 'ILS', name: 'Israeli Shekel', symbol: '₪' },
|
|
{ code: 'ISK', name: 'Icelandic Krona', symbol: 'kr' },
|
|
] as const;
|
|
|
|
export type CurrencyCode = typeof CURRENCIES[number]['code'];
|
|
|
|
export const getCurrencyByCode = (code: string) => {
|
|
return CURRENCIES.find(currency => currency.code === code);
|
|
};
|
|
|
|
export const formatCurrency = (amount: number, currencyCode: string) => {
|
|
const useLanguage = localStorage.getItem('language') || 'en';
|
|
const currency = getCurrencyByCode(currencyCode);
|
|
|
|
// For non-currency codes (units like "gram", "shares", etc.)
|
|
if (!currency) {
|
|
const formatter = new Intl.NumberFormat('id-ID', {
|
|
minimumFractionDigits: 0,
|
|
maximumFractionDigits: 2
|
|
});
|
|
const formattedAmount = formatter.format(amount);
|
|
return `${formattedAmount} ${(amount === 1) ? currencyCode : currencyCode + (useLanguage == 'en' ? 's' : '')}`;
|
|
}
|
|
|
|
// For IDR, format without decimals
|
|
if (currencyCode === 'IDR') {
|
|
const formatter = new Intl.NumberFormat('id-ID', {
|
|
minimumFractionDigits: 0,
|
|
maximumFractionDigits: 0
|
|
});
|
|
return `${currency.symbol} ${formatter.format(amount)}`;
|
|
}
|
|
|
|
// For other currencies, use 2 decimal places
|
|
const formatter = new Intl.NumberFormat('en-US', {
|
|
minimumFractionDigits: 2,
|
|
maximumFractionDigits: 2
|
|
});
|
|
return `${currency.symbol} ${formatter.format(amount)}`;
|
|
};
|