| 1 |
/** |
| 2 |
* Currency Data |
| 3 |
* |
| 4 |
* Centralized currency definitions for use throughout the application. |
| 5 |
* Keep in sync with PHP: app/Helpers/CurrencyHelper.php |
| 6 |
*/ |
| 7 |
|
| 8 |
export interface Currency { |
| 9 |
code: string; |
| 10 |
name: string; |
| 11 |
symbol: string; |
| 12 |
decimalDigits: number; |
| 13 |
} |
| 14 |
|
| 15 |
export const CURRENCIES: Record<string, Currency> = { |
| 16 |
// Major Currencies |
| 17 |
USD: { code: "USD", name: "US Dollar", symbol: "$", decimalDigits: 2 }, |
| 18 |
EUR: { code: "EUR", name: "Euro", symbol: "€", decimalDigits: 2 }, |
| 19 |
GBP: { code: "GBP", name: "British Pound", symbol: "£", decimalDigits: 2 }, |
| 20 |
JPY: { code: "JPY", name: "Japanese Yen", symbol: "¥", decimalDigits: 0 }, |
| 21 |
CNY: { code: "CNY", name: "Chinese Yuan", symbol: "¥", decimalDigits: 2 }, |
| 22 |
CHF: { code: "CHF", name: "Swiss Franc", symbol: "CHF", decimalDigits: 2 }, |
| 23 |
CAD: { code: "CAD", name: "Canadian Dollar", symbol: "C$", decimalDigits: 2 }, |
| 24 |
AUD: { |
| 25 |
code: "AUD", |
| 26 |
name: "Australian Dollar", |
| 27 |
symbol: "A$", |
| 28 |
decimalDigits: 2, |
| 29 |
}, |
| 30 |
NZD: { |
| 31 |
code: "NZD", |
| 32 |
name: "New Zealand Dollar", |
| 33 |
symbol: "NZ$", |
| 34 |
decimalDigits: 2, |
| 35 |
}, |
| 36 |
|
| 37 |
// Asian Currencies |
| 38 |
INR: { code: "INR", name: "Indian Rupee", symbol: "₹", decimalDigits: 2 }, |
| 39 |
NPR: { code: "NPR", name: "Nepalese Rupee", symbol: "Rs", decimalDigits: 2 }, |
| 40 |
PKR: { code: "PKR", name: "Pakistani Rupee", symbol: "₨", decimalDigits: 2 }, |
| 41 |
BDT: { code: "BDT", name: "Bangladeshi Taka", symbol: "৳", decimalDigits: 2 }, |
| 42 |
LKR: { |
| 43 |
code: "LKR", |
| 44 |
name: "Sri Lankan Rupee", |
| 45 |
symbol: "Rs", |
| 46 |
decimalDigits: 2, |
| 47 |
}, |
| 48 |
MMK: { code: "MMK", name: "Myanmar Kyat", symbol: "K", decimalDigits: 2 }, |
| 49 |
THB: { code: "THB", name: "Thai Baht", symbol: "฿", decimalDigits: 2 }, |
| 50 |
VND: { code: "VND", name: "Vietnamese Dong", symbol: "₫", decimalDigits: 0 }, |
| 51 |
IDR: { |
| 52 |
code: "IDR", |
| 53 |
name: "Indonesian Rupiah", |
| 54 |
symbol: "Rp", |
| 55 |
decimalDigits: 2, |
| 56 |
}, |
| 57 |
MYR: { |
| 58 |
code: "MYR", |
| 59 |
name: "Malaysian Ringgit", |
| 60 |
symbol: "RM", |
| 61 |
decimalDigits: 2, |
| 62 |
}, |
| 63 |
SGD: { |
| 64 |
code: "SGD", |
| 65 |
name: "Singapore Dollar", |
| 66 |
symbol: "S$", |
| 67 |
decimalDigits: 2, |
| 68 |
}, |
| 69 |
PHP: { code: "PHP", name: "Philippine Peso", symbol: "₱", decimalDigits: 2 }, |
| 70 |
KRW: { code: "KRW", name: "South Korean Won", symbol: "₩", decimalDigits: 0 }, |
| 71 |
TWD: { code: "TWD", name: "Taiwan Dollar", symbol: "NT$", decimalDigits: 2 }, |
| 72 |
HKD: { |
| 73 |
code: "HKD", |
| 74 |
name: "Hong Kong Dollar", |
| 75 |
symbol: "HK$", |
| 76 |
decimalDigits: 2, |
| 77 |
}, |
| 78 |
MOP: { |
| 79 |
code: "MOP", |
| 80 |
name: "Macanese Pataca", |
| 81 |
symbol: "MOP$", |
| 82 |
decimalDigits: 2, |
| 83 |
}, |
| 84 |
KHR: { code: "KHR", name: "Cambodian Riel", symbol: "៛", decimalDigits: 2 }, |
| 85 |
LAK: { code: "LAK", name: "Lao Kip", symbol: "₭", decimalDigits: 2 }, |
| 86 |
BND: { code: "BND", name: "Brunei Dollar", symbol: "B$", decimalDigits: 2 }, |
| 87 |
MNT: { code: "MNT", name: "Mongolian Tugrik", symbol: "₮", decimalDigits: 2 }, |
| 88 |
KZT: { |
| 89 |
code: "KZT", |
| 90 |
name: "Kazakhstani Tenge", |
| 91 |
symbol: "₸", |
| 92 |
decimalDigits: 2, |
| 93 |
}, |
| 94 |
UZS: { |
| 95 |
code: "UZS", |
| 96 |
name: "Uzbekistani Som", |
| 97 |
symbol: "сўм", |
| 98 |
decimalDigits: 2, |
| 99 |
}, |
| 100 |
KGS: { |
| 101 |
code: "KGS", |
| 102 |
name: "Kyrgyzstani Som", |
| 103 |
symbol: "сом", |
| 104 |
decimalDigits: 2, |
| 105 |
}, |
| 106 |
TJS: { |
| 107 |
code: "TJS", |
| 108 |
name: "Tajikistani Somoni", |
| 109 |
symbol: "� |
| 110 |
М", |
| 111 |
decimalDigits: 2, |
| 112 |
}, |
| 113 |
TMT: { |
| 114 |
code: "TMT", |
| 115 |
name: "Turkmenistani Manat", |
| 116 |
symbol: "m", |
| 117 |
decimalDigits: 2, |
| 118 |
}, |
| 119 |
AFN: { code: "AFN", name: "Afghan Afghani", symbol: "؋", decimalDigits: 2 }, |
| 120 |
|
| 121 |
// Middle Eastern Currencies |
| 122 |
AED: { code: "AED", name: "UAE Dirham", symbol: "د.إ", decimalDigits: 2 }, |
| 123 |
SAR: { code: "SAR", name: "Saudi Riyal", symbol: "﷼", decimalDigits: 2 }, |
| 124 |
QAR: { code: "QAR", name: "Qatari Riyal", symbol: "﷼", decimalDigits: 2 }, |
| 125 |
KWD: { code: "KWD", name: "Kuwaiti Dinar", symbol: "د.ك", decimalDigits: 3 }, |
| 126 |
BHD: { |
| 127 |
code: "BHD", |
| 128 |
name: "Bahraini Dinar", |
| 129 |
symbol: ".د.ب", |
| 130 |
decimalDigits: 3, |
| 131 |
}, |
| 132 |
OMR: { code: "OMR", name: "Omani Rial", symbol: "﷼", decimalDigits: 3 }, |
| 133 |
JOD: { |
| 134 |
code: "JOD", |
| 135 |
name: "Jordanian Dinar", |
| 136 |
symbol: "د.ا", |
| 137 |
decimalDigits: 3, |
| 138 |
}, |
| 139 |
ILS: { code: "ILS", name: "Israeli Shekel", symbol: "₪", decimalDigits: 2 }, |
| 140 |
LBP: { code: "LBP", name: "Lebanese Pound", symbol: "ل.ل", decimalDigits: 2 }, |
| 141 |
SYP: { code: "SYP", name: "Syrian Pound", symbol: "£S", decimalDigits: 2 }, |
| 142 |
IQD: { code: "IQD", name: "Iraqi Dinar", symbol: "ع.د", decimalDigits: 3 }, |
| 143 |
IRR: { code: "IRR", name: "Iranian Rial", symbol: "﷼", decimalDigits: 2 }, |
| 144 |
YER: { code: "YER", name: "Yemeni Rial", symbol: "﷼", decimalDigits: 2 }, |
| 145 |
EGP: { code: "EGP", name: "Egyptian Pound", symbol: "E£", decimalDigits: 2 }, |
| 146 |
TRY: { code: "TRY", name: "Turkish Lira", symbol: "₺", decimalDigits: 2 }, |
| 147 |
|
| 148 |
// European Currencies |
| 149 |
SEK: { code: "SEK", name: "Swedish Krona", symbol: "kr", decimalDigits: 2 }, |
| 150 |
NOK: { code: "NOK", name: "Norwegian Krone", symbol: "kr", decimalDigits: 2 }, |
| 151 |
DKK: { code: "DKK", name: "Danish Krone", symbol: "kr", decimalDigits: 2 }, |
| 152 |
ISK: { code: "ISK", name: "Icelandic Króna", symbol: "kr", decimalDigits: 0 }, |
| 153 |
PLN: { code: "PLN", name: "Polish Zloty", symbol: "zł", decimalDigits: 2 }, |
| 154 |
CZK: { code: "CZK", name: "Czech Koruna", symbol: "Kč", decimalDigits: 2 }, |
| 155 |
HUF: { |
| 156 |
code: "HUF", |
| 157 |
name: "Hungarian Forint", |
| 158 |
symbol: "Ft", |
| 159 |
decimalDigits: 2, |
| 160 |
}, |
| 161 |
RON: { code: "RON", name: "Romanian Leu", symbol: "lei", decimalDigits: 2 }, |
| 162 |
BGN: { code: "BGN", name: "Bulgarian Lev", symbol: "лв", decimalDigits: 2 }, |
| 163 |
HRK: { code: "HRK", name: "Croatian Kuna", symbol: "kn", decimalDigits: 2 }, |
| 164 |
RSD: { code: "RSD", name: "Serbian Dinar", symbol: "дин.", decimalDigits: 2 }, |
| 165 |
MKD: { |
| 166 |
code: "MKD", |
| 167 |
name: "Macedonian Denar", |
| 168 |
symbol: "ден", |
| 169 |
decimalDigits: 2, |
| 170 |
}, |
| 171 |
BAM: { |
| 172 |
code: "BAM", |
| 173 |
name: "Bosnia-Herzegovina Mark", |
| 174 |
symbol: "KM", |
| 175 |
decimalDigits: 2, |
| 176 |
}, |
| 177 |
ALL: { code: "ALL", name: "Albanian Lek", symbol: "L", decimalDigits: 2 }, |
| 178 |
MDL: { code: "MDL", name: "Moldovan Leu", symbol: "L", decimalDigits: 2 }, |
| 179 |
UAH: { |
| 180 |
code: "UAH", |
| 181 |
name: "Ukrainian Hryvnia", |
| 182 |
symbol: "₴", |
| 183 |
decimalDigits: 2, |
| 184 |
}, |
| 185 |
BYN: { |
| 186 |
code: "BYN", |
| 187 |
name: "Belarusian Ruble", |
| 188 |
symbol: "Br", |
| 189 |
decimalDigits: 2, |
| 190 |
}, |
| 191 |
RUB: { code: "RUB", name: "Russian Ruble", symbol: "₽", decimalDigits: 2 }, |
| 192 |
GEL: { code: "GEL", name: "Georgian Lari", symbol: "₾", decimalDigits: 2 }, |
| 193 |
AMD: { code: "AMD", name: "Armenian Dram", symbol: "֏", decimalDigits: 2 }, |
| 194 |
AZN: { |
| 195 |
code: "AZN", |
| 196 |
name: "Azerbaijani Manat", |
| 197 |
symbol: "₼", |
| 198 |
decimalDigits: 2, |
| 199 |
}, |
| 200 |
|
| 201 |
// African Currencies |
| 202 |
ZAR: { |
| 203 |
code: "ZAR", |
| 204 |
name: "South African Rand", |
| 205 |
symbol: "R", |
| 206 |
decimalDigits: 2, |
| 207 |
}, |
| 208 |
NGN: { code: "NGN", name: "Nigerian Naira", symbol: "₦", decimalDigits: 2 }, |
| 209 |
KES: { |
| 210 |
code: "KES", |
| 211 |
name: "Kenyan Shilling", |
| 212 |
symbol: "KSh", |
| 213 |
decimalDigits: 2, |
| 214 |
}, |
| 215 |
GHS: { code: "GHS", name: "Ghanaian Cedi", symbol: "₵", decimalDigits: 2 }, |
| 216 |
TZS: { |
| 217 |
code: "TZS", |
| 218 |
name: "Tanzanian Shilling", |
| 219 |
symbol: "TSh", |
| 220 |
decimalDigits: 2, |
| 221 |
}, |
| 222 |
UGX: { |
| 223 |
code: "UGX", |
| 224 |
name: "Ugandan Shilling", |
| 225 |
symbol: "USh", |
| 226 |
decimalDigits: 0, |
| 227 |
}, |
| 228 |
RWF: { code: "RWF", name: "Rwandan Franc", symbol: "FRw", decimalDigits: 0 }, |
| 229 |
ETB: { code: "ETB", name: "Ethiopian Birr", symbol: "Br", decimalDigits: 2 }, |
| 230 |
MAD: { |
| 231 |
code: "MAD", |
| 232 |
name: "Moroccan Dirham", |
| 233 |
symbol: "د.� |
| 234 |
.", |
| 235 |
decimalDigits: 2, |
| 236 |
}, |
| 237 |
TND: { code: "TND", name: "Tunisian Dinar", symbol: "د.ت", decimalDigits: 3 }, |
| 238 |
DZD: { code: "DZD", name: "Algerian Dinar", symbol: "د.ج", decimalDigits: 2 }, |
| 239 |
LYD: { code: "LYD", name: "Libyan Dinar", symbol: "ل.د", decimalDigits: 3 }, |
| 240 |
SDG: { |
| 241 |
code: "SDG", |
| 242 |
name: "Sudanese Pound", |
| 243 |
symbol: "ج.س.", |
| 244 |
decimalDigits: 2, |
| 245 |
}, |
| 246 |
XOF: { |
| 247 |
code: "XOF", |
| 248 |
name: "West African CFA Franc", |
| 249 |
symbol: "CFA", |
| 250 |
decimalDigits: 0, |
| 251 |
}, |
| 252 |
XAF: { |
| 253 |
code: "XAF", |
| 254 |
name: "Central African CFA Franc", |
| 255 |
symbol: "FCFA", |
| 256 |
decimalDigits: 0, |
| 257 |
}, |
| 258 |
MUR: { code: "MUR", name: "Mauritian Rupee", symbol: "₨", decimalDigits: 2 }, |
| 259 |
SCR: { |
| 260 |
code: "SCR", |
| 261 |
name: "Seychellois Rupee", |
| 262 |
symbol: "₨", |
| 263 |
decimalDigits: 2, |
| 264 |
}, |
| 265 |
MGA: { code: "MGA", name: "Malagasy Ariary", symbol: "Ar", decimalDigits: 2 }, |
| 266 |
MZN: { |
| 267 |
code: "MZN", |
| 268 |
name: "Mozambican Metical", |
| 269 |
symbol: "MT", |
| 270 |
decimalDigits: 2, |
| 271 |
}, |
| 272 |
ZMW: { code: "ZMW", name: "Zambian Kwacha", symbol: "ZK", decimalDigits: 2 }, |
| 273 |
BWP: { code: "BWP", name: "Botswana Pula", symbol: "P", decimalDigits: 2 }, |
| 274 |
NAD: { code: "NAD", name: "Namibian Dollar", symbol: "N$", decimalDigits: 2 }, |
| 275 |
AOA: { code: "AOA", name: "Angolan Kwanza", symbol: "Kz", decimalDigits: 2 }, |
| 276 |
CDF: { code: "CDF", name: "Congolese Franc", symbol: "FC", decimalDigits: 2 }, |
| 277 |
|
| 278 |
// Americas Currencies |
| 279 |
BRL: { code: "BRL", name: "Brazilian Real", symbol: "R$", decimalDigits: 2 }, |
| 280 |
MXN: { code: "MXN", name: "Mexican Peso", symbol: "$", decimalDigits: 2 }, |
| 281 |
ARS: { code: "ARS", name: "Argentine Peso", symbol: "$", decimalDigits: 2 }, |
| 282 |
CLP: { code: "CLP", name: "Chilean Peso", symbol: "$", decimalDigits: 0 }, |
| 283 |
COP: { code: "COP", name: "Colombian Peso", symbol: "$", decimalDigits: 2 }, |
| 284 |
PEN: { code: "PEN", name: "Peruvian Sol", symbol: "S/", decimalDigits: 2 }, |
| 285 |
UYU: { code: "UYU", name: "Uruguayan Peso", symbol: "$U", decimalDigits: 2 }, |
| 286 |
PYG: { |
| 287 |
code: "PYG", |
| 288 |
name: "Paraguayan Guarani", |
| 289 |
symbol: "₲", |
| 290 |
decimalDigits: 0, |
| 291 |
}, |
| 292 |
BOB: { |
| 293 |
code: "BOB", |
| 294 |
name: "Bolivian Boliviano", |
| 295 |
symbol: "Bs.", |
| 296 |
decimalDigits: 2, |
| 297 |
}, |
| 298 |
VES: { |
| 299 |
code: "VES", |
| 300 |
name: "Venezuelan Bolívar", |
| 301 |
symbol: "Bs.S", |
| 302 |
decimalDigits: 2, |
| 303 |
}, |
| 304 |
CRC: { |
| 305 |
code: "CRC", |
| 306 |
name: "Costa Rican Colón", |
| 307 |
symbol: "₡", |
| 308 |
decimalDigits: 2, |
| 309 |
}, |
| 310 |
PAB: { |
| 311 |
code: "PAB", |
| 312 |
name: "Panamanian Balboa", |
| 313 |
symbol: "B/.", |
| 314 |
decimalDigits: 2, |
| 315 |
}, |
| 316 |
GTQ: { |
| 317 |
code: "GTQ", |
| 318 |
name: "Guatemalan Quetzal", |
| 319 |
symbol: "Q", |
| 320 |
decimalDigits: 2, |
| 321 |
}, |
| 322 |
HNL: { code: "HNL", name: "Honduran Lempira", symbol: "L", decimalDigits: 2 }, |
| 323 |
NIO: { |
| 324 |
code: "NIO", |
| 325 |
name: "Nicaraguan Córdoba", |
| 326 |
symbol: "C$", |
| 327 |
decimalDigits: 2, |
| 328 |
}, |
| 329 |
SVC: { code: "SVC", name: "Salvadoran Colón", symbol: "₡", decimalDigits: 2 }, |
| 330 |
DOP: { code: "DOP", name: "Dominican Peso", symbol: "RD$", decimalDigits: 2 }, |
| 331 |
CUP: { code: "CUP", name: "Cuban Peso", symbol: "₱", decimalDigits: 2 }, |
| 332 |
HTG: { code: "HTG", name: "Haitian Gourde", symbol: "G", decimalDigits: 2 }, |
| 333 |
JMD: { code: "JMD", name: "Jamaican Dollar", symbol: "J$", decimalDigits: 2 }, |
| 334 |
TTD: { |
| 335 |
code: "TTD", |
| 336 |
name: "Trinidad & Tobago Dollar", |
| 337 |
symbol: "TT$", |
| 338 |
decimalDigits: 2, |
| 339 |
}, |
| 340 |
BBD: { |
| 341 |
code: "BBD", |
| 342 |
name: "Barbadian Dollar", |
| 343 |
symbol: "Bds$", |
| 344 |
decimalDigits: 2, |
| 345 |
}, |
| 346 |
BSD: { code: "BSD", name: "Bahamian Dollar", symbol: "B$", decimalDigits: 2 }, |
| 347 |
BZD: { code: "BZD", name: "Belize Dollar", symbol: "BZ$", decimalDigits: 2 }, |
| 348 |
GYD: { code: "GYD", name: "Guyanese Dollar", symbol: "G$", decimalDigits: 2 }, |
| 349 |
SRD: { |
| 350 |
code: "SRD", |
| 351 |
name: "Surinamese Dollar", |
| 352 |
symbol: "$", |
| 353 |
decimalDigits: 2, |
| 354 |
}, |
| 355 |
XCD: { |
| 356 |
code: "XCD", |
| 357 |
name: "East Caribbean Dollar", |
| 358 |
symbol: "EC$", |
| 359 |
decimalDigits: 2, |
| 360 |
}, |
| 361 |
AWG: { code: "AWG", name: "Aruban Florin", symbol: "ƒ", decimalDigits: 2 }, |
| 362 |
ANG: { |
| 363 |
code: "ANG", |
| 364 |
name: "Netherlands Antillean Guilder", |
| 365 |
symbol: "ƒ", |
| 366 |
decimalDigits: 2, |
| 367 |
}, |
| 368 |
KYD: { |
| 369 |
code: "KYD", |
| 370 |
name: "Cayman Islands Dollar", |
| 371 |
symbol: "CI$", |
| 372 |
decimalDigits: 2, |
| 373 |
}, |
| 374 |
BMD: { code: "BMD", name: "Bermudian Dollar", symbol: "$", decimalDigits: 2 }, |
| 375 |
|
| 376 |
// Oceania Currencies |
| 377 |
FJD: { code: "FJD", name: "Fijian Dollar", symbol: "FJ$", decimalDigits: 2 }, |
| 378 |
PGK: { |
| 379 |
code: "PGK", |
| 380 |
name: "Papua New Guinean Kina", |
| 381 |
symbol: "K", |
| 382 |
decimalDigits: 2, |
| 383 |
}, |
| 384 |
SBD: { |
| 385 |
code: "SBD", |
| 386 |
name: "Solomon Islands Dollar", |
| 387 |
symbol: "SI$", |
| 388 |
decimalDigits: 2, |
| 389 |
}, |
| 390 |
VUV: { code: "VUV", name: "Vanuatu Vatu", symbol: "VT", decimalDigits: 0 }, |
| 391 |
WST: { code: "WST", name: "Samoan Tala", symbol: "WS$", decimalDigits: 2 }, |
| 392 |
TOP: { code: "TOP", name: "Tongan Paʻanga", symbol: "T$", decimalDigits: 2 }, |
| 393 |
XPF: { code: "XPF", name: "CFP Franc", symbol: "₣", decimalDigits: 0 }, |
| 394 |
|
| 395 |
// Crypto |
| 396 |
BTC: { code: "BTC", name: "Bitcoin", symbol: "₿", decimalDigits: 8 }, |
| 397 |
ETH: { code: "ETH", name: "Ethereum", symbol: "Ξ", decimalDigits: 8 }, |
| 398 |
}; |
| 399 |
|
| 400 |
/** |
| 401 |
* Get all currencies as array for dropdowns |
| 402 |
*/ |
| 403 |
export const getCurrencyOptions = (): Array<{ |
| 404 |
value: string; |
| 405 |
label: string; |
| 406 |
}> => { |
| 407 |
return Object.values(CURRENCIES).map((currency) => ({ |
| 408 |
value: currency.code, |
| 409 |
label: `${currency.code} - ${currency.name} (${currency.symbol})`, |
| 410 |
})); |
| 411 |
}; |
| 412 |
|
| 413 |
/** |
| 414 |
* Get popular currencies (for quick selection) |
| 415 |
*/ |
| 416 |
export const POPULAR_CURRENCIES = [ |
| 417 |
"USD", |
| 418 |
"EUR", |
| 419 |
"GBP", |
| 420 |
"JPY", |
| 421 |
"CNY", |
| 422 |
"CAD", |
| 423 |
"AUD", |
| 424 |
"CHF", |
| 425 |
"INR", |
| 426 |
"NPR", |
| 427 |
]; |
| 428 |
|
| 429 |
export const getPopularCurrencyOptions = (): Array<{ |
| 430 |
value: string; |
| 431 |
label: string; |
| 432 |
}> => { |
| 433 |
return POPULAR_CURRENCIES.filter((code) => CURRENCIES[code]).map((code) => ({ |
| 434 |
value: code, |
| 435 |
label: `${code} - ${CURRENCIES[code].name} (${CURRENCIES[code].symbol})`, |
| 436 |
})); |
| 437 |
}; |
| 438 |
|
| 439 |
/** |
| 440 |
* Get currency by code |
| 441 |
*/ |
| 442 |
export const getCurrency = (code: string): Currency | undefined => { |
| 443 |
return CURRENCIES[code.toUpperCase()]; |
| 444 |
}; |
| 445 |
|
| 446 |
/** |
| 447 |
* Get currency symbol |
| 448 |
*/ |
| 449 |
export const getCurrencySymbol = (code: string): string => { |
| 450 |
return CURRENCIES[code.toUpperCase()]?.symbol || code; |
| 451 |
}; |
| 452 |
|
| 453 |
/** |
| 454 |
* Format amount with currency |
| 455 |
*/ |
| 456 |
export const formatCurrency = ( |
| 457 |
amount: number, |
| 458 |
code: string = "USD", |
| 459 |
showCode: boolean = false, |
| 460 |
): string => { |
| 461 |
const currency = CURRENCIES[code.toUpperCase()]; |
| 462 |
if (!currency) { |
| 463 |
return `${amount.toFixed(2)} ${code}`; |
| 464 |
} |
| 465 |
|
| 466 |
const formatted = amount.toFixed(currency.decimalDigits); |
| 467 |
const result = `${currency.symbol}${formatted}`; |
| 468 |
|
| 469 |
return showCode ? `${result} ${code}` : result; |
| 470 |
}; |
| 471 |
|