-
Notifications
You must be signed in to change notification settings - Fork 47
Description
Issue: When we hit the "Mint your NFT" button, the wallet pops up on the browser. When we hit "accept", the the minting process is initiated and the membership page is rendered once the NFT is minted. However, when we "reject" the transfer, it still takes us to the membership page.
It looks like under button onClick, we're executing the bundleDropModule where it sets the HasClaimedNFT state variable to True regardless of whether or an exception is thrown or caught. This is because we're using "finally".
One way to fix this problem is to add a "errorTx" flag and set it to true whenever there's an exception and set HasClaimedNFT state variable to True only if this flag is set to false.
`<button
disabled={isClaiming}
onClick={() => {
setIsClaiming(true);
// Call bundleDropModule.claim("0", 1) to mint nft to user's wallet.
let errorTx = false;
bundleDropModule
.claim("0", 1)
.catch((err) => {
console.error("failed to claim", err);
setIsClaiming(false);
**errorTx = true;**
})
.finally(() => {
// Stop loading state.
**if (!errorTx)** {
setIsClaiming(false);
// Set claim state.
setHasClaimedNFT(true);
// Show user their fancy new NFT!
console.log(
Successfully Minted! Check it our on OpenSea: https://testnets.opensea.io/assets/${bundleDropModule.address}/0
);
}
});
}}
>`