Skip to content

Commit 9244f11

Browse files
authored
Merge pull request #16 from nftlabs/am/fixes
Fix error parsing and tab redirect
2 parents f4b1fd2 + 887bb00 commit 9244f11

File tree

4 files changed

+52
-46
lines changed

4 files changed

+52
-46
lines changed

parcel-build.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@
2020
</head>
2121
<body>
2222
<div id="root"></div>
23-
<script type="module" src="./src/widgets/drop.tsx"></script>
23+
<script type="module" src="./src/widgets/bundledrop.tsx"></script>
2424
</body>
2525
</html>

src/shared/parseError.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
export const parseError = (err: any) => {
2+
// Explicity error recognition
3+
if (err.code === "INSUFFICIENT_FUNDS") {
4+
return "Insufficient funds to mint";
5+
} else if (err.code === "UNPREDICTABLE_GAS_LIMIT") {
6+
if (err.message.includes("exceed max mint supply")) {
7+
return "Your transaction failed because you attempted to mint more tokens than the maximum allowed mint supply";
8+
}
9+
} else if (err.message.includes("User denied transaction signature")) {
10+
return "You denied the transaction";
11+
}
12+
13+
if (err.data.message.includes("execution reverted:")) {
14+
return err.data.message.replace("execution reverted:", "")
15+
}
16+
17+
if (err.data.message) {
18+
return err.data.message;
19+
}
20+
21+
return undefined;
22+
}

src/widgets/bundledrop.tsx

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ import { useFormatedValue } from "../shared/tokenHooks";
4343
import { useAddress } from "../shared/useAddress";
4444
import { useConnectors } from "../shared/useConnectors";
4545
import { useSDKWithSigner } from "../shared/useSdkWithSigner";
46+
import { parseError } from "../shared/parseError";
4647

4748
function parseHugeNumber(totalAvailable: BigNumberish = 0) {
4849
const bn = BigNumber.from(totalAvailable);
@@ -226,26 +227,19 @@ const ClaimButton: React.FC<ClaimPageProps> = ({
226227
return module.claim(tokenId, quantity);
227228
},
228229
{
229-
onSuccess: () => queryClient.invalidateQueries("numbers"),
230+
onSuccess: () => {
231+
queryClient.invalidateQueries();
232+
toast({
233+
title: "Successfuly claimed.",
234+
status: "success",
235+
duration: 5000,
236+
isClosable: true,
237+
});
238+
},
230239
onError: (err) => {
231-
const anyErr = err as any;
232-
let message = "";
233-
234-
if (anyErr.code === "INSUFFICIENT_FUNDS") {
235-
message = "Insufficient funds to mint";
236-
} else if (anyErr.code === "UNPREDICTABLE_GAS_LIMIT") {
237-
if (anyErr.message.includes("exceed max mint supply")) {
238-
message = "You are not eligible to mint right now";
239-
}
240-
} else if (anyErr.message.includes("User denied transaction signature")) {
241-
message = "You denied the transaction";
242-
} else {
243-
message = "You may be ineligible to claim this drop"
244-
}
245-
246240
toast({
247241
title: "Minting failed",
248-
description: message,
242+
description: parseError(err),
249243
status: "error",
250244
duration: 9000,
251245
isClosable: true,
@@ -516,14 +510,12 @@ const DropWidget: React.FC<DropWidgetProps> = ({
516510

517511
const isNotSoldOut = parseInt(claimed) < parseInt(totalAvailable);
518512

519-
const onlyOnce = useRef(true);
520-
513+
const numOwned = BigNumber.from(owned.data || 0).toNumber();
521514
useEffect(() => {
522-
if (owned.data?.gt(0) && !isNotSoldOut && onlyOnce.current) {
523-
onlyOnce.current = false;
515+
if (owned.data?.gt(0) && isNotSoldOut) {
524516
setActiveTab("inventory");
525517
}
526-
}, [owned.data, isNotSoldOut]);
518+
}, [numOwned, isNotSoldOut]);
527519

528520
return (
529521
<Flex

src/widgets/drop.tsx

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ import { useFormatedValue } from "../shared/tokenHooks";
4343
import { useAddress } from "../shared/useAddress";
4444
import { useConnectors } from "../shared/useConnectors";
4545
import { useSDKWithSigner } from "../shared/useSdkWithSigner";
46+
import { parseError } from "src/shared/parseError";
4647

4748
interface DropWidgetProps {
4849
startingTab?: "claim" | "inventory";
@@ -223,26 +224,19 @@ const ClaimButton: React.FC<ClaimPageProps> = ({
223224
return module.claim(quantity);
224225
},
225226
{
226-
onSuccess: () => queryClient.invalidateQueries(),
227+
onSuccess: () => {
228+
queryClient.invalidateQueries()
229+
toast({
230+
title: "Successfuly claimed.",
231+
status: "success",
232+
duration: 5000,
233+
isClosable: true,
234+
});
235+
},
227236
onError: (err) => {
228-
const anyErr = err as any;
229-
let message = "";
230-
231-
if (anyErr.code === "INSUFFICIENT_FUNDS") {
232-
message = "Insufficient funds to mint";
233-
} else if (anyErr.code === "UNPREDICTABLE_GAS_LIMIT") {
234-
if (anyErr.message.includes("exceed max mint supply")) {
235-
message = "You are not eligible to mint right now";
236-
}
237-
} else if (anyErr.message.includes("User denied transaction signature")) {
238-
message = "You denied the transaction";
239-
} else {
240-
message = "You may be ineligible to claim this drop"
241-
}
242-
243237
toast({
244238
title: "Failed to claim drop.",
245-
description: message,
239+
description: parseError(err),
246240
status: "error",
247241
duration: 9000,
248242
isClosable: true,
@@ -492,16 +486,14 @@ const DropWidget: React.FC<DropWidgetProps> = ({
492486
{ enabled: !!dropModule },
493487
);
494488

495-
const isSoldOut = totalAvailable.data?.gte(available.data || 0);
496-
497-
const onlyOnce = useRef(true);
489+
const isNotSoldOut = totalAvailable.data?.gte(available.data || 0);
498490

491+
const numOwned = BigNumber.from(owned.data || 0).toNumber();
499492
useEffect(() => {
500-
if (owned.data?.gt(0) && isSoldOut && onlyOnce.current) {
501-
onlyOnce.current = false;
493+
if (owned.data?.gt(0) && isNotSoldOut) {
502494
setActiveTab("inventory");
503495
}
504-
}, [owned.data, isSoldOut]);
496+
}, [numOwned, isNotSoldOut]);
505497

506498
return (
507499
<Flex

0 commit comments

Comments
 (0)