From ab1f00b304daa7891b34f0762770fe705c1548e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?nishan=20=28o=5E=E2=96=BD=5Eo=29?= Date: Tue, 31 Oct 2023 10:08:04 +0530 Subject: [PATCH] Fix/eip1559 (#2476) * fix: gas estimation * fix: gas estimation * fix: gas estimation * fix --- .../use-creator-token-approve.ts | 50 ++++++++++--------- .../creator-token/use-creator-token-buy.ts | 15 +++--- 2 files changed, 32 insertions(+), 33 deletions(-) diff --git a/packages/app/hooks/creator-token/use-creator-token-approve.ts b/packages/app/hooks/creator-token/use-creator-token-approve.ts index 12ed51d07..ee8e1ec1e 100644 --- a/packages/app/hooks/creator-token/use-creator-token-approve.ts +++ b/packages/app/hooks/creator-token/use-creator-token-approve.ts @@ -50,34 +50,36 @@ export const useApproveToken = () => { maxFeePerGas, maxPriorityFeePerGas, }); - if (maxFeePerGas) { - const { request } = await publicClient.simulateContract({ - address: usdcAddress, - account: walletAddress, - abi: erc20Abi, - functionName: "approve", - args: [creatorTokenContract, maxPrice], - chain: chain, - maxFeePerGas, - maxPriorityFeePerGas, - }); + const { request } = await publicClient.simulateContract({ + address: usdcAddress, + account: walletAddress, + abi: erc20Abi, + functionName: "approve", + args: [creatorTokenContract, maxPrice], + chain: chain, + }); - const hash = await walletClient?.writeContract(request); - console.log("approve transaction hash ", hash); - if (hash) { - const transaction = await publicClient.waitForTransactionReceipt({ - hash, - pollingInterval: 2000, - confirmations: 3, - }); - if (transaction.status === "success") { - return true; - } + //@ts-ignore + const hash = await walletClient?.writeContract({ + ...request, + type: "eip1559", + maxFeePerGas, + maxPriorityFeePerGas, + }); + console.log("approve transaction hash ", hash); + if (hash) { + const transaction = await publicClient.waitForTransactionReceipt({ + hash, + pollingInterval: 2000, + confirmations: 3, + }); + if (transaction.status === "success") { + return true; } } - } else { - return true; } + } else { + return true; } } ); diff --git a/packages/app/hooks/creator-token/use-creator-token-buy.ts b/packages/app/hooks/creator-token/use-creator-token-buy.ts index c9e13306c..21a5e4b6c 100644 --- a/packages/app/hooks/creator-token/use-creator-token-buy.ts +++ b/packages/app/hooks/creator-token/use-creator-token-buy.ts @@ -91,9 +91,6 @@ export const useCreatorTokenBuy = (params: { functionName: "buy", args: [priceToBuyNext.data?.totalPrice], chain: baseChain, - type: "eip1559", - maxFeePerGas, - maxPriorityFeePerGas, }); requestPayload = request; console.log("token amount 1 simulation ", request); @@ -105,9 +102,6 @@ export const useCreatorTokenBuy = (params: { functionName: "bulkBuy", args: [tokenAmount, priceToBuyNext.data?.totalPrice], chain: baseChain, - type: "eip1559", - maxFeePerGas, - maxPriorityFeePerGas, }); console.log("bulk buy request", request); requestPayload = request; @@ -115,9 +109,12 @@ export const useCreatorTokenBuy = (params: { console.log("simulate ", requestPayload); - const transactionHash = await walletClient?.writeContract?.( - requestPayload - ); + const transactionHash = await walletClient?.writeContract?.({ + ...requestPayload, + type: "eip1559", + maxFeePerGas, + maxPriorityFeePerGas, + }); console.log("Buy transaction hash ", requestPayload); if (transactionHash) {