Skip to content

Commit

Permalink
fix(useCollectNft): estimate gas manually
Browse files Browse the repository at this point in the history
  • Loading branch information
BrickheadJohnny committed Jan 29, 2025
1 parent a1a6645 commit fc4d694
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions src/components/[guild]/collect/hooks/useCollectNft.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ const useCollectNft = () => {
: BigInt(0)

let hash: `0x${string}` | undefined = undefined
let estimatedGas: bigint | undefined = undefined

if (isLegacyClaimArgs(claimData.args)) {
const [address, userId, , signature] = claimData.args
Expand All @@ -145,13 +144,12 @@ const useCollectNft = () => {
value: claimFee,
account: walletClient.account,
} as const
estimatedGas = await publicClient.estimateContractGas(args)
captureEvent("useCollectNFT:estimatedGas", {
estimatedGas,
})
const estimatedGas = await publicClient.estimateContractGas(args)

const { request: legacyClaimRequest } =
await publicClient.simulateContract(args)
const { request: legacyClaimRequest } = await publicClient.simulateContract({
...args,
gas: estimatedGas * BigInt(2),
})
hash = await walletClient.writeContract(legacyClaimRequest)
}

Expand All @@ -166,10 +164,10 @@ const useCollectNft = () => {
account: walletClient.account,
} as const

estimatedGas = await publicClient.estimateContractGas(args)
const { request: newClaimRequest } = await publicClient.simulateContract(args)
captureEvent("useCollectNFT:estimatedGas", {
estimatedGas,
const estimatedGas = await publicClient.estimateContractGas(args)
const { request: newClaimRequest } = await publicClient.simulateContract({
...args,
gas: estimatedGas * BigInt(2),
})

hash = await walletClient.writeContract(newClaimRequest)
Expand Down

0 comments on commit fc4d694

Please sign in to comment.