Skip to content

Commit

Permalink
fix(faucet): check status of transaction before showing success
Browse files Browse the repository at this point in the history
  • Loading branch information
grezle committed Jul 18, 2023
1 parent 8a906c4 commit b134414
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions apps/faucet/src/components/MintTokens.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,7 @@ function MintTokens() {
abi: ABI,
functionName: "mint",
async onSettled(data, err) {
// wait for full resolve
await data?.wait();

// check for error first...
if (err) {
setError(
err.toString().toLowerCase().indexOf("user rejected") !== -1
Expand All @@ -72,13 +70,21 @@ function MintTokens() {
return false;
}

setAmount(undefined);
setSuccess(
`Success! We minted ${amount} MNT and sent ${
(amount || 0) === 1 ? "it" : "them"
} to ${truncateAddress(address as `0x${string}`)}`
);
return true;
// wait for full resolve
const receipt = await data?.wait();

// check that the transaction actually succeeded
if (parseInt(receipt?.status?.toString() || "0x0", 16) === 1) {
setAmount(undefined);
setSuccess(
`Success! We minted ${amount} MNT and sent ${
(amount || 0) === 1 ? "it" : "them"
} to ${truncateAddress(address as `0x${string}`)}`
);
return true;
}
setError("Transaction failed - did the transaction run out of gas?");
return false;
},
});

Expand Down

1 comment on commit b134414

@vercel
Copy link

@vercel vercel bot commented on b134414 Jul 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.