Skip to content

Commit

Permalink
omit gas price
Browse files Browse the repository at this point in the history
  • Loading branch information
0xjojoex committed Jul 10, 2023
1 parent 34e4bb4 commit cb7b35c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
4 changes: 2 additions & 2 deletions apps/web/src/hooks/useApproveCallback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,14 @@ export function useApproveCallback(

const estimatedGas = await tokenContract.estimateGas
.approve([spender as Address, MaxUint256], {
// account: tokenContract.account,
account: tokenContract.account,
})
.catch(() => {
// general fallback for tokens who restrict approval amounts
useExact = true
return tokenContract.estimateGas
.approve([spender as Address, amountToApprove?.quotient ?? targetAmount ?? MaxUint256], {
// account: tokenContract.account,
account: tokenContract.account,
})
.catch((e) => {
console.error('estimate gas failure', e)
Expand Down
28 changes: 16 additions & 12 deletions apps/web/src/hooks/useCallWithGasPrice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,26 +73,30 @@ export function useCallWithGasPrice() {
methodArgs?: Args extends never ? undefined : Args,
overrides?: Omit<CallParameters, 'chain' | 'to' | 'data'>,
): Promise<SendTransactionResult> => {
// const gas = await publicClient({ chainId }).estimateContractGas({
// abi: contract.abi,
// address: contract.address,
// // account: walletClient.account,
// functionName: methodName,
// args: methodArgs,
// gasPrice,
// value: 0n,
// ...overrides,
// } as unknown as EstimateContractGasParameters)
const { gas: gas_, ...overrides_ } = overrides || {}
let gas = gas_
if (!gas) {
gas = await publicClient({ chainId }).estimateContractGas({
abi: contract.abi,
address: contract.address,
account: walletClient.account,
functionName: methodName,
args: methodArgs,
value: 0n,
...overrides_,
} as unknown as EstimateContractGasParameters)
}

const res = await walletClient.writeContract({
abi: contract.abi,
address: contract.address,
account: walletClient.account,
functionName: methodName,
args: methodArgs,
gasPrice,
// gas: calculateGasMargin(gas),
gas: calculateGasMargin(gas),
value: 0n,
...overrides,
...overrides_,
} as unknown as WriteContractParameters)

const hash = res
Expand Down

0 comments on commit cb7b35c

Please sign in to comment.