Skip to content

Commit

Permalink
addressing comments
Browse files Browse the repository at this point in the history
  • Loading branch information
dbrans committed Apr 16, 2024
1 parent 9980779 commit 93843bd
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 11 deletions.
4 changes: 2 additions & 2 deletions ui/hooks/useCurrencyDisplay.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const MIN_AMOUNT_DISPLAY = `<${MIN_AMOUNT}`;

// The default precision for displaying currency values.
// It set to the number of decimal places in the minimum amount.
export const MIN_AMOUNT_DECIMALS = new BigNumber(MIN_AMOUNT).decimalPlaces();
export const DEFAULT_PRECISION = new BigNumber(MIN_AMOUNT).decimalPlaces();

/**
* Defines the shape of the options parameter for useCurrencyDisplay
Expand Down Expand Up @@ -74,7 +74,7 @@ export function useCurrencyDisplay(
) {
const ethDisplayValue = new Numeric(inputValue, 16, EtherDenomination.WEI)
.toDenomination(denomination || EtherDenomination.ETH)
.round(numberOfDecimals || MIN_AMOUNT_DECIMALS)
.round(numberOfDecimals || DEFAULT_PRECISION)
.toBase(10)
.toString();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,7 @@ export const AmountPill: React.FC<{
// ERC721 amounts are always 1 and are not displayed.
if (asset.standard !== TokenStandard.ERC721) {
const formattedAmount = formatAmount(locale, amount.abs());
const fullPrecisionAmount = formatAmountMaxPrecision(
locale,
amount.abs().toNumber(),
);
const fullPrecisionAmount = formatAmountMaxPrecision(locale, amount.abs());

amountParts.push(formattedAmount);
tooltipParts.push(fullPrecisionAmount);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
import { BigNumber } from 'bignumber.js';
import {
MIN_AMOUNT,
MIN_AMOUNT_DECIMALS,
DEFAULT_PRECISION,
} from '../../../../hooks/useCurrencyDisplay';

// The number of significant decimals places to show for amounts less than 1.
const MAX_SIGNIFICANT_DECIMAL_PLACES = 3;

const ZERO_DISPLAY = '0';

export const formatAmountMaxPrecision = (
export function formatAmountMaxPrecision(
locale: string,
num: number | BigNumber,
): string =>
new Intl.NumberFormat(locale, {
): string {
return new Intl.NumberFormat(locale, {
minimumSignificantDigits: 1,
}).format(new BigNumber(num.toString()).toNumber());
}

/**
* Formats the a token amount with variable precision and significant
Expand Down Expand Up @@ -65,7 +66,7 @@ export function formatAmount(locale: string, amount: BigNumber): string {
return new Intl.NumberFormat(locale, {
maximumSignificantDigits: MAX_SIGNIFICANT_DECIMAL_PLACES,
} as Intl.NumberFormatOptions).format(
amount.round(MIN_AMOUNT_DECIMALS).toNumber(),
amount.round(DEFAULT_PRECISION).toNumber(),
);
}

Expand Down

0 comments on commit 93843bd

Please sign in to comment.