@@ -50,14 +50,8 @@ export const useZkSyncTransactionStatusStore = defineStore("zkSyncTransactionSta
50
50
)
51
51
) ;
52
52
53
- const getDepositL2TransactionHash = async ( l1TransactionHash : string ) => {
54
- const publicClient = onboardStore . getPublicClient ( ) ;
55
- const transaction = await retry ( ( ) =>
56
- publicClient . waitForTransactionReceipt ( {
57
- hash : l1TransactionHash as Hash ,
58
- } )
59
- ) ;
60
- for ( const log of transaction . logs ) {
53
+ const getDepositL2TransactionHash = ( l1Receipt : any ) => {
54
+ for ( const log of l1Receipt . logs ) {
61
55
try {
62
56
const { args, eventName } = decodeEventLog ( {
63
57
abi : IZkSyncHyperchain ,
@@ -74,12 +68,50 @@ export const useZkSyncTransactionStatusStore = defineStore("zkSyncTransactionSta
74
68
throw new Error ( "No L2 transaction hash found" ) ;
75
69
} ;
76
70
const getDepositStatus = async ( transaction : TransactionInfo ) => {
77
- const transactionHash = await getDepositL2TransactionHash ( transaction . transactionHash ) ;
78
- const transactionReceipt = await providerStore . requestProvider ( ) . getTransactionReceipt ( transactionHash ) ;
79
- if ( ! transactionReceipt ) return transaction ;
80
- transaction . info . toTransactionHash = transactionHash ;
81
- transaction . info . completed = true ;
82
- return transaction ;
71
+ try {
72
+ // Get L1 transaction receipt with retry logic for consistency
73
+ const publicClient = onboardStore . getPublicClient ( ) ;
74
+ const l1Receipt = await retry ( ( ) =>
75
+ publicClient . waitForTransactionReceipt ( {
76
+ hash : transaction . transactionHash as Hash ,
77
+ } )
78
+ ) ;
79
+
80
+ // Create a copy to avoid mutating the input parameter
81
+ const updatedTransaction = { ...transaction , info : { ...transaction . info } } ;
82
+
83
+ // If L1 transaction failed, mark the deposit as failed
84
+ if ( l1Receipt . status === "reverted" ) {
85
+ updatedTransaction . info . failed = true ;
86
+ updatedTransaction . info . completed = true ;
87
+ return updatedTransaction ;
88
+ }
89
+
90
+ // L1 transaction succeeded, extract L2 transaction hash from the same receipt
91
+ const l2TransactionHash = getDepositL2TransactionHash ( l1Receipt ) ;
92
+ const l2TransactionReceipt = await providerStore . requestProvider ( ) . getTransactionReceipt ( l2TransactionHash ) ;
93
+ if ( ! l2TransactionReceipt ) return updatedTransaction ;
94
+
95
+ updatedTransaction . info . toTransactionHash = l2TransactionHash ;
96
+ updatedTransaction . info . completed = true ;
97
+ return updatedTransaction ;
98
+ } catch ( err ) {
99
+ // Only mark as failed for specific transaction-related errors
100
+ // Network/RPC errors should be re-thrown to allow retry at higher level
101
+ const error = err as Error ;
102
+ if (
103
+ error . message . includes ( "transaction" ) ||
104
+ error . message . includes ( "reverted" ) ||
105
+ error . message . includes ( "failed" )
106
+ ) {
107
+ const updatedTransaction = { ...transaction , info : { ...transaction . info } } ;
108
+ updatedTransaction . info . failed = true ;
109
+ updatedTransaction . info . completed = true ;
110
+ return updatedTransaction ;
111
+ }
112
+ // Re-throw network/infrastructure errors for retry at higher level
113
+ throw err ;
114
+ }
83
115
} ;
84
116
const getWithdrawalStatus = async ( transaction : TransactionInfo ) => {
85
117
if ( ! transaction . info . withdrawalFinalizationAvailable ) {
0 commit comments