@@ -8,10 +8,7 @@ import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
88import { Separator } from '@/components/ui/separator' ;
99import { useCurrentSafeClient } from '@/providers/SafeProvider' ;
1010import { createPublicClient } from 'viem' ;
11- import { useWallet } from '@/hooks/useWallet' ;
12- import * as chains from 'viem/chains'
13- import { extractChain } from 'viem'
14- import { baseSepolia } from 'viem/chains' ;
11+ import { useChainId , usePublicClient } from 'wagmi' ;
1512
1613interface TransactionExecuteProps {
1714 transactionData : MetaTransactionData ;
@@ -26,73 +23,10 @@ export function TransactionExecute({ transactionData, onComplete, onBack }: Tran
2623 const [ signStatus , setSignStatus ] = useState < string > ( '' ) ;
2724 const [ executionStatus , setExecutionStatus ] = useState < string > ( '' ) ;
2825 const [ error , setError ] = useState < string > ( '' ) ;
29- const { chainId } = useWallet ( ) ;
26+ const publicClient = usePublicClient ( ) ;
3027
3128 const valueInEth = formatEther ( BigInt ( transactionData . value || '0' ) ) ;
3229
33- const fetchGasParams = async ( ) => {
34- try {
35- const ethProvider = ( globalThis as any ) . ethereum ;
36- if ( ! ethProvider ) return { } as any ;
37-
38- if ( ! chainId ) return { } as any ;
39- const chain = extractChain ( {
40- chains : Object . values ( chains ) ,
41- id : Number ( chainId ) as any ,
42- } ) ;
43- const publicClient = createPublicClient ( {
44- chain : chain ,
45- transport : http ( )
46- } )
47-
48- // Try EIP-1559 fees first
49- let maxFeePerGas : bigint | undefined ;
50- let maxPriorityFeePerGas : bigint | undefined ;
51- try {
52- const fees = await publicClient . estimateFeesPerGas ( ) ;
53- maxFeePerGas = fees . maxFeePerGas as bigint | undefined ;
54- maxPriorityFeePerGas = fees . maxPriorityFeePerGas as bigint | undefined ;
55- } catch { }
56-
57- // Fallback gasPrice (pre-1559 or if node doesn't support fee history)
58- let gasPrice : bigint | undefined ;
59- try {
60- gasPrice = await publicClient . getGasPrice ( ) ;
61- } catch { }
62-
63- // Estimate gas limit for this transaction shape
64- let from : `0x${string } ` | undefined ;
65- try {
66- const accounts : string [ ] = await ethProvider . request ( { method : 'eth_accounts' } ) ;
67- from = ( accounts ?. [ 0 ] as `0x${string } `) || undefined ;
68- } catch { }
69-
70- let gasLimit : bigint | undefined ;
71- try {
72- gasLimit = await publicClient . estimateGas ( {
73- account : from as any ,
74- to : transactionData . to as `0x${string } `,
75- data : transactionData . data as `0x${string } `,
76- value : ( transactionData . value ? BigInt ( transactionData . value ) : BigInt ( 0 ) ) as bigint ,
77- } ) ;
78- } catch { }
79-
80- return {
81- gasLimit : gasLimit ? gasLimit . toString ( ) : undefined ,
82- gasPrice : gasPrice ? gasPrice . toString ( ) : undefined ,
83- maxFeePerGas : maxFeePerGas ? maxFeePerGas . toString ( ) : undefined ,
84- maxPriorityFeePerGas : maxPriorityFeePerGas ? maxPriorityFeePerGas . toString ( ) : undefined ,
85- } as {
86- gasLimit ?: string ;
87- gasPrice ?: string ;
88- maxFeePerGas ?: string ;
89- maxPriorityFeePerGas ?: string ;
90- } ;
91- } catch {
92- return { } as any ;
93- }
94- } ;
95-
9630 const handleSign = async ( ) => {
9731 if ( ! safeClient ) {
9832 setError ( 'Safe client not available' ) ;
@@ -106,10 +40,10 @@ export function TransactionExecute({ transactionData, onComplete, onBack }: Tran
10640 try {
10741 const nonce = await safeClient . getNonce ( ) ;
10842
109- const publicClient = createPublicClient ( {
110- chain : baseSepolia ,
111- transport : http ( )
112- } )
43+ if ( ! publicClient ) {
44+ setError ( 'Public client not available' ) ;
45+ return ;
46+ }
11347
11448 const gasPrice = await publicClient . getGasPrice ( )
11549
0 commit comments