diff --git a/components/identities/actions/autoRenewalModal.tsx b/components/identities/actions/autoRenewalModal.tsx index 7a7dfb03..25abb636 100644 --- a/components/identities/actions/autoRenewalModal.tsx +++ b/components/identities/actions/autoRenewalModal.tsx @@ -6,7 +6,7 @@ import { useTransactionManager, } from "@starknet-react/core"; import React, { FunctionComponent, useEffect, useState } from "react"; -import { useEtherContract, usePricingContract } from "../../../hooks/contracts"; +import { usePricingContract } from "../../../hooks/contracts"; import styles from "../../../styles/components/autoRenewal.module.css"; import Button from "../../UI/button"; import { timestampToReadableDate } from "../../../utils/dateService"; @@ -30,7 +30,7 @@ type AutoRenewalModalProps = { callDataEncodedDomain: (number | string)[]; identity?: Identity; domain?: string; - limit?: string; + allowance?: string; }; const AutoRenewalModal: FunctionComponent = ({ @@ -39,12 +39,13 @@ const AutoRenewalModal: FunctionComponent = ({ callDataEncodedDomain, identity, domain, - limit, + allowance, }) => { const { address } = useAccount(); const [price, setPrice] = useState("0"); - const [limitPrice, setLimitPrice] = useState(limit ?? "0"); - const [needApproval, setNeedApproval] = useState(false); + const [renewalAllowance, setRenewalAllowance] = useState( + allowance ?? "0" + ); const [isTxSent, setIsTxSent] = useState(false); const [isUsResident, setIsUsResident] = useState(false); const [usState, setUsState] = useState("DE"); @@ -59,7 +60,6 @@ const AutoRenewalModal: FunctionComponent = ({ const [needMedadata, setNeedMetadata] = useState(true); const [callData, setCallData] = useState([]); const { contract: pricingContract } = usePricingContract(); - const { contract: etherContract } = useEtherContract(); const { addTransaction } = useTransactionManager(); const { data: priceData, error: priceError } = useContractRead({ address: pricingContract?.address as string, @@ -67,15 +67,6 @@ const AutoRenewalModal: FunctionComponent = ({ functionName: "compute_renew_price", args: [callDataEncodedDomain[1], 365], }); - const { data: approvalData, error: approvalError } = useContractRead({ - address: etherContract?.address as string, - abi: etherContract?.abi as Abi, - functionName: "allowance", - args: [ - address as string, - process.env.NEXT_PUBLIC_RENEWAL_CONTRACT as string, - ], - }); const { writeAsync: execute, data: autorenewData } = useContractWrite({ calls: callData, }); @@ -89,8 +80,8 @@ const AutoRenewalModal: FunctionComponent = ({ }, [priceData, priceError]); useEffect(() => { - if (limitPrice === "0") setLimitPrice(price); - }, [address, domain, price, limitPrice]); + if (renewalAllowance === "0") setRenewalAllowance(price); + }, [address, domain, price, renewalAllowance]); // on first load, we generate a salt useEffect(() => { @@ -131,16 +122,6 @@ const AutoRenewalModal: FunctionComponent = ({ })(); }, [usState, salt, email, needMedadata]); - useEffect(() => { - // check approval has been granted to renewal contract - if (approvalError || !approvalData) return; - if ( - approvalData?.["remaining"].low === BigInt(0) && - approvalData?.["remaining"].high === BigInt(0) - ) - setNeedApproval(true); - }, [approvalData, approvalError]); - useEffect(() => { if (isUsResident) { salesTax.getSalesTax("US", usState).then((tax) => { @@ -163,7 +144,7 @@ const AutoRenewalModal: FunctionComponent = ({ txMetadataHash ) ); - }, [needApproval, price, salesTaxRate, metadataHash]); + }, [price, salesTaxRate, metadataHash]); useEffect(() => { if (!autorenewData?.transaction_hash || !salt) return; @@ -233,7 +214,7 @@ const AutoRenewalModal: FunctionComponent = ({ ? `Your domain will be renewed for 1 year on ${timestampToReadableDate( identity.domain_expiry - 2592000 - )} at ${gweiToEth(limitPrice)} ETH.` + )} at ${gweiToEth(renewalAllowance)} ETH.` : null}

diff --git a/components/identities/actions/identityActions.tsx b/components/identities/actions/identityActions.tsx index 988164b6..27083b86 100644 --- a/components/identities/actions/identityActions.tsx +++ b/components/identities/actions/identityActions.tsx @@ -57,7 +57,7 @@ const IdentityActions: FunctionComponent = ({ const [isAutoRenewalOpen, setIsAutoRenewalOpen] = useState(false); const [isAutoRenewalEnabled, setIsAutoRenewalEnabled] = useState(false); - const [limitPrice, setLimitPrice] = useState("0"); + const [allowance, setAllowance] = useState("0"); const [isTxSent, setIsTxSent] = useState(false); const [disableRenewalCalldata, setDisableRenewalCalldata] = useState( [] @@ -120,9 +120,9 @@ const IdentityActions: FunctionComponent = ({ ) .then((response) => response.json()) .then((data) => { - if (!data.error && data.auto_renewal_enabled) { + if (!data.error && data.enabled) { setIsAutoRenewalEnabled(true); - setLimitPrice(data.limit_price); + setAllowance(data.allowance); } else { setIsAutoRenewalEnabled(false); } @@ -144,13 +144,10 @@ const IdentityActions: FunctionComponent = ({ useEffect(() => { if (isAutoRenewalEnabled) { setDisableRenewalCalldata( - registerCalls.disableRenewal( - callDataEncodedDomain[1].toString(), - limitPrice - ) + registerCalls.disableRenewal(callDataEncodedDomain[1].toString()) ); } - }, [limitPrice, isAutoRenewalEnabled]); + }, [allowance, isAutoRenewalEnabled]); useEffect(() => { if (!disableRenewalData?.transaction_hash) return; @@ -328,7 +325,7 @@ const IdentityActions: FunctionComponent = ({ identity={identity} // isEnabled={isAutoRenewalEnabled} domain={identity?.domain} - limit={limitPrice} + allowance={allowance} /> {isTxSent ? (