-
Notifications
You must be signed in to change notification settings - Fork 79
Expand file tree
/
Copy pathTxStatusButton.tsx
More file actions
142 lines (128 loc) · 3.93 KB
/
TxStatusButton.tsx
File metadata and controls
142 lines (128 loc) · 3.93 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
import dayjs from "dayjs"
import Countdown from "react-countdown"
import { makeStyles } from "tss-react/mui"
import { ButtonBase, Chip, Tooltip } from "@mui/material"
import { TX_STATUS } from "@/constants"
import useTxStore from "@/stores/txStore"
import ActiveButton from "./ActiveButton"
const useStyles = makeStyles()(theme => {
return {
chip: {
width: "15rem",
height: "4rem",
fontSize: "1.4rem",
fontWeight: 600,
borderRadius: "10rem",
display: "flex",
justifyContent: "center",
alignItems: "center",
".MuiChip-label": {
display: "flex",
alignItems: "center",
},
},
pendingChip: {
color: "#8C591A",
backgroundColor: "#FFF8F3",
},
successChip: {
color: "#0F8E7E",
backgroundColor: "#DFFCF8",
},
failedChip: {
backgroundColor: "#FFE1DB",
color: "#FF684B",
},
cancelledChip: {
color: "#5B5B5B",
background: "#EDEDED",
},
waitingClaimChip: {
background: "#FFF8F3",
color: "#8C591A",
},
claimButton: {
borderRadius: "0.5rem",
backgroundColor: theme.palette.primary.main,
color: theme.palette.primary.contrastText,
},
pagination: {
".MuiPaginationItem-text": {
fontSize: "1.6rem",
},
".MuiPaginationItem-root": {
color: theme.palette.text.primary,
},
".MuiPaginationItem-root.Mui-selected": {
fontWeight: 700,
backgroundColor: "unset",
},
".MuiSvgIcon-root": {
fontSize: "2.4rem",
},
},
}
})
const TxStatus = props => {
const { tx } = props
const { classes, cx } = useStyles()
const { estimatedTimeMap } = useTxStore()
const renderEstimatedWaitingTime = timestamp => {
if (timestamp) {
return <Countdown date={timestamp} renderer={renderCountDown}></Countdown>
}
return <>Pending</>
}
const renderCountDown = ({ hours, minutes, seconds, completed }) => {
if (completed) {
return <>Pending</>
}
return (
<>
{tx.isL1 ? "Ready" : "Claimable"} in ~{hours ? `${hours}h ` : ""}
{minutes ? `${minutes}m` : ""}
{!minutes && seconds ? `${seconds}s` : ""}
</>
)
}
if (tx.txStatus === TX_STATUS.Sent || tx.txStatus === TX_STATUS.BatchDepositSent) {
if (tx.claimInfo?.claimable) {
return <ActiveButton type="Claim" tx={tx} />
} else if (tx.isL1) {
return <Chip label={renderEstimatedWaitingTime(estimatedTimeMap[`from_${tx.hash}`])} className={cx(classes.chip, classes.pendingChip)}></Chip>
} else {
return (
<Tooltip
placement="top"
title="Scroll provers are still finalizing your transaction, this can take up to 2 hours. Once done, you'll be able to claim it here for use on the target network."
>
<ButtonBase className={cx(classes.chip, classes.waitingClaimChip)}>
{renderEstimatedWaitingTime(tx.initiatedAt ? dayjs.unix(tx.initiatedAt).add(2, "h").valueOf() : null)}
</ButtonBase>
</Tooltip>
)
}
}
if ([TX_STATUS.Dropped, TX_STATUS.SentFailed, TX_STATUS.Skipped, TX_STATUS.BatchDepositFailed].includes(tx.txStatus)) {
return (
<Tooltip placement="top" title="Please click on the transaction hash to view the error reason.">
<Chip
className={cx(classes.chip, classes.failedChip)}
label={
<>
<span>Failed</span>
</>
}
></Chip>
</Tooltip>
)
}
if (tx.txStatus === TX_STATUS.Relayed || tx.txStatus === TX_STATUS.BatchDepositRelayed) {
return <Chip className={cx(classes.chip, classes.successChip)} label="Success"></Chip>
}
if (tx.txStatus === TX_STATUS.RelayedReverted || tx.txStatus === TX_STATUS.FailedRelayed) {
return <ActiveButton type="Retry" tx={tx} />
}
return <Chip label="Pending" className={cx(classes.chip, classes.pendingChip)}></Chip>
}
export default TxStatus