Skip to content

Commit 685b464

Browse files
committed
refactor(explorer): improve rail settlement transaction handling
1 parent 3de82ab commit 685b464

File tree

1 file changed

+18
-16
lines changed

1 file changed

+18
-16
lines changed

apps/explorer/src/hooks/useRailSettlements.tsx

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,12 @@ export const useRailSettlements = (options: UseRailSettlementsOptions) => {
3939
const { data: blockNumber } = useBlockNumber({ watch: true });
4040
const { writeContractAsync } = useWriteContract();
4141

42-
// Watch for any pending transaction
42+
// Watches for a pending transaction receipt.
43+
// Currently processes transactions sequentially: once a transaction
44+
// completes, it is removed from `pendingTxHashes` in `handleTransactionComplete`,
45+
// allowing the next pending transaction to be processed.
46+
// NOTE: This is a temporary approach and may need a more robust solution
47+
// for handling multiple concurrent pending transactions.
4348
const currentPendingTx = Array.from(pendingTxHashes)[0];
4449
const {
4550
data: receipt,
@@ -96,18 +101,16 @@ export const useRailSettlements = (options: UseRailSettlementsOptions) => {
96101
}
97102

98103
// Cleanup
99-
setTimeout(() => {
100-
setSettlements((prev) => {
101-
const next = new Map(prev);
102-
next.delete(settlement.railId);
103-
return next;
104-
});
105-
setPendingTxHashes((prev) => {
106-
const next = new Set(prev);
107-
next.delete(txHash);
108-
return next;
109-
});
110-
}, 3000);
104+
setSettlements((prev) => {
105+
const next = new Map(prev);
106+
next.delete(settlement.railId);
107+
return next;
108+
});
109+
setPendingTxHashes((prev) => {
110+
const next = new Set(prev);
111+
next.delete(txHash);
112+
return next;
113+
});
111114
},
112115
[explorerUrl, onSettlementSuccess, onSettlementError],
113116
);
@@ -185,12 +188,11 @@ export const useRailSettlements = (options: UseRailSettlementsOptions) => {
185188
});
186189

187190
// Get the settlement to access toastId
188-
const settlement = settlements.get(railIdStr);
191+
const settlement = settlementsRef.current.get(railIdStr);
189192

190193
// Dismiss the loading toast and show error
191194
toast.dismiss(settlement?.toastId);
192195
toast.error("Settlement Rejected", {
193-
id: settlement?.toastId,
194196
description: "Transaction was rejected. Please try again.",
195197
duration: 4000,
196198
});
@@ -205,7 +207,7 @@ export const useRailSettlements = (options: UseRailSettlementsOptions) => {
205207
throw err;
206208
}
207209
},
208-
[blockNumber, contractAddress, abi, writeContractAsync, settlements],
210+
[blockNumber, contractAddress, abi, writeContractAsync],
209211
);
210212

211213
const isSettling = useCallback(

0 commit comments

Comments
 (0)