11'use client' ;
22
33import React , { useState } from 'react' ;
4- import { formatEther } from 'viem' ;
4+ import { formatEther , http } from 'viem' ;
55import { MetaTransactionData } from '@safe-global/types-kit' ;
66import { Button } from '@/components/ui/button' ;
77import { Card , CardContent , CardHeader , CardTitle } from '@/components/ui/card' ;
88import { Separator } from '@/components/ui/separator' ;
9- import { useCurrentSafeClient } from '@/providers/SafeProvider' ;
9+ import { useCurrentChain , useCurrentSafeClient } from '@/providers/SafeProvider' ;
1010import { createPublicClient , custom } 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' ;
1115
1216interface TransactionExecuteProps {
1317 transactionData : MetaTransactionData ;
@@ -22,6 +26,7 @@ export function TransactionExecute({ transactionData, onComplete, onBack }: Tran
2226 const [ signStatus , setSignStatus ] = useState < string > ( '' ) ;
2327 const [ executionStatus , setExecutionStatus ] = useState < string > ( '' ) ;
2428 const [ error , setError ] = useState < string > ( '' ) ;
29+ const { chainId } = useWallet ( ) ;
2530
2631 const valueInEth = formatEther ( BigInt ( transactionData . value || '0' ) ) ;
2732
@@ -30,7 +35,15 @@ export function TransactionExecute({ transactionData, onComplete, onBack }: Tran
3035 const ethProvider = ( globalThis as any ) . ethereum ;
3136 if ( ! ethProvider ) return { } as any ;
3237
33- const publicClient = createPublicClient ( { transport : custom ( ethProvider ) as any } as any ) ;
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+ } )
3447
3548 // Try EIP-1559 fees first
3649 let maxFeePerGas : bigint | undefined ;
@@ -92,18 +105,18 @@ export function TransactionExecute({ transactionData, onComplete, onBack }: Tran
92105
93106 try {
94107 const nonce = await safeClient . getNonce ( ) ;
95- const gasParams = await fetchGasParams ( ) ;
108+
109+ const publicClient = createPublicClient ( {
110+ chain : baseSepolia ,
111+ transport : http ( )
112+ } )
113+
114+ const gasPrice = await publicClient . getGasPrice ( )
96115
97116 const txResult = await safeClient . send ( {
98117 transactions : [ transactionData ] ,
99118 nonce,
100- // Only pass one pricing model if available
101- ...( gasParams . maxFeePerGas && gasParams . maxPriorityFeePerGas
102- ? { maxFeePerGas : gasParams . maxFeePerGas , maxPriorityFeePerGas : gasParams . maxPriorityFeePerGas }
103- : gasParams . gasPrice
104- ? { gasPrice : gasParams . gasPrice }
105- : { } ) ,
106- ...( gasParams . gasLimit ? { gasLimit : gasParams . gasLimit } : { } ) ,
119+ gasPrice : gasPrice ,
107120 } ) ;
108121
109122 setSignStatus ( 'Transaction signed successfully!' ) ;
@@ -128,16 +141,8 @@ export function TransactionExecute({ transactionData, onComplete, onBack }: Tran
128141 setExecutionStatus ( 'Executing transaction...' ) ;
129142
130143 try {
131- const gasParams = await fetchGasParams ( ) ;
132-
133144 const txResult = await safeClient . send ( {
134145 transactions : [ transactionData ] ,
135- ...( gasParams . maxFeePerGas && gasParams . maxPriorityFeePerGas
136- ? { maxFeePerGas : gasParams . maxFeePerGas , maxPriorityFeePerGas : gasParams . maxPriorityFeePerGas }
137- : gasParams . gasPrice
138- ? { gasPrice : gasParams . gasPrice }
139- : { } ) ,
140- ...( gasParams . gasLimit ? { gasLimit : gasParams . gasLimit } : { } ) ,
141146 } ) ;
142147 const safeTxHash = txResult . transactions ?. safeTxHash ;
143148
0 commit comments