MCPcopy
hub / github.com/Uniswap/interface / formatNumber

Function formatNumber

src/utils/formatNumbers.ts:476–507  ·  view source on GitHub ↗
({
  input,
  type = NumberType.TokenNonTx,
  placeholder = '-',
  locale = DEFAULT_LOCALE,
  localCurrency = DEFAULT_LOCAL_CURRENCY,
  conversionRate,
}: FormatNumberOptions)

Source from the content-addressed store, hash-verified

474}
475
476function 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
509interface FormatCurrencyAmountOptions {
510 amount: Nullish<CurrencyAmount<Currency>>

Callers 15

SwapModalHeaderAmountFunction · 0.85
TradePriceFunction · 0.85
useGasPriceFunction · 0.85
GasCostItemFunction · 0.85
GaslessSwapLabelFunction · 0.85
GasEstimateTooltipFunction · 0.85
FeeRowFunction · 0.85
useLineItemFunction · 0.85
TokenRow.tsxFile · 0.85
StatFunction · 0.85
AuthenticatedHeaderFunction · 0.85
TokenRowFunction · 0.85

Calls 1

getFormatterRuleFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…