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

feat: add auto renewal button #254

Merged
merged 79 commits into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
Changes from 59 commits
Commits
Show all changes
79 commits
Select commit Hold shift + click to select a range
1de7bb6
feat: add automatic renewal btn
irisdv May 18, 2023
8ff2af4
feat: add auto renew btn on identity card
irisdv May 18, 2023
b306ad5
Merge branch 'testnet' into feat/add_auto_renewal_btn
irisdv May 25, 2023
7eeaaa2
feat: add renewal contract abi + hook
irisdv May 25, 2023
0fb5c2f
feat: add auto renewal btn
irisdv May 25, 2023
9f631a6
fix: build error
irisdv May 25, 2023
3694c25
fix: update autorenewal modal
irisdv May 29, 2023
7bdd1cf
fix: add strong className
irisdv May 29, 2023
2e5f981
feat: add approval checks and auto-renewal on registration
fricoben Jun 10, 2023
20de379
fix: conflicts
fricoben Jun 11, 2023
bea6bdb
fix: review
fricoben Jun 11, 2023
617c8a9
fix conflicts
fricoben Jun 22, 2023
a01e439
fix: conflicts
fricoben Jul 9, 2023
5375598
fix: merge conflicts
irisdv Jul 27, 2023
adec78a
feat: update renewalmodal to work with latest renewal contract version
irisdv Jul 27, 2023
237be56
feat: update autoRenewalModal
irisdv Jul 27, 2023
baa697a
fix: merge conflicts
irisdv Jul 27, 2023
e15d9e2
fix: conflicts
fricoben Jul 28, 2023
5596149
fix: typo
Th0rgal Aug 7, 2023
eeb59d4
fix: add package-lock
irisdv Aug 8, 2023
97fa6e5
fix: merge conflicts
irisdv Aug 8, 2023
428a408
fix: merge conflicts with testnet
irisdv Aug 23, 2023
86212ac
Merge branch 'testnet' into feat/add_auto_renewal_btn
irisdv Sep 7, 2023
56db0d5
ref: update form style & add ustax
irisdv Sep 7, 2023
456af20
ref: update auto renew front
irisdv Sep 7, 2023
b11e7e1
fix: do not show tax when disabling
irisdv Sep 7, 2023
f82baef
fix: add tax to limit price & fix calldata
irisdv Sep 11, 2023
85558d6
fix: merge conflicts with master
irisdv Sep 11, 2023
3740150
fix: merge conflicts with branch testnet
irisdv Sep 14, 2023
7afa8b0
fix: autorenew modal
irisdv Sep 14, 2023
4c2b728
fix merge conflicts with testnet
irisdv Sep 19, 2023
2849259
fix: auto renewals front
irisdv Sep 20, 2023
2260882
fix: delete old register component
irisdv Sep 20, 2023
b15b794
feat: add autorenewal in registerV2
irisdv Sep 20, 2023
aa42228
feat: add metahash check + update design form
irisdv Sep 21, 2023
b685578
fix: meta hash
irisdv Sep 22, 2023
8ecd3ea
fix: merge conflicts with branch testnet
irisdv Oct 6, 2023
afe8762
ref: update sierra renewal contract
irisdv Oct 6, 2023
9783924
ref: update front to work with latest version of autorenew contract
irisdv Oct 6, 2023
6a30e73
Merge branch 'testnet' into feat/add_auto_renewal_btn
irisdv Oct 11, 2023
8e9339a
fix: update auto renewal
irisdv Oct 12, 2023
f81cb3f
Merge branch 'testnet' into feat/add_auto_renewal_btn
irisdv Oct 12, 2023
9415a1f
fix: merge conflicts with branch testnet
irisdv Oct 12, 2023
9e65b7d
fix: spacing
irisdv Oct 12, 2023
6cea34c
test: add toUint256 tests
irisdv Oct 16, 2023
bcaff5c
fix: registerSummary
irisdv Oct 16, 2023
8863cd9
fix: remove terms
irisdv Oct 16, 2023
59488b0
fix: css
irisdv Oct 16, 2023
4207628
Merge branch 'testnet' into feat/add_auto_renewal_btn
irisdv Oct 16, 2023
b9a37da
feat: add autorenewal checkbox in renewal page
irisdv Oct 16, 2023
e357ff2
Merge branch 'testnet' into feat/add_auto_renewal_btn
irisdv Oct 16, 2023
408d4b9
Merge branch 'testnet' into feat/add_auto_renewal_btn
irisdv Oct 16, 2023
31dd9dc
ref: update multicall auto renewal
irisdv Oct 16, 2023
1a1270e
fix: font & textfield background
irisdv Oct 17, 2023
890a241
ref: add auto renewal group
irisdv Oct 17, 2023
e0f3c74
ref: autorenewal calls
irisdv Oct 17, 2023
bc2cf95
fix: merge conflicts with testnet
irisdv Oct 20, 2023
8838f7c
fix: add allowance check + update mail_subscribe
irisdv Oct 20, 2023
8282500
fix: build error
irisdv Oct 20, 2023
ccc0180
fix: merge conflicts
irisdv Oct 26, 2023
4661e6a
fix: icon off
irisdv Oct 26, 2023
9ce54ff
fix: conflicts with branch testnet
irisdv Nov 13, 2023
6cc7956
fix: build error
irisdv Nov 13, 2023
a7d39b8
fix: auto renwal with tax
irisdv Nov 15, 2023
a0f3278
fix: remove logs
irisdv Nov 15, 2023
99331c5
fix: build error
irisdv Nov 15, 2023
d4a56ec
fix: regenerate package-lock file
irisdv Nov 15, 2023
e1f7a23
fix: final price round
irisdv Nov 15, 2023
41aa43e
fix: rounding + add logs
irisdv Nov 15, 2023
fcfcd87
dev: add more logs
irisdv Nov 15, 2023
493b4e5
dev: add more logs
irisdv Nov 15, 2023
bdb10ae
fix: sales tax rate undefined
irisdv Nov 15, 2023
c84623d
dev: remove logs
irisdv Nov 15, 2023
ea982b3
fix: check allowance on register and renewal forms
irisdv Nov 16, 2023
1d5fca6
ref: update mailing list groups
irisdv Nov 16, 2023
d8524cf
fix: add missing dependency
irisdv Nov 16, 2023
ab9b131
fix: merge conflicts with branch testnet
irisdv Nov 16, 2023
0b22a58
Merge branch 'testnet' into feat/add_auto_renewal_btn
irisdv Nov 17, 2023
eae84e8
ref: move month in seconds into constant
irisdv Nov 17, 2023
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
1 change: 1 addition & 0 deletions abi/starknet/renewal.sierra.json

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions components/UI/textField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type TextFieldProps = {
placeholder?: string;
helperText?: string;
type?: React.InputHTMLAttributes<unknown>["type"];
variant?: "default" | "white";
};

const TextField: FunctionComponent<TextFieldProps> = ({
Expand All @@ -28,6 +29,7 @@ const TextField: FunctionComponent<TextFieldProps> = ({
placeholder,
helperText,
type,
variant = "default",
}) => {
return (
<div className="flex flex-col w-full">
Expand All @@ -51,6 +53,7 @@ const TextField: FunctionComponent<TextFieldProps> = ({
InputProps={{
classes: {
root: styles.textfield,
input: variant === "white" ? styles.inputWhite : "",
},
irisdv marked this conversation as resolved.
Show resolved Hide resolved
}}
required={required}
Expand Down
71 changes: 42 additions & 29 deletions components/domains/registerCheckboxes.tsx
Original file line number Diff line number Diff line change
@@ -1,50 +1,63 @@
import React, { FunctionComponent } from "react";
import { Checkbox } from "@mui/material";
import styles from "../../styles/components/variants.module.css";

type RegisterCheckboxes = {
onChangeTermsBox: () => void;
onChangeTermsBox?: () => void;
onChangeRenewalBox?: () => void;
termsBox: boolean;
termsBox?: boolean;
renewalBox?: boolean;
variant?: "default" | "white";
};

const RegisterCheckboxes: FunctionComponent<RegisterCheckboxes> = ({
onChangeRenewalBox,
onChangeTermsBox,
termsBox,
renewalBox,
variant = "default",
}) => {
return (
<div className="w-full mb-3">
<div className="flex mt-2 flex-col sm:flex-row">
<div
className="flex items-center justify-left text-xs mr-2 cursor-pointer"
onClick={onChangeTermsBox}
>
<Checkbox checked={termsBox} sx={{ padding: 0 }} />
<p className="ml-2">
Accept{" "}
<a
className="underline"
href={process.env.NEXT_PUBLIC_STARKNET_ID + "/pdfs/Terms.pdf"}
target="_blank"
rel="noreferrer"
>
terms
</a>{" "}
&{" "}
<a
className="underline"
href={
process.env.NEXT_PUBLIC_STARKNET_ID + "/pdfs/PrivacyPolicy.pdf"
{onChangeTermsBox ? (
<div
className="flex items-center justify-left text-xs mr-2 cursor-pointer"
onClick={onChangeTermsBox}
>
<Checkbox
checked={termsBox}
className={
variant === "white"
? styles.whiteCheckbox
: styles.defaultCheckbox
}
target="_blank"
rel="noreferrer"
>
policies
</a>
</p>
</div>
/>
<p className="ml-2">
Accept{" "}
<a
className="underline"
href={process.env.NEXT_PUBLIC_STARKNET_ID + "/pdfs/Terms.pdf"}
target="_blank"
rel="noreferrer"
>
terms
</a>{" "}
&{" "}
<a
className="underline"
href={
process.env.NEXT_PUBLIC_STARKNET_ID +
"/pdfs/PrivacyPolicy.pdf"
}
target="_blank"
rel="noreferrer"
>
policies
</a>
</p>
</div>
) : null}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Delete for now (we'll soon add it back with new version)

{onChangeRenewalBox ? (
<div
className="flex items-center justify-left text-xs cursor-pointer"
Expand Down
37 changes: 25 additions & 12 deletions components/domains/registerV2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ import Wallets from "../UI/wallets";
import registrationCalls from "../../utils/callData/registrationCalls";
import { computeMetadataHash, generateSalt } from "../../utils/userDataService";
import { getPriceFromDomain } from "../../utils/priceService";
import RegisterCheckboxes from "./registerCheckboxes";
import autoRenewalCalls from "../../utils/callData/autoRenewalCalls";

type RegisterV2Props = {
domain: string;
Expand Down Expand Up @@ -63,7 +65,7 @@ const RegisterV2: FunctionComponent<RegisterV2Props> = ({ domain, groups }) => {
const encodedDomain = utils
.encodeDomain(domain)
.map((element) => element.toString())[0];
// const [renewalBox, setRenewalBox] = useState<boolean>(true);
const [renewalBox, setRenewalBox] = useState<boolean>(true);
const [walletModalOpen, setWalletModalOpen] = useState<boolean>(false);
const [sponsor, setSponsor] = useState<string>("0");
const [salt, setSalt] = useState<string | undefined>();
Expand All @@ -85,9 +87,6 @@ const RegisterV2: FunctionComponent<RegisterV2Props> = ({ domain, groups }) => {
args: [address],
});
const { writeAsync: execute, data: registerData } = useContractWrite({
// calls: renewalBox
// ? callData.concat(registrationCalls.renewal(encodedDomain, price))
// : callData,
calls: callData,
});
const hasMainDomain = !useDisplayName(address ?? "", false).startsWith("0x");
Expand Down Expand Up @@ -115,7 +114,7 @@ const RegisterV2: FunctionComponent<RegisterV2Props> = ({ domain, groups }) => {
)
);
})();
}, [email, usState, salt]);
}, [email, usState, salt, renewalBox]);

useEffect(() => {
// if price query does not work we use the off-chain hardcoded price
Expand Down Expand Up @@ -201,6 +200,21 @@ const RegisterV2: FunctionComponent<RegisterV2Props> = ({ domain, groups }) => {
calls.push(registrationCalls.addressToDomain(encodedDomain));
}

// If the user has toggled autorenewal
if (renewalBox) {
const limitPrice = salesTaxAmount
fricoben marked this conversation as resolved.
Show resolved Hide resolved
? (parseInt(salesTaxAmount) + parseInt(price)).toString()
: price;
calls.push(
autoRenewalCalls.approve(),
autoRenewalCalls.enableRenewal(
encodedDomain,
limitPrice,
txMetadataHash
)
);
}

// Merge and set the call data
setCallData(calls);
}, [
Expand All @@ -214,6 +228,7 @@ const RegisterV2: FunctionComponent<RegisterV2Props> = ({ domain, groups }) => {
sponsor,
metadataHash,
salesTaxRate,
renewalBox,
]);

useEffect(() => {
Expand All @@ -239,7 +254,7 @@ const RegisterV2: FunctionComponent<RegisterV2Props> = ({ domain, groups }) => {
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
tx_hash: formatHexString(registerData.transaction_hash),
groups,
groups: renewalBox ? groups : [groups[0]],
}),
})
.then((res) => res.json())
Expand Down Expand Up @@ -341,12 +356,10 @@ const RegisterV2: FunctionComponent<RegisterV2Props> = ({ domain, groups }) => {
isUsResident={isUsResident}
/>
<Divider className="w-full" />
{/* <RegisterCheckboxes
// onChangeRenewalBox={() => setRenewalBox(!renewalBox)}
onChangeTermsBox={() => setTermsBox(!termsBox)}
termsBox={termsBox}
// renewalBox={renewalBox}
/> */}
<RegisterCheckboxes
onChangeRenewalBox={() => setRenewalBox(!renewalBox)}
renewalBox={renewalBox}
/>
irisdv marked this conversation as resolved.
Show resolved Hide resolved
{address ? (
<Button
onClick={() =>
Expand Down
56 changes: 44 additions & 12 deletions components/domains/renewal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
useTransactionManager,
} from "@starknet-react/core";
import {
formatHexString,
isValidEmail,
selectedDomainsToArray,
selectedDomainsToEncodedArray,
Expand All @@ -31,8 +32,12 @@ import {
} from "../../utils/priceService";
import RenewalDomainsBox from "./renewalDomainsBox";
import registrationCalls from "../../utils/callData/registrationCalls";
import autoRenewalCalls from "../../utils/callData/autoRenewalCalls";
import BackButton from "../UI/backButton";
import { useRouter } from "next/router";
import RegisterCheckboxes from "./registerCheckboxes";
import { utils } from "starknetid.js";
import { getPriceFromDomain } from "../../utils/priceService";

type RenewalProps = {
groups: string[];
Expand All @@ -52,7 +57,7 @@ const Renewal: FunctionComponent<RenewalProps> = ({ groups }) => {
const { contract: etherContract } = useEtherContract();
const [isTxModalOpen, setIsTxModalOpen] = useState(false);
// const [termsBox, setTermsBox] = useState<boolean>(true);
// const [renewalBox, setRenewalBox] = useState<boolean>(true);
const [renewalBox, setRenewalBox] = useState<boolean>(true);
const [walletModalOpen, setWalletModalOpen] = useState<boolean>(false);
const [salt, setSalt] = useState<string | undefined>();
const [metadataHash, setMetadataHash] = useState<string | undefined>();
Expand All @@ -67,9 +72,6 @@ const Renewal: FunctionComponent<RenewalProps> = ({ groups }) => {
args: [address],
});
const { writeAsync: execute, data: renewData } = useContractWrite({
// calls: renewalBox
// ? callData.concat(registrationCalls.renewal(encodedDomain, price))
// : callData,
calls: callData,
});
const [domainsMinting, setDomainsMinting] =
Expand All @@ -89,14 +91,24 @@ const Renewal: FunctionComponent<RenewalProps> = ({ groups }) => {
body: JSON.stringify({
meta_hash: metadataHash,
email,
groups,
tax_state: isUsResident ? usState : "none",
salt: salt,
}),
})
.then((res) => res.json())
.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(renewData.transaction_hash),
groups: renewalBox ? groups : [groups[0]],
}),
})
.then((res) => res.json())
.catch((err) => console.log("Error on registering to email:", err));

addTransaction({ hash: renewData.transaction_hash });
setIsTxModalOpen(true);
}, [renewData, salt, email, usState]);
Expand All @@ -120,7 +132,7 @@ const Renewal: FunctionComponent<RenewalProps> = ({ groups }) => {
)
);
})();
}, [email, usState, salt]);
}, [email, usState, salt, renewalBox]);

useEffect(() => {
if (!selectedDomains) return;
Expand Down Expand Up @@ -182,6 +194,28 @@ const Renewal: FunctionComponent<RenewalProps> = ({ groups }) => {
calls.unshift(registrationCalls.vatTransfer(salesTaxAmount)); // IMPORTANT: We use unshift to put the call at the beginning of the array
}

if (renewalBox) {
calls.push(autoRenewalCalls.approve());
selectedDomainsToArray(selectedDomains).map((domain) => {
const encodedDomain = utils
.encodeDomain(domain)
.map((element) => element.toString())[0];
const price = getPriceFromDomain(1, domain);
const allowance: string = salesTaxRate
? (
Number(price) + applyRateToBigInt(price, salesTaxRate)
).toString()
: price.toString();
calls.push(
autoRenewalCalls.enableRenewal(
encodedDomain,
allowance,
"0x" + metadataHash
)
);
});
}

setCallData(calls);
}
}, [selectedDomains, price, salesTaxRate]);
Expand Down Expand Up @@ -228,12 +262,10 @@ const Renewal: FunctionComponent<RenewalProps> = ({ groups }) => {
isUsResident={isUsResident}
/>
<Divider className="w-full" />
{/* <RegisterCheckboxes
// onChangeRenewalBox={() => setRenewalBox(!renewalBox)}
onChangeTermsBox={() => setTermsBox(!termsBox)}
termsBox={termsBox}
// renewalBox={renewalBox}
/> */}
<RegisterCheckboxes
onChangeRenewalBox={() => setRenewalBox(!renewalBox)}
renewalBox={renewalBox}
/>
{address ? (
<Button
onClick={() =>
Expand Down
3 changes: 3 additions & 0 deletions components/domains/selectState.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ import allUsStates from "../../public/usa/allUsStates.json";
type SelectStateProps = {
usState: string;
changeUsState: (value: string) => void;
variant?: "default" | "white";
};

const SelectState: FunctionComponent<SelectStateProps> = ({
usState,
changeUsState,
variant = "default",
}) => {
return (
<div className="flex flex-col w-full">
Expand All @@ -30,6 +32,7 @@ const SelectState: FunctionComponent<SelectStateProps> = ({
display: "flex",
justifyContent: "center",
alignItems: "center",
backgroundColor: variant ? "#FFFFFF" : "transparent",
irisdv marked this conversation as resolved.
Show resolved Hide resolved
},
"& .css-10hburv-MuiTypography-root": {
fontFamily: "Poppins-Regular",
Expand Down
11 changes: 10 additions & 1 deletion components/domains/usForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
RadioGroup,
} from "@mui/material";
import textFieldStyles from "../../styles/components/textField.module.css";
import variantStyles from "../../styles/components/variants.module.css";
import SelectState from "./selectState";
import InputHelper from "../UI/inputHelper";

Expand All @@ -17,21 +18,29 @@ type UsFormProps = {
) => void;
usState: string;
changeUsState: (value: string) => void;
variant?: "default" | "white";
};

const UsForm: FunctionComponent<UsFormProps> = ({
isUsResident,
onUsResidentChange,
usState,
changeUsState,
variant = "default",
fricoben marked this conversation as resolved.
Show resolved Hide resolved
}) => {
return (
<FormControl className="flex gap-4 w-full">
<div className="flex flex-col">
<div className="flex gap-1 my-1">
<p className={textFieldStyles.legend}>Do you live in the USA ?*</p>
</div>
<div className="border-solid border border-[#c4c4c4ff] rounded-[7.983px] pl-[16.5px] py-1">
<div
className={
variant === "white"
? variantStyles.whiteUsForm
: variantStyles.defaultUsForm
}
>
<InputHelper helperText="If you live in the US, we need your ZIP code due to the USA tax policy.">
<RadioGroup
aria-labelledby="demo-controlled-radio-buttons-group"
Expand Down
Loading