Skip to content

Commit

Permalink
fix: handle undefined options in number abbrev (#3860)
Browse files Browse the repository at this point in the history
  • Loading branch information
firebomb1 authored Feb 23, 2023
1 parent 4ae2a06 commit 9d1b22c
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/hooks/useLocaleFormatter/useLocaleFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,14 +187,19 @@ export const useLocaleFormatter = (args?: useLocaleFormatterArgs): NumberFormatt
minimumFractionDigits,
lessThanMin ? 6 : getFiatNumberFractionDigits(number),
)
// Filter out undefined options caused by optional component props so they do not override the defaults
const filteredOptions = options
? Object.fromEntries(Object.entries(options).filter(([_, value]) => value !== undefined))
: {}
const formatter = new Intl.NumberFormat(deviceLocale, {
notation: number < bounds.min || noDecimals ? 'standard' : 'compact',
compactDisplay: fiatType || number < longCompactDisplayLowerBound ? 'short' : 'long',
style: fiatType ? 'currency' : 'decimal',
currency: fiatType,
minimumFractionDigits,
// Force enough fractional digits to truncate it properly without rounding off below
maximumFractionDigits: 10,
...options,
...filteredOptions,
})

const parts = formatter.formatToParts(formatNumber)
Expand Down

0 comments on commit 9d1b22c

Please sign in to comment.