Skip to content

Commit 18f74fe

Browse files
committed
chore: remove bold weight on token list item v2 and adding comma separation to token price
1 parent b5124ce commit 18f74fe

File tree

3 files changed

+24
-8
lines changed

3 files changed

+24
-8
lines changed

app/components/UI/Predict/utils/format.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1618,6 +1618,22 @@ describe('format utils', () => {
16181618
// Assert
16191619
expect(result).toBe('$0.5678');
16201620
});
1621+
1622+
it('truncates to 2 decimals for prices >= 1 with extra decimal places', () => {
1623+
// Arrange & Act
1624+
const result = formatPriceWithSubscriptNotation(2285.013);
1625+
1626+
// Assert
1627+
expect(result).toBe('$2,285.01');
1628+
});
1629+
1630+
it('truncates to 2 decimals for prices >= 1 with 4 decimal places', () => {
1631+
// Arrange & Act
1632+
const result = formatPriceWithSubscriptNotation(1.2345);
1633+
1634+
// Assert
1635+
expect(result).toBe('$1.23');
1636+
});
16211637
});
16221638

16231639
describe('Zero value', () => {

app/components/UI/Predict/utils/format.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,15 +114,17 @@ export const formatPrice = (
114114
* - Uses subscript notation for values with 4+ leading zeros (e.g., 0.00000614 → $0.0₅614)
115115
* - The subscript indicates the number of leading zeros after the decimal point
116116
* - Returns "—" for zero values
117-
* - Uses min 2, max 4 decimal places for regular values
117+
* - Values >= 1: exactly 2 decimal places (e.g. $2,285.01)
118+
* - Values < 1: up to 4 decimal places (e.g. $0.1446)
118119
* @param price - The price value to format (string or number)
119120
* @param currencyCode - ISO 4217 currency code (e.g. 'USD', 'EUR'). Defaults to 'USD'.
120121
* @returns Formatted price string with currency symbol or "—" for zero
122+
* @example formatPriceWithSubscriptNotation(2285.013) => "$2,285.01"
121123
* @example formatPriceWithSubscriptNotation(1.99) => "$1.99"
122124
* @example formatPriceWithSubscriptNotation(0.144566) => "$0.1446"
123125
* @example formatPriceWithSubscriptNotation(0.00000614) => "$0.0₅614"
124126
* @example formatPriceWithSubscriptNotation(0) => "—"
125-
* @example formatPriceWithSubscriptNotation(1.2345, 'EUR') => "€1.2345"
127+
* @example formatPriceWithSubscriptNotation(1.2345, 'EUR') => "€1.23"
126128
*/
127129
export const formatPriceWithSubscriptNotation = (
128130
price: string | number,
@@ -151,7 +153,7 @@ export const formatPriceWithSubscriptNotation = (
151153
const formattedNumber = new Intl.NumberFormat('en-US', {
152154
style: 'decimal',
153155
minimumFractionDigits: 2,
154-
maximumFractionDigits: 4,
156+
maximumFractionDigits: num >= 1 ? 2 : 4,
155157
}).format(num);
156158
return addSymbol(formattedNumber);
157159
};

app/components/UI/Tokens/TokenList/TokenListItemV2/TokenListItemV2.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ import {
7272
} from '../../../../../selectors/networkController';
7373
import { selectShowFiatInTestnets } from '../../../../../selectors/settings';
7474
import { getNativeTokenAddress } from '@metamask/assets-controllers';
75-
import { addCurrencySymbol } from '../../../../../util/number';
75+
import { formatPriceWithSubscriptNotation } from '../../../Predict/utils/format';
7676
import { safeToChecksumAddress } from '../../../../../util/address';
7777
import generateTestId from '../../../../../../wdio/utils/generateTestId';
7878
import { getAssetTestId } from '../../../../../../wdio/screen-objects/testIDs/Screens/WalletView.testIds';
@@ -631,7 +631,7 @@ export const TokenListItemV2 = React.memo(
631631
asset.balanceFiat === TOKEN_RATE_UNDEFINED ||
632632
hideFiatForTestnet
633633
? CLTextVariant.BodySM
634-
: CLTextVariant.BodyMDBold
634+
: CLTextVariant.BodyMDMedium
635635
}
636636
isHidden={privacyMode}
637637
length={SensitiveTextLength.Medium}
@@ -662,11 +662,9 @@ export const TokenListItemV2 = React.memo(
662662
twClassName="uppercase"
663663
>
664664
{tokenPriceInFiat && !hideFiatForScamWarning
665-
? addCurrencySymbol(
665+
? formatPriceWithSubscriptNotation(
666666
tokenPriceInFiat,
667667
currentCurrency,
668-
true,
669-
true,
670668
)
671669
: '-'}
672670
{' \u2022 '}

0 commit comments

Comments
 (0)