Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion parcel-build.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@
</head>
<body>
<div id="root"></div>
<script type="module" src="./src/widgets/drop.tsx"></script>
<script type="module" src="./src/widgets/bundledrop.tsx"></script>
</body>
</html>
22 changes: 22 additions & 0 deletions src/shared/parseError.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
export const parseError = (err: any) => {
// Explicity error recognition
if (err.code === "INSUFFICIENT_FUNDS") {
return "Insufficient funds to mint";
} else if (err.code === "UNPREDICTABLE_GAS_LIMIT") {
if (err.message.includes("exceed max mint supply")) {
return "Your transaction failed because you attempted to mint more tokens than the maximum allowed mint supply";
}
} else if (err.message.includes("User denied transaction signature")) {
return "You denied the transaction";
}

if (err.data.message.includes("execution reverted:")) {
return err.data.message.replace("execution reverted:", "")
}

if (err.data.message) {
return err.data.message;
}

return undefined;
}
36 changes: 14 additions & 22 deletions src/widgets/bundledrop.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import { useFormatedValue } from "../shared/tokenHooks";
import { useAddress } from "../shared/useAddress";
import { useConnectors } from "../shared/useConnectors";
import { useSDKWithSigner } from "../shared/useSdkWithSigner";
import { parseError } from "../shared/parseError";

function parseHugeNumber(totalAvailable: BigNumberish = 0) {
const bn = BigNumber.from(totalAvailable);
Expand Down Expand Up @@ -226,26 +227,19 @@ const ClaimButton: React.FC<ClaimPageProps> = ({
return module.claim(tokenId, quantity);
},
{
onSuccess: () => queryClient.invalidateQueries("numbers"),
onSuccess: () => {
queryClient.invalidateQueries();
toast({
title: "Successfuly claimed.",
status: "success",
duration: 5000,
isClosable: true,
});
},
onError: (err) => {
const anyErr = err as any;
let message = "";

if (anyErr.code === "INSUFFICIENT_FUNDS") {
message = "Insufficient funds to mint";
} else if (anyErr.code === "UNPREDICTABLE_GAS_LIMIT") {
if (anyErr.message.includes("exceed max mint supply")) {
message = "You are not eligible to mint right now";
}
} else if (anyErr.message.includes("User denied transaction signature")) {
message = "You denied the transaction";
} else {
message = "You may be ineligible to claim this drop"
}

toast({
title: "Minting failed",
description: message,
description: parseError(err),
status: "error",
duration: 9000,
isClosable: true,
Expand Down Expand Up @@ -516,14 +510,12 @@ const DropWidget: React.FC<DropWidgetProps> = ({

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

const onlyOnce = useRef(true);

const numOwned = BigNumber.from(owned.data || 0).toNumber();
useEffect(() => {
if (owned.data?.gt(0) && !isNotSoldOut && onlyOnce.current) {
onlyOnce.current = false;
if (owned.data?.gt(0) && isNotSoldOut) {
setActiveTab("inventory");
}
}, [owned.data, isNotSoldOut]);
}, [numOwned, isNotSoldOut]);

return (
<Flex
Expand Down
38 changes: 15 additions & 23 deletions src/widgets/drop.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import { useFormatedValue } from "../shared/tokenHooks";
import { useAddress } from "../shared/useAddress";
import { useConnectors } from "../shared/useConnectors";
import { useSDKWithSigner } from "../shared/useSdkWithSigner";
import { parseError } from "src/shared/parseError";

interface DropWidgetProps {
startingTab?: "claim" | "inventory";
Expand Down Expand Up @@ -223,26 +224,19 @@ const ClaimButton: React.FC<ClaimPageProps> = ({
return module.claim(quantity);
},
{
onSuccess: () => queryClient.invalidateQueries(),
onSuccess: () => {
queryClient.invalidateQueries()
toast({
title: "Successfuly claimed.",
status: "success",
duration: 5000,
isClosable: true,
});
},
onError: (err) => {
const anyErr = err as any;
let message = "";

if (anyErr.code === "INSUFFICIENT_FUNDS") {
message = "Insufficient funds to mint";
} else if (anyErr.code === "UNPREDICTABLE_GAS_LIMIT") {
if (anyErr.message.includes("exceed max mint supply")) {
message = "You are not eligible to mint right now";
}
} else if (anyErr.message.includes("User denied transaction signature")) {
message = "You denied the transaction";
} else {
message = "You may be ineligible to claim this drop"
}

toast({
title: "Failed to claim drop.",
description: message,
description: parseError(err),
status: "error",
duration: 9000,
isClosable: true,
Expand Down Expand Up @@ -492,16 +486,14 @@ const DropWidget: React.FC<DropWidgetProps> = ({
{ enabled: !!dropModule },
);

const isSoldOut = totalAvailable.data?.gte(available.data || 0);

const onlyOnce = useRef(true);
const isNotSoldOut = totalAvailable.data?.gte(available.data || 0);

const numOwned = BigNumber.from(owned.data || 0).toNumber();
useEffect(() => {
if (owned.data?.gt(0) && isSoldOut && onlyOnce.current) {
onlyOnce.current = false;
if (owned.data?.gt(0) && isNotSoldOut) {
setActiveTab("inventory");
}
}, [owned.data, isSoldOut]);
}, [numOwned, isNotSoldOut]);

return (
<Flex
Expand Down