From 3cf64b39754531abe4e8d295e55caa248ef66900 Mon Sep 17 00:00:00 2001 From: Nico Date: Thu, 12 Sep 2024 19:09:37 +0200 Subject: [PATCH] fix: coupon errors (#875) * fix: coupon errors * improve call data loading message * fix: reset error message when trying another ticket * removing one setter --- components/discount/freeRegisterCheckout.tsx | 30 +++++++++----------- hooks/paymaster.tsx | 12 ++++++++ styles/components/registerV2.module.css | 7 +++++ styles/components/textField.module.css | 4 ++- 4 files changed, 35 insertions(+), 18 deletions(-) diff --git a/components/discount/freeRegisterCheckout.tsx b/components/discount/freeRegisterCheckout.tsx index 0e002233..42a4842a 100644 --- a/components/discount/freeRegisterCheckout.tsx +++ b/components/discount/freeRegisterCheckout.tsx @@ -41,6 +41,7 @@ const FreeRegisterCheckout: FunctionComponent = ({ }) => { const [targetAddress, setTargetAddress] = useState(""); const [callData, setCallData] = useState([]); + const [loadingCallData, setLoadingCallData] = useState(true); const [salt, setSalt] = useState(); const encodedDomain = utils .encodeDomain(domain) @@ -67,6 +68,7 @@ const FreeRegisterCheckout: FunctionComponent = ({ loadingDeploymentData, refreshRewards, invalidTx, + txError, loadingTypedData, } = usePaymaster( callData, @@ -76,7 +78,7 @@ const FreeRegisterCheckout: FunctionComponent = ({ ); if (transactionHash) setTransactionHash(transactionHash); }, - !coupon + loadingCallData ); useEffect(() => { @@ -107,7 +109,7 @@ const FreeRegisterCheckout: FunctionComponent = ({ }, [salt]); useEffect(() => { - if (signature[0] === null) return; + if (!signature[0]) return; // Variables const newTokenId: number = Math.floor(Math.random() * 1000000000000); setTokenId(newTokenId); @@ -118,7 +120,8 @@ const FreeRegisterCheckout: FunctionComponent = ({ signature, txMetadataHash ); - return setCallData(freeRegisterCalls); + setCallData(freeRegisterCalls); + setLoadingCallData(false); }, [metadataHash, encodedDomain, signature]); function changeCoupon(value: string): void { @@ -146,17 +149,8 @@ const FreeRegisterCheckout: FunctionComponent = ({ useEffect(() => { if (!coupon) return setLoadingCoupon(false); - const lastSuccessCoupon = localStorage.getItem("lastSuccessCoupon"); - if (coupon === lastSuccessCoupon) { - setCouponError(""); - setLoadingCoupon(false); - const signature = JSON.parse( - localStorage.getItem("couponSignature") as string - ); - setSignature(signature); - return; - } if (!address) return; + setLoadingCallData(true); getFreeDomain(address, `${domain}.stark`, coupon).then((res) => { if (res.error) setCouponError( @@ -166,9 +160,6 @@ const FreeRegisterCheckout: FunctionComponent = ({ const signature = [res.r, res.s]; setSignature(signature); setCouponError(""); - // Write in local storage - localStorage.setItem("lastSuccessCoupon", coupon); - localStorage.setItem("couponSignature", JSON.stringify(signature)); } setLoadingCoupon(false); }); @@ -207,6 +198,9 @@ const FreeRegisterCheckout: FunctionComponent = ({ checked={termsBox} onChange={() => setTermsBox(!termsBox)} /> + {invalidTx && txError?.message ? ( +

{txError.message}

+ ) : null} {address ? (