Skip to content

Commit 03cabfa

Browse files
authored
feat: Add hideValue flag to TransactionDataListItem (#583)
Signed-off-by: Milos Dzepina <milos@aragon.org>
1 parent 337c796 commit 03cabfa

5 files changed

Lines changed: 50 additions & 4 deletions

File tree

.changeset/nine-moles-start.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@aragon/gov-ui-kit': minor
3+
---
4+
5+
Add `hideValue` flag to `TransactionDataListItem` to hide fiat value

src/modules/components/transaction/transactionDataListItem/transactionDataListItemStructure/transactionDataListItemStructure.api.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ export type ITransactionDataListItemProps = IDataListItemProps & {
3030
* The price of the transaction in USD.
3131
*/
3232
amountUsd?: number | string;
33+
/**
34+
* Whether to hide the value of the transaction (USD price).
35+
*/
36+
hideValue?: boolean;
3337
/**
3438
* The type of transaction.
3539
* @default TransactionType.ACTION

src/modules/components/transaction/transactionDataListItem/transactionDataListItemStructure/transactionDataListItemStructure.stories.tsx

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,15 @@ type Story = StoryObj<typeof TransactionDataListItemStructure>;
2323
/**
2424
* Default usage example of the TransactionDataList module component.
2525
*/
26-
export const Default: Story = {};
26+
export const Deposit: Story = {
27+
args: {
28+
status: TransactionStatus.SUCCESS,
29+
type: TransactionType.DEPOSIT,
30+
tokenAmount: 10,
31+
tokenSymbol: 'ETH',
32+
date: 1613984914000,
33+
},
34+
};
2735

2836
/**
2937
* Example of the TransactionDataList component with withdraw transaction.
@@ -52,4 +60,19 @@ export const Failed: Story = {
5260
},
5361
};
5462

63+
/**
64+
* Example of the TransactionDataList component without fiat price.
65+
*/
66+
export const HideValue: Story = {
67+
args: {
68+
status: TransactionStatus.SUCCESS,
69+
type: TransactionType.DEPOSIT,
70+
tokenSymbol: 'ETH',
71+
tokenAmount: 10,
72+
amountUsd: 100,
73+
hideValue: true,
74+
date: 1613984914000,
75+
},
76+
};
77+
5578
export default meta;

src/modules/components/transaction/transactionDataListItem/transactionDataListItemStructure/transactionDataListItemStructure.test.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,4 +92,13 @@ describe('<TransactionDataListItem.Structure /> component', () => {
9292
render(createTestComponent({ href }));
9393
expect(screen.getByRole('link')).toHaveAttribute('href', href);
9494
});
95+
96+
it('does not render the formatted USD price of the transaction when hideValue flag is set', () => {
97+
const amountUsd = '123.21';
98+
const tokenAmount = 10;
99+
const type = TransactionType.DEPOSIT;
100+
const usdPrice = formatterUtils.formatNumber(amountUsd, { format: NumberFormat.FIAT_TOTAL_SHORT })!;
101+
render(createTestComponent({ amountUsd, tokenAmount, type, hideValue: true }));
102+
expect(screen.queryByText(usdPrice)).not.toBeInTheDocument();
103+
});
95104
});

src/modules/components/transaction/transactionDataListItem/transactionDataListItemStructure/transactionDataListItemStructure.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ export const TransactionDataListItemStructure: React.FC<ITransactionDataListItem
4040
tokenSymbol,
4141
tokenAmount,
4242
amountUsd,
43+
hideValue,
4344
type = TransactionType.ACTION,
4445
status = TransactionStatus.PENDING,
4546
date,
@@ -81,7 +82,7 @@ export const TransactionDataListItemStructure: React.FC<ITransactionDataListItem
8182
<Spinner className="transition" variant="neutral" responsiveSize={{ md: 'lg' }} />
8283
</div>
8384
)}
84-
<div className="flex w-full flex-col items-start gap-y-1 self-center">
85+
<div className="flex w-full flex-col items-start gap-y-0.5 self-center md:gap-y-1">
8586
<span className="leading-tight text-neutral-800 md:text-lg">{typeToHeading[type]}</span>
8687
{date && (
8788
<p className="text-sm leading-tight text-neutral-500 md:text-base">
@@ -90,9 +91,13 @@ export const TransactionDataListItemStructure: React.FC<ITransactionDataListItem
9091
)}
9192
</div>
9293

93-
<div className="flex shrink-0 flex-col items-end gap-y-1 truncate">
94+
<div className="flex h-full shrink-0 flex-col items-end gap-y-0.5 truncate md:gap-y-1">
9495
<span className="leading-tight text-neutral-800 md:text-lg">{processedTokenAmount}</span>
95-
<span className="text-sm leading-tight text-neutral-500 md:text-base">{formattedTransactionValue}</span>
96+
{!hideValue && (
97+
<span className="text-sm leading-tight text-neutral-500 md:text-base">
98+
{formattedTransactionValue}
99+
</span>
100+
)}
96101
</div>
97102
</DataList.Item>
98103
);

0 commit comments

Comments
 (0)