Skip to content

Commit c3c2ff1

Browse files
committed
fix: nft bridge history UI
1 parent ca17d5c commit c3c2ff1

File tree

9 files changed

+288
-46
lines changed

9 files changed

+288
-46
lines changed

Diff for: src/pages/bridge/components/TxTable/index.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import { useApp } from "@/contexts/AppContextProvider"
2424
import useTokenInfo from "@/hooks/useTokenInfo"
2525
import useTxStore from "@/stores/txStore"
2626
import { toTokenDisplay } from "@/utils"
27-
import { generateExploreLink, truncateHash } from "@/utils"
27+
import { generateTxLink, truncateHash } from "@/utils"
2828

2929
const useStyles = makeStyles()(theme => {
3030
return {
@@ -232,7 +232,7 @@ const TxRow = props => {
232232
<TableCell sx={{ width: "30rem" }}>
233233
<Stack direction="column">
234234
<Typography>From {tx.fromName}: </Typography>
235-
<Link external href={generateExploreLink(tx.fromExplore, tx.hash)} className="leading-normal flex-1">
235+
<Link external href={generateTxLink(tx.fromExplore, tx.hash)} className="leading-normal flex-1">
236236
{truncateHash(tx.hash)}
237237
</Link>
238238
{!tx.fromBlockNumber && <LinearProgress />}
@@ -242,7 +242,7 @@ const TxRow = props => {
242242
<Stack direction="column" className="mt-[1.2rem]">
243243
<Typography>To {tx.toName}: </Typography>
244244
{tx.toHash ? (
245-
<Link external href={generateExploreLink(tx.toExplore, tx.toHash)} className="leading-normal flex-1">
245+
<Link external href={generateTxLink(tx.toExplore, tx.toHash)} className="leading-normal flex-1">
246246
{truncateHash(tx.toHash)}
247247
</Link>
248248
) : (

Diff for: src/pages/nftBridge/Header/TransactionHistory.tsx

+5-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { CircularProgress, Stack, Typography } from "@mui/material"
44

55
import { BRIDGE_PAGE_SIZE } from "@/constants"
66
import { useApp } from "@/contexts/AppContextProvider"
7-
import useTxStore from "@/stores/txStore"
7+
import useNFTTxStore from "@/stores/nftTxStore"
88

99
import TxTable from "../components/TxTable"
1010

@@ -42,9 +42,10 @@ const TransactionsList = (props: any) => {
4242
txHistory: { refreshPageTransactions },
4343
} = useApp()
4444

45-
const { page, total, loading, frontTransactions, pageTransactions } = useTxStore()
45+
const { page, total, loading, frontTransactions } = useNFTTxStore()
4646

47-
if (!pageTransactions?.length) {
47+
// TODO: waiting for api
48+
if (!frontTransactions?.length) {
4849
return (
4950
<Typography variant="body1" color="textSecondary">
5051
Your transactions will appear here...
@@ -67,7 +68,7 @@ const TransactionsList = (props: any) => {
6768
</Stack>
6869
</div>
6970
<TxTable
70-
data={pageTransactions}
71+
data={frontTransactions.slice(0, 3)}
7172
pagination={{
7273
count: Math.ceil((total + frontTransactions.length) / BRIDGE_PAGE_SIZE),
7374
page,

Diff for: src/pages/nftBridge/Header/index.tsx

+7-8
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ import { ReactComponent as ExitIcon } from "@/assets/svgs/exit.svg"
88
import Link from "@/components/Link"
99
import TextIconButton from "@/components/TextIconButton"
1010
import WalletIndicator from "@/components/WalletIndicator"
11-
import { useApp } from "@/contexts/AppContextProvider"
11+
// import { useApp } from "@/contexts/AppContextProvider"
1212
import { useWeb3Context } from "@/contexts/Web3ContextProvider"
13-
// import TransactionHistory from "@/pages/bridge/Header/TransactionHistory"
1413
import useBridgeStore from "@/stores/bridgeStore"
1514
import useNFTBridgeStore from "@/stores/nftBridgeStore"
1615
import { truncateAddress } from "@/utils"
1716

1817
import CopyButton from "./CopyButton"
1918
import PageTitle from "./PageTitle"
19+
import TransactionHistory from "./TransactionHistory"
2020

2121
const useStyles = makeStyles()(theme => ({
2222
container: {
@@ -89,14 +89,14 @@ const Header = () => {
8989

9090
const { clearViewingList, clearSelectedList } = useNFTBridgeStore()
9191

92-
const {
93-
txHistory: { refreshPageTransactions },
94-
} = useApp()
92+
// const {
93+
// txHistory: { refreshPageTransactions },
94+
// } = useApp()
9595
const { historyVisible, changeHistoryVisible } = useBridgeStore()
9696

9797
const handleOpen = () => {
9898
changeHistoryVisible(true)
99-
refreshPageTransactions(1)
99+
// refreshPageTransactions(1)
100100
}
101101

102102
const handleClose = () => {
@@ -132,8 +132,7 @@ const Header = () => {
132132
</Stack>
133133
<Divider />
134134
<Box sx={{ position: "relative", margin: ["2.4rem 0", "3rem 0"] }}>
135-
coming soon!
136-
{/* <TransactionHistory /> */}
135+
<TransactionHistory />
137136
</Box>
138137
</Card>
139138
</WalletIndicator>

Diff for: src/pages/nftBridge/NFTPanel/Transfer/Send.tsx

+29-15
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { useAsyncMemo } from "@/hooks"
1111
import useGasFee from "@/hooks/useGasFee"
1212
import useApprove from "@/hooks/useNFTApprove"
1313
import useNFTBridgeStore from "@/stores/nftBridgeStore"
14+
import useNFTTxStore from "@/stores/nftTxStore"
1415

1516
import ApproveLoadingModal from "./ApproveLoadingModal"
1617
import SendLoadingModal from "./SendLoadingModal"
@@ -20,8 +21,9 @@ const Send = () => {
2021
const { walletCurrentAddress } = useWeb3Context()
2122
const { networksAndSigners } = useApp()
2223

24+
const { addNFTTransaction, updateNFTTransaction } = useNFTTxStore()
2325
const { tokenInstance, gatewayAddress, isLayer1 } = useNFTBridgeContext()
24-
const { contract, selectedList, exciseSelected, updatePromptMessage } = useNFTBridgeStore()
26+
const { contract, selectedList, exciseSelected, updatePromptMessage, fromNetwork, toNetwork } = useNFTBridgeStore()
2527
const selectedTokenIds = useNFTBridgeStore(state => state.selectedTokenIds())
2628

2729
const { setApproval, checkApproval } = useApprove()
@@ -69,15 +71,31 @@ const Send = () => {
6971
}
7072
}
7173

72-
const handleSend = () => {
74+
const handleSend = async () => {
7375
setSendLoading(true)
7476
setSendModalLoading(true)
75-
const tx = isLayer1 ? deposite() : withdraw()
76-
tx.then(result => {
77-
console.log(result, "send result")
78-
setTxHash(result.transactionHash)
79-
exciseSelected()
77+
const tx = isLayer1 ? await deposite() : await withdraw()
78+
addNFTTransaction({
79+
hash: tx.hash,
80+
fromName: fromNetwork.name,
81+
toName: toNetwork.name,
82+
fromExplore: fromNetwork.explorer,
83+
toExplore: toNetwork.explorer,
84+
tokenType: contract.type,
85+
tokenAddress: isLayer1 ? contract.l1 : contract.l2,
86+
amounts: selectedList.map(item => item.transferAmount),
87+
tokenIds: selectedTokenIds,
88+
isL1: isLayer1,
8089
})
90+
tx.wait()
91+
.then(receipt => {
92+
console.log(receipt, "send receipt")
93+
updateNFTTransaction(tx.hash, {
94+
fromBlockNumber: receipt.blockNumber,
95+
})
96+
setTxHash(receipt.transactionHash)
97+
exciseSelected()
98+
})
8199
.catch(error => {
82100
updatePromptMessage(error.message)
83101
})
@@ -104,8 +122,7 @@ const Send = () => {
104122
value: gasFee,
105123
},
106124
)
107-
const txResult = await tx.wait()
108-
return txResult
125+
return tx
109126
}
110127

111128
const deposite1155 = async () => {
@@ -119,8 +136,7 @@ const Send = () => {
119136
value: gasFee,
120137
},
121138
)
122-
const txResult = await tx.wait()
123-
return txResult
139+
return tx
124140
}
125141

126142
const withdraw = () => {
@@ -138,8 +154,7 @@ const Send = () => {
138154
gasLimit,
139155
{ value: gasFee },
140156
)
141-
const txResult = await tx.wait()
142-
return txResult
157+
return tx
143158
}
144159

145160
const withdraw1155 = async () => {
@@ -151,8 +166,7 @@ const Send = () => {
151166
gasLimit,
152167
{ value: gasFee },
153168
)
154-
const txResult = await tx.wait()
155-
return txResult
169+
return tx
156170
}
157171

158172
const handleCloseSendModal = () => {

Diff for: src/pages/nftBridge/NFTPanel/Transfer/TransactionResultModal.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { Button } from "@mui/material"
55
import Link from "@/components/Link"
66
import { BLOCK_EXPLORER } from "@/constants"
77
import { useWeb3Context } from "@/contexts/Web3ContextProvider"
8-
import { generateExploreLink } from "@/utils"
8+
import { generateTxLink } from "@/utils"
99

1010
import Modal from "../../components/Modal"
1111

@@ -17,7 +17,7 @@ const TransactionResultModal = props => {
1717
const txUrl = useMemo(() => {
1818
if (hash && chainId) {
1919
const explorer = BLOCK_EXPLORER[chainId]
20-
return generateExploreLink(explorer, hash)
20+
return generateTxLink(explorer, hash)
2121
}
2222
return ""
2323
}, [chainId, hash])

Diff for: src/pages/nftBridge/components/TxTable/index.tsx

+38-13
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ import {
1919

2020
import Link from "@/components/Link"
2121
import { useApp } from "@/contexts/AppContextProvider"
22-
import useSymbol from "@/hooks/useSymbol"
23-
import { generateExploreLink, truncateHash } from "@/utils"
22+
import { generateContractLink, generateTxLink, truncateAddress, truncateHash } from "@/utils"
2423

2524
const useStyles = makeStyles()(theme => {
2625
return {
@@ -35,7 +34,7 @@ const useStyles = makeStyles()(theme => {
3534
boxShadow: "unset",
3635
border: `1px solid ${theme.palette.border.main}`,
3736
borderRadius: "1rem",
38-
width: "70rem",
37+
width: "82rem",
3938
},
4039
tableTitle: {
4140
marginTop: "2.8rem",
@@ -52,10 +51,15 @@ const useStyles = makeStyles()(theme => {
5251
},
5352
},
5453
chip: {
55-
width: "12.6rem",
56-
height: "3.8rem",
57-
fontSize: "1.6rem",
54+
width: "9rem",
55+
height: "2.8rem",
56+
fontSize: "1.2rem",
57+
padding: 0,
5858
fontWeight: 500,
59+
".MuiChip-label": {
60+
paddingLeft: 0,
61+
paddingRight: 0,
62+
},
5963
},
6064
pendingChip: {
6165
color: theme.palette.tagWarning.main,
@@ -100,6 +104,9 @@ const TxTable = (props: any) => {
100104
<TableHead className={classes.tableHeader}>
101105
<TableRow>
102106
<TableCell>Status</TableCell>
107+
<TableCell>Contract Address</TableCell>
108+
<TableCell>Type</TableCell>
109+
<TableCell>Token IDs</TableCell>
103110
<TableCell>Amount</TableCell>
104111
<TableCell>Txn Hash</TableCell>
105112
</TableRow>
@@ -165,8 +172,6 @@ const TxRow = props => {
165172
return txStatus(tx.toBlockNumber, tx.isL1, true)
166173
}, [tx, txStatus])
167174

168-
const { loading: symbolLoading, symbol } = useSymbol(tx.symbolToken, tx.isL1)
169-
170175
return (
171176
<TableRow key={tx.hash}>
172177
<TableCell>
@@ -184,17 +189,37 @@ const TxRow = props => {
184189
)}
185190
</Stack>
186191
</TableCell>
187-
<TableCell className="w-full">
192+
<TableCell>
193+
<Typography>
194+
<Link external href={generateContractLink(tx.fromExplore, tx.tokenAddress)} className="leading-normal flex-1">
195+
{truncateAddress(tx.tokenAddress)}
196+
</Link>
197+
</Typography>
198+
</TableCell>
199+
<TableCell>
188200
<Typography>
189-
<span>{tx.amount} </span>
190-
{symbolLoading ? <Skeleton variant="text" width="5rem" className="inline-block" /> : <span>{symbol}</span>}
201+
<Chip className={classes.chip} label={tx.tokenType}></Chip>
191202
</Typography>
192203
</TableCell>
204+
<TableCell>
205+
<Stack direction="column">
206+
{tx.tokenIds.map(item => (
207+
<Typography sx={{ fontSize: "1.2rem" }}>{item}</Typography>
208+
))}
209+
</Stack>
210+
</TableCell>
211+
<TableCell>
212+
<Stack direction="column">
213+
{tx.amounts.map(item => (
214+
<Typography sx={{ fontSize: "1.2rem" }}>{item}</Typography>
215+
))}
216+
</Stack>
217+
</TableCell>
193218
<TableCell>
194219
<Stack direction="column">
195220
<Typography>From {tx.fromName}: </Typography>
196221
<Stack direction="row" spacing="0.8rem" className="align-center">
197-
<Link external href={generateExploreLink(tx.fromExplore, tx.hash)} className="leading-normal flex-1">
222+
<Link external href={generateTxLink(tx.fromExplore, tx.hash)} className="leading-normal flex-1">
198223
{truncateHash(tx.hash)}
199224
</Link>
200225
</Stack>
@@ -204,7 +229,7 @@ const TxRow = props => {
204229
<Typography>To {tx.toName}: </Typography>
205230
<Stack direction="row" spacing="0.8rem" className="align-center">
206231
{tx.toHash ? (
207-
<Link external href={generateExploreLink(tx.toExplore, tx.toHash)} className="leading-normal flex-1">
232+
<Link external href={generateTxLink(tx.toExplore, tx.toHash)} className="leading-normal flex-1">
208233
{truncateHash(tx.toHash)}
209234
</Link>
210235
) : (

0 commit comments

Comments
 (0)