Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ref: delete mail #934

Merged
merged 2 commits into from
Dec 12, 2024
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
44 changes: 24 additions & 20 deletions components/discount/freeRegisterCheckout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,12 @@ const FreeRegisterCheckout: FunctionComponent<FreeRegisterCheckoutProps> = ({
// 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]);

Expand Down Expand Up @@ -168,6 +173,23 @@ const FreeRegisterCheckout: FunctionComponent<FreeRegisterCheckoutProps> = ({
});
}, [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 (
<div className={styles.container}>
<div className={styles.card}>
Expand Down Expand Up @@ -222,25 +244,7 @@ const FreeRegisterCheckout: FunctionComponent<FreeRegisterCheckoutProps> = ({
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()}
</Button>
) : (
<ConnectButton />
Expand Down
47 changes: 5 additions & 42 deletions components/discount/freeRenewalCheckout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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<FreeRenewalCheckoutProps> = ({
groups,
offer,
goBack,
}) => {
const [email, setEmail] = useState<string>("");
const [emailError, setEmailError] = useState<boolean>(true);
const [isSwissResident, setIsSwissResident] = useState<boolean>(false);
const [salesTaxRate, setSalesTaxRate] = useState<number>(0);
const [salesTaxAmount, setSalesTaxAmount] = useState<bigint>(BigInt(0));
Expand Down Expand Up @@ -99,7 +93,7 @@ const FreeRenewalCheckout: FunctionComponent<FreeRenewalCheckoutProps> = ({
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
meta_hash: metadataHash,
email: email,
email: "none",
tax_state: isSwissResident ? "switzerland" : "none",
salt: salt,
}),
Expand All @@ -108,17 +102,6 @@ const FreeRenewalCheckout: FunctionComponent<FreeRenewalCheckoutProps> = ({
.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(),
Expand Down Expand Up @@ -211,20 +194,15 @@ const FreeRenewalCheckout: FunctionComponent<FreeRenewalCheckoutProps> = ({

const computeHashes = async () => {
const hash = await computeMetadataHash(
email,
"none",
isSwissResident ? "switzerland" : "none",
salt
);
setMetadataHash(hash);
};

computeHashes();
}, [email, salt, isSwissResident, needMetadata]);

function changeEmail(value: string): void {
setEmail(value);
setEmailError(isValidEmail(value) ? false : true);
}
}, [salt, isSwissResident, needMetadata]);

useEffect(() => {
if (isSwissResident) {
Expand Down Expand Up @@ -287,18 +265,6 @@ const FreeRenewalCheckout: FunctionComponent<FreeRenewalCheckoutProps> = ({
<h3 className={styles.domain}>Renew Your domain(s)</h3>
</div>
<div className="flex flex-col items-start gap-6 self-stretch">
{needMetadata && (
<TextField
helperText="Secure your domain's future and stay ahead with vital updates. Your email stays private with us, always."
label="Email address"
value={email}
onChange={(e) => changeEmail(e.target.value)}
color="secondary"
error={emailError}
errorMessage="Please enter a valid email address"
type="email"
/>
)}
{needMetadata && (
<SwissForm
isSwissResident={isSwissResident}
Expand Down Expand Up @@ -347,17 +313,14 @@ const FreeRenewalCheckout: FunctionComponent<FreeRenewalCheckoutProps> = ({
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)"}
</Button>
) : (
<ConnectButton />
Expand Down
33 changes: 6 additions & 27 deletions components/discount/registerDiscount.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -66,8 +64,6 @@ const RegisterDiscount: FunctionComponent<RegisterDiscountProps> = ({
}) => {
const router = useRouter();
const [targetAddress, setTargetAddress] = useState<string>("");
const [email, setEmail] = useState<string>("");
const [emailError, setEmailError] = useState<boolean>(true);
const [isSwissResident, setIsSwissResident] = useState<boolean>(false);
const [salesTaxRate, setSalesTaxRate] = useState<number>(0);
const [salesTaxAmount, setSalesTaxAmount] = useState<bigint>(BigInt(0));
Expand Down Expand Up @@ -111,14 +107,13 @@ const RegisterDiscount: FunctionComponent<RegisterDiscountProps> = ({
(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(() => {
Expand Down Expand Up @@ -292,7 +287,7 @@ const RegisterDiscount: FunctionComponent<RegisterDiscountProps> = ({
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,
fricoben marked this conversation as resolved.
Show resolved Hide resolved
Expand Down Expand Up @@ -323,10 +318,6 @@ const RegisterDiscount: FunctionComponent<RegisterDiscountProps> = ({
// 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) {
Expand Down Expand Up @@ -363,15 +354,6 @@ const RegisterDiscount: FunctionComponent<RegisterDiscountProps> = ({
<h3 className={styles.domain}>{getDomainWithStark(domain)}</h3>
</div>
<div className="flex flex-col items-start gap-6 self-stretch">
<TextField
helperText="We won't share your email with anyone. We'll use it only to inform you about your domain and our news, you can unsubscribe at any moment."
label="Email address"
value={email}
onChange={(e) => changeEmail(e.target.value)}
color="secondary"
error={emailError}
errorMessage="Please enter a valid email address"
/>
<SwissForm
isSwissResident={isSwissResident}
onSwissResidentChange={() => setIsSwissResident(!isSwissResident)}
Expand Down Expand Up @@ -413,17 +395,14 @@ const RegisterDiscount: FunctionComponent<RegisterDiscountProps> = ({
!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"}
</Button>
) : (
<ConnectButton />
Expand Down
Loading