diff --git a/components/discount/freeRegisterCheckout.tsx b/components/discount/freeRegisterCheckout.tsx index c49f2d66..0aea3f8d 100644 --- a/components/discount/freeRegisterCheckout.tsx +++ b/components/discount/freeRegisterCheckout.tsx @@ -106,7 +106,12 @@ const FreeRegisterCheckout: FunctionComponent = ({ // salt must not be empty to preserve privacy if (!salt) return; (async () => { - setMetadataHash(await computeMetadataHash("none", "none", salt)); + setMetadataHash(await computeMetadataHash( + "none", + "none", + salt + ) + ); })(); }, [salt]); @@ -168,6 +173,23 @@ const FreeRegisterCheckout: FunctionComponent = ({ }); }, [coupon, domain, address, isWrongNetwork]); + const getButtonText = () => { + if (isWrongNetwork) return "Wrong Network"; + if (!termsBox) return "Please accept terms & policies"; + if (couponError || !coupon) return "Enter a valid Coupon"; + if (loadingCallData) return "Loading call data"; + if (loadingGas) { + if (invalidTx) return txError?.short; + return "Loading gas"; + } + if (loadingTypedData) return "Building typed data"; + if (loadingDeploymentData) { + if (paymasterRewards.length > 0) return "Loading deployment data"; + return "No Paymaster reward available"; + } + return "Register my domain"; + }; + return (
@@ -222,25 +244,7 @@ const FreeRegisterCheckout: FunctionComponent = ({ loadingTypedData } > - {isWrongNetwork - ? "Wrong Network" - : !termsBox - ? "Please accept terms & policies" - : couponError || !coupon - ? "Enter a valid Coupon" - : loadingCallData - ? "Loading call data" - : loadingGas - ? invalidTx - ? txError?.short - : "Loading gas" - : loadingTypedData - ? "Building typed data" - : loadingDeploymentData - ? paymasterRewards.length > 0 - ? "Loading deployment data" - : "No Paymaster reward available" - : "Register my domain"} + {getButtonText()} ) : ( diff --git a/components/discount/freeRenewalCheckout.tsx b/components/discount/freeRenewalCheckout.tsx index 90d65a1e..d17ff8f7 100644 --- a/components/discount/freeRenewalCheckout.tsx +++ b/components/discount/freeRenewalCheckout.tsx @@ -2,10 +2,8 @@ import React from "react"; import { FunctionComponent, useEffect, useState } from "react"; import Button from "../UI/button"; import { useAccount, useSendTransaction } from "@starknet-react/core"; -import { formatHexString, isValidEmail } from "../../utils/stringService"; import { applyRateToBigInt } from "../../utils/feltService"; import styles from "../../styles/components/registerV2.module.css"; -import TextField from "../UI/textField"; import SwissForm from "../domains/swissForm"; import { Divider } from "@mui/material"; import RegisterSummary from "../domains/registerSummary"; @@ -33,18 +31,14 @@ import { areArraysEqual } from "@/utils/arrayService"; import { useFreeRenewalTxPrep } from "@/hooks/checkout/useFreeRenewalTxPrep"; type FreeRenewalCheckoutProps = { - groups: string[]; goBack: () => void; offer: Discount; }; const FreeRenewalCheckout: FunctionComponent = ({ - groups, offer, goBack, }) => { - const [email, setEmail] = useState(""); - const [emailError, setEmailError] = useState(true); const [isSwissResident, setIsSwissResident] = useState(false); const [salesTaxRate, setSalesTaxRate] = useState(0); const [salesTaxAmount, setSalesTaxAmount] = useState(BigInt(0)); @@ -99,7 +93,7 @@ const FreeRenewalCheckout: FunctionComponent = ({ headers: { "Content-Type": "application/json" }, body: JSON.stringify({ meta_hash: metadataHash, - email: email, + email: "none", tax_state: isSwissResident ? "switzerland" : "none", salt: salt, }), @@ -108,17 +102,6 @@ const FreeRenewalCheckout: FunctionComponent = ({ .catch((err) => console.log("Error on sending metadata:", err)); } - // Subscribe to auto renewal mailing list if renewal box is checked - fetch(`${process.env.NEXT_PUBLIC_SALES_SERVER_LINK}/mail_subscribe`, { - method: "POST", - headers: { "Content-Type": "application/json" }, - body: JSON.stringify({ - tx_hash: formatHexString(renewData.transaction_hash), - groups, - }), - }) - .then((res) => res.json()) - .catch((err) => console.log("Error on registering to email:", err)); addTransaction({ timestamp: Date.now(), @@ -211,7 +194,7 @@ const FreeRenewalCheckout: FunctionComponent = ({ const computeHashes = async () => { const hash = await computeMetadataHash( - email, + "none", isSwissResident ? "switzerland" : "none", salt ); @@ -219,12 +202,7 @@ const FreeRenewalCheckout: FunctionComponent = ({ }; computeHashes(); - }, [email, salt, isSwissResident, needMetadata]); - - function changeEmail(value: string): void { - setEmail(value); - setEmailError(isValidEmail(value) ? false : true); - } + }, [salt, isSwissResident, needMetadata]); useEffect(() => { if (isSwissResident) { @@ -287,18 +265,6 @@ const FreeRenewalCheckout: FunctionComponent = ({

Renew Your domain(s)

- {needMetadata && ( - changeEmail(e.target.value)} - color="secondary" - error={emailError} - errorMessage="Please enter a valid email address" - type="email" - /> - )} {needMetadata && ( = ({ domainsMinting === selectedDomains || !address || !termsBox || - (emailError && needMetadata) || !areDomainSelected(selectedDomains) } > {!termsBox ? "Please accept terms & policies" : !areDomainSelected(selectedDomains) - ? "Select a domain to renew" - : emailError && needMetadata - ? "Enter a valid Email" - : "Renew my domain(s)"} + ? "Select a domain to renew" + : "Renew my domain(s)"} ) : ( diff --git a/components/discount/registerDiscount.tsx b/components/discount/registerDiscount.tsx index 2c4fc95c..70886456 100644 --- a/components/discount/registerDiscount.tsx +++ b/components/discount/registerDiscount.tsx @@ -6,14 +6,12 @@ import { utils } from "starknetid.js"; import { formatHexString, getDomainWithStark, - isValidEmail, } from "../../utils/stringService"; import { applyRateToBigInt, hexToDecimal } from "../../utils/feltService"; import { useDisplayName } from "../../hooks/displayName.tsx"; import { Call } from "starknet"; import { posthog } from "posthog-js"; import styles from "../../styles/components/registerV2.module.css"; -import TextField from "../UI/textField"; import { Divider } from "@mui/material"; import RegisterCheckboxes from "../domains/registerCheckboxes"; import RegisterSummary from "../domains/registerSummary"; @@ -66,8 +64,6 @@ const RegisterDiscount: FunctionComponent = ({ }) => { const router = useRouter(); const [targetAddress, setTargetAddress] = useState(""); - const [email, setEmail] = useState(""); - const [emailError, setEmailError] = useState(true); const [isSwissResident, setIsSwissResident] = useState(false); const [salesTaxRate, setSalesTaxRate] = useState(0); const [salesTaxAmount, setSalesTaxAmount] = useState(BigInt(0)); @@ -111,14 +107,13 @@ const RegisterDiscount: FunctionComponent = ({ (async () => { setMetadataHash( await computeMetadataHash( - email, - //mailGroups, + "none", isSwissResident ? "switzerland" : "none", salt ) ); })(); - }, [email, isSwissResident, salt]); + }, [isSwissResident, salt]); // refetch new quote if the timestamp from quote is expired useEffect(() => { @@ -292,7 +287,7 @@ const RegisterDiscount: FunctionComponent = ({ headers: { "Content-Type": "application/json" }, body: JSON.stringify({ meta_hash: metadataHash, - email, + email: "none", groups: mailGroups, // Domain Owner group tax_state: isSwissResident ? "switzerland" : "none", salt: salt, @@ -323,10 +318,6 @@ const RegisterDiscount: FunctionComponent = ({ // eslint-disable-next-line react-hooks/exhaustive-deps }, [registerData]); // We want to execute this only once after the tx is sent - function changeEmail(value: string): void { - setEmail(value); - setEmailError(isValidEmail(value) ? false : true); - } useEffect(() => { if (isSwissResident) { @@ -363,15 +354,6 @@ const RegisterDiscount: FunctionComponent = ({

{getDomainWithStark(domain)}

- changeEmail(e.target.value)} - color="secondary" - error={emailError} - errorMessage="Please enter a valid email address" - /> setIsSwissResident(!isSwissResident)} @@ -413,17 +395,14 @@ const RegisterDiscount: FunctionComponent = ({ !durationInDays || !targetAddress || invalidBalance || - !termsBox || - emailError + !termsBox } > {!termsBox ? "Please accept terms & policies" : invalidBalance - ? `You don't have enough ${displayedCurrency}` - : emailError - ? "Enter a valid Email" - : "Register my domain"} + ? `You don't have enough ${displayedCurrency}` + : "Register my domain"} ) : ( diff --git a/components/domains/autorenewal.tsx b/components/domains/autorenewal.tsx index f3b45f96..27ef4435 100644 --- a/components/domains/autorenewal.tsx +++ b/components/domains/autorenewal.tsx @@ -3,15 +3,12 @@ import { FunctionComponent, useEffect, useState } from "react"; import Button from "../UI/button"; import { useAccount, useSendTransaction } from "@starknet-react/core"; import { - formatHexString, - isValidEmail, selectedDomainsToArray, } from "../../utils/stringService"; import { applyRateToBigInt } from "../../utils/feltService"; import { Call } from "starknet"; import { posthog } from "posthog-js"; import styles from "../../styles/components/registerV2.module.css"; -import TextField from "../UI/textField"; import SwissForm from "./swissForm"; import { computeMetadataHash, generateSalt } from "../../utils/userDataService"; import { @@ -48,13 +45,8 @@ import useNeedSubscription from "@/hooks/useNeedSubscription"; import AutoRenewalDomainsBox from "./autoRenewalDomainsBox"; import Notification from "../UI/notification"; -type SubscriptionProps = { - groups: string[]; -}; -const Subscription: FunctionComponent = ({ groups }) => { - const [email, setEmail] = useState(""); - const [emailError, setEmailError] = useState(true); +const Subscription: FunctionComponent = () => { const [isSwissResident, setIsSwissResident] = useState(false); const [salesTaxRate, setSalesTaxRate] = useState(0); const [salesTaxAmount, setSalesTaxAmount] = useState(BigInt(0)); @@ -117,7 +109,7 @@ const Subscription: FunctionComponent = ({ groups }) => { headers: { "Content-Type": "application/json" }, body: JSON.stringify({ meta_hash: metadataHash, - email, + email: "none", tax_state: isSwissResident ? "switzerland" : "none", salt: salt, }), @@ -128,17 +120,6 @@ const Subscription: FunctionComponent = ({ groups }) => { }); } - // Subscribe to auto renewal mailing list if renewal box is checked - fetch(`${process.env.NEXT_PUBLIC_SALES_SERVER_LINK}/mail_subscribe`, { - method: "POST", - headers: { "Content-Type": "application/json" }, - body: JSON.stringify({ - tx_hash: formatHexString(autorenewData.transaction_hash), - groups, - }), - }) - .then((res) => res.json()) - .catch((err) => console.log("Error on registering to email:", err)); addTransaction({ timestamp: Date.now(), @@ -168,13 +149,13 @@ const Subscription: FunctionComponent = ({ groups }) => { (async () => { setMetadataHash( await computeMetadataHash( - email, + "none", isSwissResident ? "switzerland" : "none", salt ) ); })(); - }, [email, salt, renewalBox, isSwissResident, needMedadata]); + }, [salt, isSwissResident, needMedadata]); // refetch new quote if the timestamp from quote is expired useEffect(() => { @@ -332,11 +313,6 @@ const Subscription: FunctionComponent = ({ groups }) => { priceInEth, ]); - function changeEmail(value: string): void { - setEmail(value); - setEmailError(isValidEmail(value) ? false : true); - } - return (
@@ -350,18 +326,6 @@ const Subscription: FunctionComponent = ({ groups }) => {

- {needMedadata ? ( - changeEmail(e.target.value)} - color="secondary" - error={emailError} - errorMessage="Please enter a valid email address" - type="email" - /> - ) : null} {needMedadata ? ( = ({ groups }) => { domainsMinting === selectedDomains || !address || !termsBox || - (needMedadata && emailError) || !areDomainSelected(selectedDomains) || callData.length === 0 // Cover the case where there are no domains to subscribe } @@ -413,12 +376,10 @@ const Subscription: FunctionComponent = ({ groups }) => { {!termsBox ? "Please accept terms & policies" : !areDomainSelected(selectedDomains) - ? "Select a domain to subscribe" - : needMedadata && emailError - ? "Enter a valid Email" - : callData.length === 0 - ? "You're already subscribed" - : "Enable subscription"} + ? "Select a domain to subscribe" + : callData.length === 0 + ? "You're already subscribed" + : "Enable subscription"} ) : ( diff --git a/components/domains/registerV3.tsx b/components/domains/registerV3.tsx index 7218231f..7b81ea1e 100644 --- a/components/domains/registerV3.tsx +++ b/components/domains/registerV3.tsx @@ -12,14 +12,12 @@ import evergreenDiscounts from "@/utils/discounts/evergreen"; type RegisterV3Props = { domain: string; - groups: string[]; setDomain: (domain: string) => void; }; const RegisterV3: FunctionComponent = ({ domain, setDomain, - groups, }) => { const { address } = useAccount(); const [currentStep, setCurrentStep] = useState(1); @@ -85,7 +83,6 @@ const RegisterV3: FunctionComponent = ({ {currentStep === 3 && ( )} diff --git a/components/domains/renewalV2.tsx b/components/domains/renewalV2.tsx index 2550e06c..b77cf097 100644 --- a/components/domains/renewalV2.tsx +++ b/components/domains/renewalV2.tsx @@ -10,11 +10,8 @@ import SelectPfp from "./steps/selectPfp"; import { StarknetIdJsContext } from "@/context/StarknetIdJsProvider"; import evergreenDiscounts from "@/utils/discounts/evergreen"; -type RenewalProps = { - groups: string[]; -}; -const RenewalV2: FunctionComponent = ({ groups }) => { +const RenewalV2: FunctionComponent = () => { const { address } = useAccount(); const [currentStep, setCurrentStep] = useState(1); const { updateFormState, userNfts, isLoadingNfts } = useContext(FormContext); @@ -95,7 +92,6 @@ const RenewalV2: FunctionComponent = ({ groups }) => { {currentStep === 3 && ( )} diff --git a/components/domains/steps/checkoutCard.tsx b/components/domains/steps/checkoutCard.tsx index 43b88a2b..308da890 100644 --- a/components/domains/steps/checkoutCard.tsx +++ b/components/domains/steps/checkoutCard.tsx @@ -37,14 +37,12 @@ import { useRenewalTxPrep } from "@/hooks/checkout/useRenewalTxPrep"; type CheckoutCardProps = { type: FormType; - groups: string[]; discount: Upsell; }; const CheckoutCard: FunctionComponent = ({ type, discount, - groups, }) => { const router = useRouter(); const { account, address } = useAccount(); @@ -166,7 +164,7 @@ const CheckoutCard: FunctionComponent = ({ headers: { "Content-Type": "application/json" }, body: JSON.stringify({ meta_hash: formState.metadataHash, - email: formState.email, + email: "none", tax_state: formState.isSwissResident ? "switzerland" : "none", salt: formState.salt, }), @@ -175,16 +173,6 @@ const CheckoutCard: FunctionComponent = ({ .catch((err) => console.log("Error on sending metadata:", err)); } - fetch(`${process.env.NEXT_PUBLIC_SALES_SERVER_LINK}/mail_subscribe`, { - method: "POST", - headers: { "Content-Type": "application/json" }, - body: JSON.stringify({ - tx_hash: formatHexString(checkoutData.transaction_hash), - groups: renewalBox ? groups : [groups[0]], - }), - }) - .then((res) => res.json()) - .catch((err) => console.log("Error on registering to email:", err)); addTransaction({ timestamp: Date.now(), @@ -241,6 +229,12 @@ const CheckoutCard: FunctionComponent = ({ [updateFormState] ); + const getButtonText = () => { + if (!termsBox) return "Please accept terms & policies"; + if (invalidBalance) return `You don't have enough ${displayedCurrency}`; + return "Purchase"; + }; + return ( <> {formState.durationInYears === 1 ? ( @@ -255,8 +249,8 @@ const CheckoutCard: FunctionComponent = ({ /> ) : null} {reducedDuration > 0 && - invalidBalance && - reducedDuration !== formState.durationInYears * 365 ? ( + invalidBalance && + reducedDuration !== formState.durationInYears * 365 ? ( = ({ !termsBox } > - {!termsBox - ? "Please accept terms & policies" - : invalidBalance - ? `You don't have enough ${displayedCurrency}` - : "Purchase"} + {getButtonText()}
diff --git a/components/domains/steps/userInfoForm.tsx b/components/domains/steps/userInfoForm.tsx index a15f2c3b..c662076e 100644 --- a/components/domains/steps/userInfoForm.tsx +++ b/components/domains/steps/userInfoForm.tsx @@ -7,8 +7,7 @@ import React, { import styles from "../../../styles/components/registerV3.module.css"; import { FormContext } from "@/context/FormProvider"; import { FormType } from "@/utils/constants"; -import { getDomainWithStark, isValidEmail } from "@/utils/stringService"; -import TextField from "../../UI/textField"; +import { getDomainWithStark } from "@/utils/stringService"; import SwissForm from "../swissForm"; import SelectIdentity from "../selectIdentity"; import NumberTextField from "@/components/UI/numberTextField"; @@ -40,8 +39,6 @@ const UserInfoForm: FunctionComponent = ({ const maxYearsToRegister = 25; const { address } = useAccount(); const { formState, updateFormState } = useContext(FormContext); - const [email, setEmail] = useState(""); - const [emailError, setEmailError] = useState(true); const [selectedDomains, setSelectedDomains] = useState>(); @@ -51,11 +48,6 @@ const UserInfoForm: FunctionComponent = ({ // eslint-disable-next-line react-hooks/exhaustive-deps }, [selectedDomains, type]); // Don't call updateFromState on every render - function changeEmail(value: string): void { - setEmail(value); - setEmailError(isValidEmail(value) ? false : true); - updateFormState({ email: value }); - } function changeTokenId(value: number): void { updateFormState({ tokenId: value }); @@ -99,9 +91,7 @@ const UserInfoForm: FunctionComponent = ({ }; const getButtonText = (): string => { - return formState.needMetadata && emailError - ? "Enter a valid Email" - : type === FormType.RENEW && !areDomainSelected(formState.selectedDomains) + return type === FormType.RENEW && !areDomainSelected(formState.selectedDomains) ? "Select a domain to renew" : "Next step"; }; @@ -110,7 +100,6 @@ const UserInfoForm: FunctionComponent = ({ return ( !formState.durationInYears || formState.durationInYears < 1 || - (formState.needMetadata && emailError) || (type === FormType.RENEW && !areDomainSelected(formState.selectedDomains)) ); }; @@ -124,18 +113,7 @@ const UserInfoForm: FunctionComponent = ({

{getTitle()}

- {formState.needMetadata ? ( - changeEmail(e.target.value)} - color="secondary" - error={emailError} - errorMessage="Please enter a valid email address" - type="email" - /> - ) : null} + {formState.needMetadata ? ( ({ formState: initialState, // eslint-disable-next-line @typescript-eslint/no-empty-function - clearForm: () => {}, + clearForm: () => { }, // eslint-disable-next-line @typescript-eslint/no-empty-function - updateFormState: () => {}, + updateFormState: () => { }, }); export const FormProvider: FunctionComponent = ({ children }) => { @@ -103,7 +101,7 @@ export const FormProvider: FunctionComponent = ({ children }) => { (async () => { updateFormState({ metadataHash: await computeMetadataHash( - formState.email, + "none", formState.isSwissResident ? "switzerland" : "none", formState.salt as string ), @@ -111,7 +109,6 @@ export const FormProvider: FunctionComponent = ({ children }) => { })(); }, [ formState.salt, - formState.email, formState.isSwissResident, formState.needMetadata, updateFormState, diff --git a/pages/freerenewal.tsx b/pages/freerenewal.tsx index d63c2a84..9649c108 100644 --- a/pages/freerenewal.tsx +++ b/pages/freerenewal.tsx @@ -44,10 +44,6 @@ const FreeRenewalPage: NextPage = () => { {screen === 2 ? (
diff --git a/pages/register/[domainToRegister].tsx b/pages/register/[domainToRegister].tsx index 03821815..60c58884 100644 --- a/pages/register/[domainToRegister].tsx +++ b/pages/register/[domainToRegister].tsx @@ -31,10 +31,6 @@ const RegistrationPage: NextPage = () => {
diff --git a/pages/renewal.tsx b/pages/renewal.tsx index 651b8024..f5141039 100644 --- a/pages/renewal.tsx +++ b/pages/renewal.tsx @@ -10,11 +10,7 @@ const RenewalPage: NextPage = () => {
- +
diff --git a/pages/subscription.tsx b/pages/subscription.tsx index 9382cde8..9d054b81 100644 --- a/pages/subscription.tsx +++ b/pages/subscription.tsx @@ -8,11 +8,7 @@ const AutoRenewalPage: NextPage = () => { return (
- +
); diff --git a/tests/utils/userDataService.test.js b/tests/utils/userDataService.test.js index fff02fd1..9f78a774 100644 --- a/tests/utils/userDataService.test.js +++ b/tests/utils/userDataService.test.js @@ -9,7 +9,6 @@ import crypto from "crypto"; // Mock the crypto module global.crypto = crypto; -const STARKNET_ID_URL = process.env.NEXT_PUBLIC_STARKNET_ID; global.fetch = jest.fn(); describe("generateSalt function", () => {