@@ -16,65 +16,50 @@ export const useBridgeTransaction = () => {
1616 const { setOngoingTransaction, removeOngoingTransaction } = useTariAccount ( )
1717
1818 /**
19- * Fetch user transactions and update the store's `in progress` transaction state.
20- * Returns the updated transaction or null if none.
19+ * Fetch user transactions and update the store's ongoing transaction state.
20+ * Returns the updated ongoing transaction or null if none.
2121 */
22- const getUserTransactions = async (
23- currentPendingTx ?: PendingUserTransaction ,
24- ) : Promise < PendingUserTransaction | null > => {
25- const ongoingBridgeTx = useTariAccount . getState ( ) . ongoingBridgeTx
26- const tariAccount = useTariAccount . getState ( ) . tariAccount
27- console . warn ( '[ TAPPLET-BRIDGE ] GET USER TX state' , ongoingBridgeTx )
28- console . warn ( '[ TAPPLET-BRIDGE ] GET USER arg func' , currentPendingTx )
22+ const getUserTransactions =
23+ async ( ) : Promise < PendingUserTransaction | null > => {
24+ const ongoingBridgeTx = useTariAccount . getState ( ) . ongoingBridgeTx
25+ const tariAccount = useTariAccount . getState ( ) . tariAccount
2926
30- if ( ! tariAccount ) return null
31- const walletAddress = tariAccount . address
32- const { transactions } = await getUserTxs . mutateAsync ( walletAddress )
33- console . error ( '[ TAPPLET-BRIDGE ] fetche backend tx' , transactions )
34- if ( Array . isArray ( transactions ) && transactions . length > 0 ) {
35- // Find a pending transaction
36- const ongoing = transactions . find (
37- ( tx ) =>
38- tx . status === UserTransactionDTO . status . PENDING ||
39- tx . status === UserTransactionDTO . status . PROCESSING ||
40- tx . status === UserTransactionDTO . status . TOKENS_RECEIVED ,
41- )
42- console . error (
43- '[ TAPPLET-BRIDGE ] same id? ' ,
44- ongoingBridgeTx ?. paymentId === ongoing ?. paymentId ,
45- )
27+ if ( ! tariAccount ) return null
28+ const walletAddress = tariAccount . address
29+ const { transactions } = await getUserTxs . mutateAsync ( walletAddress )
4630
47- if ( ongoing ) {
48- setOngoingTransaction ( ongoing )
49- return ongoing
50- }
51- console . error ( '[ TAPPLET-BRIDGE ] FOUND ONGOING ' , ongoing )
52- // If no pending tx found, but previously had one, check if it succeeded/failed
53- const ongoingCompleted = transactions . find (
54- ( tx ) =>
55- ( tx . status === UserTransactionDTO . status . SUCCESS ||
56- tx . status === UserTransactionDTO . status . TIMEOUT ) &&
57- tx . paymentId === ongoingBridgeTx ?. paymentId ,
58- )
31+ if ( Array . isArray ( transactions ) && transactions . length > 0 ) {
32+ // Find a pending transaction
33+ const ongoing = transactions . find (
34+ ( tx ) =>
35+ tx . status === UserTransactionDTO . status . PENDING ||
36+ tx . status === UserTransactionDTO . status . PROCESSING ||
37+ tx . status === UserTransactionDTO . status . TOKENS_RECEIVED ,
38+ )
39+ if ( ongoing ) {
40+ setOngoingTransaction ( ongoing )
41+ return ongoing
42+ }
43+
44+ // If no pending tx found, but previously had one, check if it succeeded/failed
45+ const ongoingCompleted = transactions . find (
46+ ( tx ) =>
47+ ( tx . status === UserTransactionDTO . status . SUCCESS ||
48+ tx . status === UserTransactionDTO . status . TIMEOUT ) &&
49+ tx . paymentId === ongoingBridgeTx ?. paymentId ,
50+ )
5951
60- console . error (
61- '[ TAPPLET-BRIDGE ] same ongoingCompleted id? ' ,
62- ongoingBridgeTx ?. paymentId === ongoingCompleted ?. paymentId ,
63- )
64- console . error ( '[ TAPPLET-BRIDGE ] FOUND COMPLETED ' , ongoingCompleted )
65- if ( ongoingCompleted ) {
66- console . error ( '[ TAPPLET-BRIDGE ] SET COMPLETED ' , ongoingCompleted )
67- setOngoingTransaction ( ongoingCompleted )
68- return ongoingCompleted
52+ if ( ongoingCompleted ) {
53+ setOngoingTransaction ( ongoingCompleted )
54+ return ongoingCompleted
55+ }
56+ } else {
57+ // No transactions found, clear any pending transaction
58+ removeOngoingTransaction ( )
6959 }
70- } else {
71- // No transactions found, clear any pending transaction
72- console . error ( '[ TAPPLET-BRIDGE ] REMOVE ONGOING' , ongoingBridgeTx )
73- removeOngoingTransaction ( )
74- }
7560
76- return null
77- }
61+ return null
62+ }
7863
7964 return {
8065 getUserTransactions,
0 commit comments