-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathtransactionDataListItemStructure.tsx
More file actions
104 lines (94 loc) · 3.91 KB
/
Copy pathtransactionDataListItemStructure.tsx
File metadata and controls
104 lines (94 loc) · 3.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import classNames from 'classnames';
import {
AvatarIcon,
DataList,
DateFormat,
IconType,
NumberFormat,
Spinner,
formatterUtils,
type AvatarIconVariant,
} from '../../../../../core';
import { ChainEntityType, useBlockExplorer } from '../../../../hooks';
import {
TransactionStatus,
TransactionType,
type ITransactionDataListItemProps,
} from './transactionDataListItemStructure.api';
const typeToHeading: Record<TransactionType, string> = {
[TransactionType.DEPOSIT]: 'Deposit',
[TransactionType.WITHDRAW]: 'Withdraw',
[TransactionType.ACTION]: 'Smart contract action',
};
const typeToIcon: Record<TransactionType, IconType> = {
[TransactionType.DEPOSIT]: IconType.DEPOSIT,
[TransactionType.WITHDRAW]: IconType.WITHDRAW,
[TransactionType.ACTION]: IconType.BLOCKCHAIN_SMARTCONTRACT,
};
const typeToIconVariant: Record<TransactionType, AvatarIconVariant> = {
[TransactionType.DEPOSIT]: 'success',
[TransactionType.WITHDRAW]: 'warning',
[TransactionType.ACTION]: 'info',
};
export const TransactionDataListItemStructure: React.FC<ITransactionDataListItemProps> = (props) => {
const {
chainId,
tokenSymbol,
tokenAmount,
amountUsd,
hideValue,
type = TransactionType.ACTION,
status = TransactionStatus.PENDING,
date,
hash,
className,
...otherProps
} = props;
const { buildEntityUrl } = useBlockExplorer({ chainId });
const blockExplorerHref = buildEntityUrl({ type: ChainEntityType.TRANSACTION, id: hash });
const processedHref = 'href' in otherProps && otherProps.href != null ? otherProps.href : blockExplorerHref;
const formattedTokenAmount = formatterUtils.formatNumber(tokenAmount, { format: NumberFormat.TOKEN_AMOUNT_SHORT });
const formattedTransactionValue = formatterUtils.formatNumber(amountUsd, {
format: NumberFormat.FIAT_TOTAL_SHORT,
fallback: '-',
});
const processedTokenAmount =
type === TransactionType.ACTION || formattedTokenAmount == null
? '-'
: `${formattedTokenAmount} ${tokenSymbol}`;
return (
<DataList.Item
className={classNames('flex items-center justify-between gap-x-3 py-3 md:gap-x-4 md:py-5', className)}
href={processedHref}
{...otherProps}
>
{status === TransactionStatus.SUCCESS && (
<AvatarIcon variant={typeToIconVariant[type]} icon={typeToIcon[type]} responsiveSize={{ md: 'md' }} />
)}
{status === TransactionStatus.FAILED && (
<AvatarIcon variant="critical" icon={IconType.CLOSE} responsiveSize={{ md: 'md' }} />
)}
{status === TransactionStatus.PENDING && (
<div className="flex size-6 shrink-0 items-center justify-center md:size-8">
<Spinner className="transition" variant="neutral" responsiveSize={{ md: 'lg' }} />
</div>
)}
<div className="flex w-full flex-col items-start gap-y-0.5 self-center md:gap-y-1">
<span className="leading-tight text-neutral-800 md:text-lg">{typeToHeading[type]}</span>
{date && (
<p className="text-sm leading-tight text-neutral-500 md:text-base">
{formatterUtils.formatDate(date, { format: DateFormat.YEAR_MONTH_DAY_TIME })}
</p>
)}
</div>
<div className="flex h-full shrink-0 flex-col items-end gap-y-0.5 truncate md:gap-y-1">
<span className="leading-tight text-neutral-800 md:text-lg">{processedTokenAmount}</span>
{!hideValue && (
<span className="text-sm leading-tight text-neutral-500 md:text-base">
{formattedTransactionValue}
</span>
)}
</div>
</DataList.Item>
);
};