Skip to content

Commit

Permalink
fix: show more decimal places for exchange rate bottom sheet
Browse files Browse the repository at this point in the history
  • Loading branch information
chybisov committed Feb 1, 2023
1 parent 29fd67d commit 88b7f6a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
12 changes: 10 additions & 2 deletions packages/widget/src/pages/SwapPage/ExchangeRateBottomSheet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,11 @@ const ExchangeRateBottomSheetContent: React.FC<
<Typography>{t('swap.quotedAmount')}</Typography>
<Typography fontWeight={600}>
{t('format.number', {
value: formatTokenAmount(data?.oldToAmount, data?.toToken.decimals),
value: formatTokenAmount(
data?.oldToAmount,
data?.toToken.decimals,
5,
),
})}{' '}
{data?.toToken.symbol}
</Typography>
Expand All @@ -121,7 +125,11 @@ const ExchangeRateBottomSheetContent: React.FC<
<Typography>{t('swap.currentAmount')}</Typography>
<Typography fontWeight={600}>
{t('format.number', {
value: formatTokenAmount(data?.newToAmount, data?.toToken.decimals),
value: formatTokenAmount(
data?.newToAmount,
data?.toToken.decimals,
5,
),
})}{' '}
{data?.toToken.symbol}
</Typography>
Expand Down
2 changes: 1 addition & 1 deletion packages/widget/src/utils/format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Big.NE = -42;
export const formatTokenAmount = (
amount: string = '0',
decimals: number = 0,
decimalPlaces: number = 3,
) => {
let shiftedAmount = amount;
if (decimals) {
Expand All @@ -23,7 +24,6 @@ export const formatTokenAmount = (
return '0';
}

let decimalPlaces = 3;
const absAmount = Math.abs(parsedAmount);
while (absAmount < 1 / 10 ** decimalPlaces) {
decimalPlaces++;
Expand Down

0 comments on commit 88b7f6a

Please sign in to comment.