diff --git a/parcel-build.html b/parcel-build.html index 60e4286..06ae84a 100644 --- a/parcel-build.html +++ b/parcel-build.html @@ -20,6 +20,6 @@
- + diff --git a/src/shared/parseError.ts b/src/shared/parseError.ts new file mode 100644 index 0000000..8d364dd --- /dev/null +++ b/src/shared/parseError.ts @@ -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; +} \ No newline at end of file diff --git a/src/widgets/bundledrop.tsx b/src/widgets/bundledrop.tsx index 4226813..58d2966 100644 --- a/src/widgets/bundledrop.tsx +++ b/src/widgets/bundledrop.tsx @@ -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); @@ -226,26 +227,19 @@ const ClaimButton: React.FC = ({ 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, @@ -516,14 +510,12 @@ const DropWidget: React.FC = ({ 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 ( = ({ 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, @@ -492,16 +486,14 @@ const DropWidget: React.FC = ({ { 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 (