Skip to content

Commit e4f986c

Browse files
committed
fix: catch error
1 parent 7d8a9ca commit e4f986c

File tree

3 files changed

+37
-29
lines changed

3 files changed

+37
-29
lines changed

src/pages/bridge/Send/index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,8 @@ const Send: FC = () => {
218218
}
219219
}, [fromNetwork, fromToken, fromTokenAmount, checkApproval])
220220

221+
console.log(needsApproval, "needsApproval")
222+
221223
const approveFromToken = async () => {
222224
// eslint-disable-next-line
223225
const parsedAmount = amountToBN(fromTokenAmount, fromToken.decimals)

src/pages/nftBridge/NFTPanel/Transfer/Send.tsx

Lines changed: 34 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ const Send = () => {
3939

4040
const [txHash, setTxHash] = useState("")
4141

42+
// TODO: how to call this after approve
4243
const needApproval = useAsyncMemo(async () => {
4344
if (tokenInstance) {
4445
const isApproved = await checkApproval(tokenInstance, gatewayAddress)
@@ -74,35 +75,40 @@ const Send = () => {
7475
const handleSend = async () => {
7576
setSendLoading(true)
7677
setSendModalLoading(true)
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,
89-
})
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-
})
99-
.catch(error => {
100-
updatePromptMessage(error.message)
101-
})
102-
.finally(() => {
103-
setSendLoading(false)
104-
setSendModalLoading(false)
78+
try {
79+
const tx = isLayer1 ? await deposite() : await withdraw()
80+
addNFTTransaction({
81+
hash: tx.hash,
82+
fromName: fromNetwork.name,
83+
toName: toNetwork.name,
84+
fromExplore: fromNetwork.explorer,
85+
toExplore: toNetwork.explorer,
86+
tokenType: contract.type,
87+
tokenAddress: isLayer1 ? contract.l1 : contract.l2,
88+
amounts: selectedList.map(item => item.transferAmount),
89+
tokenIds: selectedTokenIds,
90+
isL1: isLayer1,
10591
})
92+
93+
tx.wait()
94+
.then(receipt => {
95+
updateNFTTransaction(tx.hash, {
96+
fromBlockNumber: receipt.blockNumber,
97+
})
98+
setTxHash(receipt.transactionHash)
99+
exciseSelected()
100+
})
101+
.catch(error => {
102+
updatePromptMessage(error.message)
103+
})
104+
.finally(() => {
105+
setSendLoading(false)
106+
setSendModalLoading(false)
107+
})
108+
} catch (e) {
109+
setSendLoading(false)
110+
setSendModalLoading(false)
111+
}
106112
}
107113

108114
const deposite = () => {

src/pages/nftBridge/NFTPanel/Viewing/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ const Viewing = props => {
9090
if (exists) {
9191
uri = await tokenInstance["uri(uint256)"](currentTokenId)
9292
amount = await tokenInstance["balanceOf(address,uint256)"](walletCurrentAddress, currentTokenId)
93-
amount = (amount as any).toNumber()
93+
amount = Number(amount)
9494
} else {
9595
throw new Error("Token does not exist!")
9696
}

0 commit comments

Comments
 (0)