@@ -13,12 +13,12 @@ import { Network } from '@/components/network-box'
1313import useTariAccount from '@/store/account'
1414import { useBridgeToEthereumFees } from '@/hooks/use-bridge-to-ethereum-fees'
1515import { useBridgeTransaction } from '@/hooks/use-bridge-transaction'
16+ import { UserTransactionDTO } from '@tari-project/wxtm-bridge-backend-api'
1617
1718export default function Home ( ) {
1819 const { isConnected, address : ethAddress } = useAccount ( )
1920 const [ modalOpen , setModalOpen ] = useState ( false )
2021 const [ modalStep , setModalStep ] = useState < number > ( 1 )
21- const [ success ] = useState ( false )
2222 const [ fromNetwork , setFromNetwork ] = useState < Network > ( {
2323 name : 'Tari' ,
2424 icon : '/icons/tari.png' ,
@@ -28,10 +28,8 @@ export default function Home() {
2828 icon : '/icons/eth.png' ,
2929 } )
3030
31- const { bridgeToEthereum, isBridging, getBridgeTxParams } =
32- useBridgeToEthereum ( )
33- const { tariAccount, isProcessingTransaction, pendingBridgeTx } =
34- useTariAccount ( )
31+ const { bridgeToEthereum, getBridgeTxParams } = useBridgeToEthereum ( )
32+ const { tariAccount, isOngoingBridgeTx, ongoingBridgeTx } = useTariAccount ( )
3533 const { getUserTransactions } = useBridgeTransaction ( )
3634
3735 const {
@@ -47,35 +45,58 @@ export default function Home() {
4745 const amount = watch ( 'amount' )
4846 const feesData = useBridgeToEthereumFees ( amount )
4947
48+ // Fetch bridge transaction parameters once on mount or when tariAccount changes
5049 useEffect ( ( ) => {
51- if ( tariAccount ) {
52- const fetchUserTransactions = async ( ) => {
53- try {
54- await getUserTransactions ( tariAccount . address , pendingBridgeTx )
55- await getBridgeTxParams ( )
56- } catch ( error ) {
57- console . error (
58- '[ TAPPLET-BRIDGE ] Failed to get user transactions:' ,
59- error ,
60- )
61- }
50+ if ( ! tariAccount ) return
51+
52+ const fetchBridgeTxParams = async ( ) => {
53+ try {
54+ await getBridgeTxParams ( )
55+ } catch ( error ) {
56+ console . error (
57+ '[ TAPPLET-BRIDGE ] Failed to get bridge transaction params:' ,
58+ error ,
59+ )
6260 }
61+ }
62+
63+ fetchBridgeTxParams ( )
64+ // eslint-disable-next-line react-hooks/exhaustive-deps
65+ } , [ tariAccount ] )
66+
67+ useEffect ( ( ) => {
68+ if ( ! tariAccount ) return
69+
70+ const fetchUserTransactions = async ( ) => {
71+ try {
72+ await getUserTransactions ( )
73+ } catch ( error ) {
74+ console . error (
75+ '[ TAPPLET-BRIDGE ] Failed to get user transactions:' ,
76+ error ,
77+ )
78+ }
79+ }
80+
81+ fetchUserTransactions ( )
82+ // Poll every 1 min
83+ const intervalId = setInterval ( fetchUserTransactions , 60000 )
6384
64- fetchUserTransactions ( )
85+ return ( ) => {
86+ clearInterval ( intervalId )
6587 }
6688 // eslint-disable-next-line react-hooks/exhaustive-deps
6789 } , [ tariAccount ] )
6890
69- // Auto-close modal when connected and on connect step
7091 useEffect ( ( ) => {
7192 if ( modalOpen && modalStep === 0 && isConnected ) {
7293 setModalOpen ( false )
7394 setModalStep ( 1 )
74- } else if ( isProcessingTransaction ) {
95+ } else if ( isOngoingBridgeTx && ongoingBridgeTx ) {
7596 setModalStep ( 2 )
7697 setModalOpen ( true )
7798 }
78- } , [ isConnected , modalOpen , modalStep , isProcessingTransaction ] )
99+ } , [ isConnected , modalOpen , modalStep , isOngoingBridgeTx , ongoingBridgeTx ] )
79100
80101 const handleConnectClick = ( ) => {
81102 if ( ! isConnected ) {
@@ -96,16 +117,15 @@ export default function Home() {
96117
97118 bridgeToEthereum ( {
98119 amount,
99- amountAfterFee : feesData . amountAfterFee ,
100120 ethAddress : ethAddress ,
101121 } )
102122 . then ( ( ) => {
103- setModalStep ( 2 )
123+ getUserTransactions ( )
104124 } )
105125 . catch ( ( error ) => {
106126 console . error ( '[ TAPPLET-BRIDGE ] Bridge operation failed:' , error )
107127 } )
108- } , [ amount , ethAddress , bridgeToEthereum , feesData ] )
128+ } , [ amount , ethAddress , bridgeToEthereum , getUserTransactions ] )
109129
110130 const handleBridgeToTari = ( ) => {
111131 setModalStep ( 2 )
@@ -125,17 +145,20 @@ export default function Home() {
125145 setFromNetwork = { setFromNetwork }
126146 toNetwork = { toNetwork }
127147 setToNetwork = { setToNetwork }
128- isProcessingTransaction = { isProcessingTransaction || isBridging }
148+ isOngoingBridgeTx = { isOngoingBridgeTx }
129149 />
130150 { modalOpen && (
131151 < MainModal
132152 setModalOpen = { setModalOpen }
133- success = { success }
153+ success = {
154+ ongoingBridgeTx ?. status === UserTransactionDTO . status . SUCCESS
155+ }
156+ failed = { ongoingBridgeTx ?. status === UserTransactionDTO . status . TIMEOUT }
134157 step = { modalStep }
135158 setStep = { setModalStep }
136159 handleBridgeToEthereum = { handleBridgeToEthereum }
137160 handleBridgeToTari = { handleBridgeToTari }
138- isBridging = { isBridging }
161+ isBridging = { isOngoingBridgeTx }
139162 amount = { amount }
140163 ethereumAddress = { ethAddress }
141164 tariWalletAddress = { tariAccount ?. address }
0 commit comments