Skip to content

Commit 5399a8b

Browse files
committed
fix: prepare claim transactions with gas estimate
1 parent 9e0c398 commit 5399a8b

1 file changed

Lines changed: 22 additions & 2 deletions

File tree

app/migration/ClaimClient.jsx

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,14 @@ function formatTokenAmount(rawValue) {
6767
}
6868

6969
function getErrorMessage(error) {
70+
let current = error;
71+
while (current) {
72+
if (current.code === -32002 || current.name === "ResourceUnavailableRpcError") {
73+
return "Your wallet could not create the transaction. Refresh and try again, or use another wallet/browser on Ethereum mainnet.";
74+
}
75+
current = current.cause;
76+
}
77+
7078
return error?.shortMessage || error?.message || "Something went wrong. Please try again.";
7179
}
7280

@@ -187,15 +195,27 @@ export default function ClaimClient() {
187195
}
188196

189197
setClaimState("claiming");
190-
setClaimMessage("Confirm the transaction in your wallet...");
198+
setClaimMessage("Preparing the claim transaction...");
191199

192200
try {
201+
const claimArgs = [BigInt(entry.amount), entry.proof || []];
202+
const estimatedGas = await publicClient.estimateContractGas({
203+
account: address,
204+
address: contractAddress,
205+
abi: AIRDROP_ABI,
206+
functionName: "claim",
207+
args: claimArgs,
208+
});
209+
210+
setClaimMessage("Confirm the transaction in your wallet...");
193211
const hash = await writeContractAsync({
212+
account: address,
194213
address: contractAddress,
195214
abi: AIRDROP_ABI,
196215
functionName: "claim",
197-
args: [BigInt(entry.amount), entry.proof || []],
216+
args: claimArgs,
198217
chainId: requiredChainId,
218+
gas: estimatedGas + estimatedGas / 5n,
199219
});
200220

201221
setClaimMessage("Transaction submitted. Waiting for confirmation...");

0 commit comments

Comments
 (0)