1- import { env } from "@/config/env" ;
2- import { ContractManager } from " @/services/ContractManager" ;
3- import { useEffect , useRef , useState } from " react" ;
1+
2+ import { ContractManager } from ' @/services/ContractManager' ;
3+ import { useEffect , useRef , useState } from ' react' ;
44
55interface UseTxConfirmationsProps {
66 isActive : boolean ;
7- maxConfirmations ?: number ;
87 transactionHash ?: string ;
98}
109
1110export function useTxConfirmations ( {
1211 isActive,
13- maxConfirmations = env . VITE_EVM_CONFIRMATIONS ,
1412 transactionHash,
1513} : UseTxConfirmationsProps ) {
1614 const [ confirmations , setConfirmations ] = useState ( 0 ) ;
@@ -29,20 +27,15 @@ export function useTxConfirmations({
2927 const checkConfirmations = async ( ) => {
3028 try {
3129 const contractManager = await ContractManager . getInstance ( ) ;
32- const receipt = await contractManager . publicClient . getTransactionReceipt ( {
33- hash : transactionHash as `0x${string } `,
34- } ) ;
30+ const receipt =
31+ await contractManager . publicClient . getTransactionReceipt ( {
32+ hash : transactionHash as `0x${string } `,
33+ } ) ;
3534 if ( receipt ) {
36- const currentBlock = await contractManager . publicClient . getBlockNumber ( ) ;
35+ const currentBlock =
36+ await contractManager . publicClient . getBlockNumber ( ) ;
3737 const confirmations = Number ( currentBlock - receipt . blockNumber ) ;
38- setConfirmations ( Math . min ( confirmations , maxConfirmations ) ) ;
39-
40- if ( confirmations >= maxConfirmations ) {
41- if ( intervalRef . current ) {
42- clearInterval ( intervalRef . current ) ;
43- intervalRef . current = null ;
44- }
45- }
38+ setConfirmations ( confirmations ) ;
4639 }
4740 } catch ( error ) {
4841 console . error ( 'Error checking confirmations:' , error ) ;
@@ -59,7 +52,7 @@ export function useTxConfirmations({
5952 intervalRef . current = null ;
6053 }
6154 } ;
62- } , [ isActive , transactionHash , maxConfirmations ] ) ;
55+ } , [ isActive , transactionHash ] ) ;
6356
6457 return confirmations ;
65- }
58+ }
0 commit comments