Skip to content
This repository has been archived by the owner on Dec 21, 2023. It is now read-only.

Commit

Permalink
Fix/eip1559 (#2476)
Browse files Browse the repository at this point in the history
* fix: gas estimation

* fix: gas estimation

* fix: gas estimation

* fix
  • Loading branch information
intergalacticspacehighway committed Oct 31, 2023
1 parent 1c43252 commit ab1f00b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 33 deletions.
50 changes: 26 additions & 24 deletions packages/app/hooks/creator-token/use-creator-token-approve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
);
Expand Down
15 changes: 6 additions & 9 deletions packages/app/hooks/creator-token/use-creator-token-buy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -105,19 +102,19 @@ 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;
}

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) {
Expand Down

0 comments on commit ab1f00b

Please sign in to comment.