Skip to content

Commit 8df7a76

Browse files
committed
feat(APP-3652): Update AssetDataListItem component to support hideValue property
1 parent b6d1597 commit 8df7a76

File tree

4 files changed

+58
-27
lines changed

4 files changed

+58
-27
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
77

88
## [Unreleased]
99

10+
### Added
11+
12+
- Update `<AssetDataListItem />` module component to support `hideValue` property
13+
1014
### Changed
1115

1216
- Update Manrope font weight for Regular variant from 500 to 400

src/modules/components/asset/assetDataListItem/assetDataListItemStructure/assetDataListItemStructure.stories.tsx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export const LongName: Story = {
4141
};
4242

4343
/**
44-
* Usage of the AssetDataListItem without fiatPrice.
44+
* Usage of the AssetDataListItem component without fiatPrice.
4545
*/
4646
export const UnknownPrice: Story = {
4747
args: {
@@ -51,4 +51,17 @@ export const UnknownPrice: Story = {
5151
},
5252
};
5353

54+
/**
55+
* Set the hideValue property to true to only render the token amount.
56+
*/
57+
export const WithoutValue: Story = {
58+
args: {
59+
name: 'Solana',
60+
logoSrc: 'https://s2.coinmarketcap.com/static/img/coins/64x64/5426.png',
61+
amount: 2.479283,
62+
symbol: 'SOL',
63+
hideValue: true,
64+
},
65+
};
66+
5467
export default meta;

src/modules/components/asset/assetDataListItem/assetDataListItemStructure/assetDataListItemStructure.test.tsx

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,33 @@ describe('<AssetDataListItem.Structure /> component', () => {
1313
return <AssetDataListItemStructure {...completeProps} />;
1414
};
1515

16-
it('renders token name and symbol', () => {
17-
const props = { name: 'Ethereum', symbol: 'ETH' };
18-
render(createTestComponent(props));
19-
expect(screen.getByText(props.name)).toBeInTheDocument();
20-
expect(screen.getByText(props.symbol)).toBeInTheDocument();
16+
it('renders the token name and symbol', () => {
17+
const name = 'Ethereum';
18+
const symbol = 'ETH';
19+
render(createTestComponent({ name, symbol }));
20+
expect(screen.getByText(name)).toBeInTheDocument();
21+
expect(screen.getByText(/ETH/)).toBeInTheDocument();
2122
});
2223

23-
it('correctly renders amount and fiat price', () => {
24-
const props = { amount: 10, fiatPrice: 1250 };
25-
render(createTestComponent(props));
24+
it('correctly renders the amount and fiat value', () => {
25+
const amount = 10;
26+
const fiatPrice = 1250;
27+
const symbol = 'SOL';
28+
render(createTestComponent({ amount, fiatPrice, symbol }));
2629
expect(screen.getByText('$12.50K')).toBeInTheDocument();
27-
expect(screen.getByText(props.amount)).toBeInTheDocument();
30+
expect(screen.getByText(`${amount.toString()} ${symbol}`)).toBeInTheDocument();
2831
});
2932

30-
it('renders unknown with fiatPrice is not set', () => {
31-
const props = { fiatPrice: undefined };
32-
render(createTestComponent(props));
33+
it('renders unknown when fiatPrice is not set', () => {
34+
const fiatPrice = undefined;
35+
render(createTestComponent({ fiatPrice }));
3336
expect(screen.getByText('Unknown')).toBeInTheDocument();
3437
});
38+
39+
it('hides the fiat value when hideValue is set to true', () => {
40+
const fiatPrice = undefined;
41+
const hideValue = true;
42+
render(createTestComponent({ fiatPrice, hideValue }));
43+
expect(screen.queryByText('Unknown')).not.toBeInTheDocument();
44+
});
3545
});

src/modules/components/asset/assetDataListItem/assetDataListItemStructure/assetDataListItemStructure.tsx

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,25 +24,26 @@ export type IAssetDataListItemStructureProps = IDataListItemProps & {
2424
* The fiat price of the asset.
2525
*/
2626
fiatPrice?: number | string;
27+
/**
28+
* Hides the asset value when set to true.
29+
*/
30+
hideValue?: boolean;
2731
};
2832

2933
export const AssetDataListItemStructure: React.FC<IAssetDataListItemStructureProps> = (props) => {
30-
const { logoSrc, name, amount, symbol, fiatPrice, className, ...otherProps } = props;
34+
const { logoSrc, name, amount, symbol, fiatPrice, className, hideValue, ...otherProps } = props;
3135

3236
const { copy } = useGukModulesContext();
3337

34-
const fiatAmount = Number(amount) * Number(fiatPrice);
35-
36-
const formattedAmount = formatterUtils.formatNumber(amount, {
37-
format: NumberFormat.TOKEN_AMOUNT_SHORT,
38-
fallback: '',
39-
});
40-
41-
const formattedPrice = formatterUtils.formatNumber(fiatAmount, {
38+
const fiatValue = Number(amount) * Number(fiatPrice);
39+
const formattedValue = formatterUtils.formatNumber(fiatValue, {
4240
format: NumberFormat.FIAT_TOTAL_SHORT,
4341
fallback: copy.assetDataListItemStructure.unknown,
4442
});
4543

44+
const formattedAmount = formatterUtils.formatNumber(amount, { format: NumberFormat.TOKEN_AMOUNT_SHORT });
45+
const parsedAmount = `${formattedAmount!} ${symbol}`;
46+
4647
return (
4748
<DataList.Item
4849
className={classNames('flex items-center justify-between gap-x-3 py-3 md:py-5', className)}
@@ -54,11 +55,14 @@ export const AssetDataListItemStructure: React.FC<IAssetDataListItemStructurePro
5455
</div>
5556
<div className="flex min-w-0 gap-x-2 text-right">
5657
<div className="flex min-w-0 flex-col gap-y-1">
57-
<span className="text-base leading-tight text-neutral-800 md:text-lg">{formattedPrice}</span>
58-
<div className="flex items-center gap-1">
59-
<p className="text-sm leading-tight text-neutral-500 md:text-base">{formattedAmount}</p>
60-
<p className="truncate text-sm leading-tight text-neutral-500 md:text-base">{symbol}</p>
61-
</div>
58+
<span className="truncate text-base leading-tight text-neutral-800 md:text-lg">
59+
{hideValue ? parsedAmount : formattedValue}
60+
</span>
61+
{!hideValue && (
62+
<span className="truncate text-sm leading-tight text-neutral-500 md:text-base">
63+
{parsedAmount}
64+
</span>
65+
)}
6266
</div>
6367
</div>
6468
</DataList.Item>

0 commit comments

Comments
 (0)