Skip to content

Commit

Permalink
fix: removes decimals from balances > $1,000
Browse files Browse the repository at this point in the history
  • Loading branch information
kyranjamie committed Mar 26, 2024
1 parent 9dcd980 commit 5db63de
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/app/common/hooks/balance/use-total-balance.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ export function useTotalBalance({ btcAddress, stxAddress }: UseTotalBalanceArgs)
const totalBalance = { ...stxUsdAmount, amount: stxUsdAmount.amount.plus(btcUsdAmount.amount) };
return {
totalBalance,
totalUsdBalance: i18nFormatCurrency(totalBalance),
totalUsdBalance: i18nFormatCurrency(
totalBalance,
totalBalance.amount.isGreaterThanOrEqualTo(100_000) ? 0 : 2
),
isLoading,
};
}, [btcBalance, btcMarketData, stxMarketData, isLoading, stxBalance]);
Expand Down
8 changes: 6 additions & 2 deletions src/app/common/money/format-money.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,13 @@ export function formatMoneyPadded({ amount, symbol, decimals }: Money) {
return `${amount.shiftedBy(-decimals).toFormat(decimals)} ${symbol}`;
}

export function i18nFormatCurrency(quantity: Money, locale = 'en-US') {
export function i18nFormatCurrency(quantity: Money, decimals: number = 2) {
if (quantity.symbol !== 'USD') throw new Error('Cannot format non-USD amounts');
const currencyFormatter = new Intl.NumberFormat(locale, { style: 'currency', currency: 'USD' });
const currencyFormatter = new Intl.NumberFormat('en-US', {
style: 'currency',
currency: 'USD',
maximumFractionDigits: decimals,
});

const formatted = currencyFormatter.format(
quantity.amount.shiftedBy(-quantity.decimals).toNumber()
Expand Down

0 comments on commit 5db63de

Please sign in to comment.