-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathExplorerTable.tsx
More file actions
172 lines (155 loc) · 6.17 KB
/
ExplorerTable.tsx
File metadata and controls
172 lines (155 loc) · 6.17 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
import React from "react"
import { Table, TableHead, TableCell, TableBody, TableRow, CircularProgress } from "@mui/material"
import clsx from "clsx"
import { Link } from "react-router-dom"
import { EnvironmentMetadata, EvmBridgeConfig, ExplorerContextState, ResourceTypes, SharedConfigDomain, Transfer, TransferStatus } from "../../types"
import { renderNetworkIcon, renderStatusIcon } from "../../utils/renderUtils"
import {
filterTransfers,
formatAmountDecimals,
formatDistanceDate,
formatTransferType,
displayStatus,
getFormatedFee,
renderAmountValue,
renderFormatedConvertedAmount,
shortenAddress,
} from "../../utils/transferHelpers"
import { useStyles } from "./styles"
import { add, isAfter } from "date-fns"
type ExplorerTable = {
active: boolean
setActive: (state: boolean) => void
chains: Array<EvmBridgeConfig>
state: ExplorerContextState
sharedConfig: SharedConfigDomain[] | []
domainMetadata: EnvironmentMetadata | {}
}
const ExplorerTable: React.FC<ExplorerTable> = ({ state, domainMetadata }: ExplorerTable) => {
const { classes } = useStyles()
const { VITE_NATIVE_TOKEN_TRANSFER_RESOURCE_ID } = import.meta.env
const renderTransferList = (transferData: Transfer[]): JSX.Element[] => {
return transferData.map((transfer: Transfer) => {
const { deposit, amount, resource, fromDomainId, toDomainId, id, resourceID, fee, usdValue, timestamp } = transfer
let { status } = transfer
if (deposit && deposit.timestamp && status === "pending" && isAfter(Date.now(), add(new Date(deposit.timestamp), { hours: 2 }))) {
status = "failed" as TransferStatus
}
const { type } = resource
const fromDomainInfo = (domainMetadata as EnvironmentMetadata)[Number(fromDomainId)]
const toDomainInfo = (domainMetadata as EnvironmentMetadata)[Number(toDomainId)]
const formatedFee = getFormatedFee(fee)
const fromDomainType = fromDomainInfo?.type
let txHash: string | undefined
if (fromDomainType === "evm" && deposit) {
txHash = shortenAddress(deposit?.txHash)
} else {
txHash = deposit?.txHash
}
const fromDomainName = fromDomainInfo.renderName
const toDomainName = toDomainInfo.renderName
const dateFormated = formatDistanceDate(deposit?.timestamp!)
const amountWithFormatedDecimals = formatAmountDecimals(amount)
return (
<TableRow className={classes.row} key={transfer.id}>
<TableCell className={clsx(classes.row, classes.dataRow, classes.cellRow)}>
{txHash !== undefined ? (
<Link
className={classes.hashAnchorLink}
to={`/transfer/${deposit?.txHash!}`}
state={{ id: id, page: state.queryParams.page, txHash: deposit?.txHash }}
>
{txHash}
</Link>
) : (
"-"
)}
</TableCell>
<TableCell className={clsx(classes.row, classes.dataRow)}>
<div className={classes.accountAddress}>
<span>
{renderStatusIcon(status, classes)} {displayStatus(status)}
</span>
</div>
</TableCell>
<TableCell className={clsx(classes.row, classes.dataRow)}>
<div style={{ width: "100%" }}>
<span style={{ display: "flex" }}>
{renderNetworkIcon(fromDomainInfo?.caipId, classes)} {fromDomainName}
</span>
</div>
</TableCell>
<TableCell className={clsx(classes.row, classes.dataRow)}>
<div style={{ width: "100%" }}>
<span style={{ display: "flex" }}>
{renderNetworkIcon(toDomainInfo?.caipId, classes)} {toDomainName}
</span>
</div>
</TableCell>
<TableCell className={clsx(classes.row, classes.dataRow)}>
<span className={classes.amountInfo}>
<span>
{type !== undefined
? formatTransferType(resourceID !== VITE_NATIVE_TOKEN_TRANSFER_RESOURCE_ID ? (type as ResourceTypes) : ResourceTypes.NATIVE)
: "-"}
</span>
</span>
</TableCell>
<TableCell className={clsx(classes.row, classes.dataRow)}>
<span className={classes.amountInfo}>
<span>{dateFormated}</span>
</span>
</TableCell>
<TableCell className={clsx(classes.row, classes.dataRow)}>
<span className={classes.amountInfo}>
<span>{formatedFee}</span>
</span>
</TableCell>
<TableCell className={clsx(classes.row, classes.dataRow)}>
<span className={classes.amountInfo}>
<div className={classes.amountContainer}>
<span>{renderAmountValue(type as ResourceTypes, amountWithFormatedDecimals, resourceID, state.resourcesPerPage)}</span>
{renderFormatedConvertedAmount(type as ResourceTypes, usdValue)}
</div>
</span>
</TableCell>
</TableRow>
)
})
}
return (
<Table className={classes.rootTable}>
<TableHead
sx={{
backgroundColor: "#DBD3C7",
"& > tr > th": {
fontSize: "14px",
fontWeight: "400",
},
}}
>
<TableRow className={classes.row}>
<TableCell sx={{ borderTopLeftRadius: "12px !important" }}>Source Tx/Extr Hash</TableCell>
<TableCell>Status</TableCell>
<TableCell>From</TableCell>
<TableCell>To</TableCell>
<TableCell>Type</TableCell>
<TableCell>Date</TableCell>
<TableCell>Fee</TableCell>
<TableCell sx={{ borderTopRightRadius: "12px !important" }}>Value</TableCell>
</TableRow>
</TableHead>
{state.isLoading === "done" && <TableBody>{renderTransferList(filterTransfers(state.transfers, domainMetadata))}</TableBody>}
{state.isLoading === "loading" && (
<TableBody>
<TableRow>
<TableCell colSpan={8} align="center">
<CircularProgress />
</TableCell>
</TableRow>
</TableBody>
)}
</Table>
)
}
export default ExplorerTable