({
input,
type = NumberType.TokenNonTx,
placeholder = '-',
locale = DEFAULT_LOCALE,
localCurrency = DEFAULT_LOCAL_CURRENCY,
conversionRate,
}: FormatNumberOptions)
| 474 | } |
| 475 | |
| 476 | function formatNumber({ |
| 477 | input, |
| 478 | type = NumberType.TokenNonTx, |
| 479 | placeholder = '-', |
| 480 | locale = DEFAULT_LOCALE, |
| 481 | localCurrency = DEFAULT_LOCAL_CURRENCY, |
| 482 | conversionRate, |
| 483 | }: FormatNumberOptions): string { |
| 484 | if (input === null || input === undefined) { |
| 485 | return placeholder |
| 486 | } |
| 487 | |
| 488 | const { hardCodedInput, formatterOptions } = getFormatterRule(input, type, conversionRate) |
| 489 | |
| 490 | if (formatterOptions.currency) { |
| 491 | input = conversionRate ? input * conversionRate : input |
| 492 | formatterOptions.currency = localCurrency |
| 493 | formatterOptions.currencyDisplay = LOCAL_CURRENCY_SYMBOL_DISPLAY_TYPE[localCurrency] |
| 494 | } |
| 495 | |
| 496 | if (!hardCodedInput) { |
| 497 | return new Intl.NumberFormat(locale, formatterOptions).format(input) |
| 498 | } |
| 499 | |
| 500 | if (hardCodedInput.hardcodedOutput) { |
| 501 | return hardCodedInput.hardcodedOutput |
| 502 | } |
| 503 | |
| 504 | const { input: hardCodedInputValue, prefix } = hardCodedInput |
| 505 | if (hardCodedInputValue === undefined) return placeholder |
| 506 | return (prefix ?? '') + new Intl.NumberFormat(locale, formatterOptions).format(hardCodedInputValue) |
| 507 | } |
| 508 | |
| 509 | interface FormatCurrencyAmountOptions { |
| 510 | amount: Nullish<CurrencyAmount<Currency>> |
no test coverage detected
searching dependent graphs…