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 6 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
237 changes: 237 additions & 0 deletions abi/starknet/renewal_abi.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,237 @@
[
{
"data": [
{
"name": "implementation",
"type": "felt"
}
],
"keys": [],
"name": "Upgraded",
"type": "event"
},
{
"data": [
{
"name": "previousAdmin",
"type": "felt"
},
{
"name": "newAdmin",
"type": "felt"
}
],
"keys": [],
"name": "AdminChanged",
"type": "event"
},
{
"data": [
{
"name": "domain",
"type": "felt"
},
{
"name": "renewer",
"type": "felt"
},
{
"name": "value",
"type": "felt"
}
],
"keys": [],
"name": "toggled_renewal",
"type": "event"
},
{
"data": [
{
"name": "domain",
"type": "felt"
},
{
"name": "renewer",
"type": "felt"
},
{
"name": "days",
"type": "felt"
}
],
"keys": [],
"name": "domain_renewed",
"type": "event"
},
{
"data": [
{
"name": "caller",
"type": "felt"
},
{
"name": "upgrade_id",
"type": "felt"
},
{
"name": "implementation_hash",
"type": "felt"
},
{
"name": "vote",
"type": "felt"
}
],
"keys": [],
"name": "voted",
"type": "event"
},
{
"inputs": [
{
"name": "admin",
"type": "felt"
},
{
"name": "naming_address",
"type": "felt"
},
{
"name": "pricing_address",
"type": "felt"
},
{
"name": "erc20_address",
"type": "felt"
}
],
"name": "initializer",
"outputs": [],
"type": "function"
},
{
"inputs": [
{
"name": "domain",
"type": "felt"
},
{
"name": "renewer",
"type": "felt"
}
],
"name": "is_renewing",
"outputs": [
{
"name": "res",
"type": "felt"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"name": "user",
"type": "felt"
},
{
"name": "upgrade_id",
"type": "felt"
},
{
"name": "implementation_hash",
"type": "felt"
}
],
"name": "has_voted_upgrade",
"outputs": [
{
"name": "res",
"type": "felt"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"name": "domain",
"type": "felt"
}
],
"name": "toggle_renewals",
"outputs": [],
"type": "function"
},
{
"inputs": [
{
"name": "root_domain",
"type": "felt"
},
{
"name": "renewer",
"type": "felt"
}
],
"name": "renew",
"outputs": [],
"type": "function"
},
{
"inputs": [
{
"name": "domain_len",
"type": "felt"
},
{
"name": "domain",
"type": "felt*"
},
{
"name": "renewer_len",
"type": "felt"
},
{
"name": "renewer",
"type": "felt*"
}
],
"name": "batch_renew",
"outputs": [],
"type": "function"
},
{
"inputs": [
{
"name": "upgrade_id",
"type": "felt"
},
{
"name": "implementation_hash",
"type": "felt"
}
],
"name": "vote_upgrade",
"outputs": [],
"type": "function"
},
{
"inputs": [
{
"name": "upgrade_id",
"type": "felt"
},
{
"name": "implementation_hash",
"type": "felt"
}
],
"name": "upgrade",
"outputs": [],
"type": "function"
}
]
139 changes: 139 additions & 0 deletions components/identities/actions/autoRenewalModal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
import { Modal, TextField } from "@mui/material";
import { useContractRead, useContractWrite } from "@starknet-react/core";
import BN from "bn.js";
import React, { FunctionComponent, useEffect, useState } from "react";
import { usePricingContract } from "../../../hooks/contracts";
import styles from "../../../styles/components/wallets.module.css";
import styles2 from "../../../styles/Home.module.css";
Copy link
Contributor

Choose a reason for hiding this comment

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

Rename homeStyles instead of styles2

import Button from "../../UI/button";
import { timestampToReadableDate } from "../../../utils/dateService";
import { Abi } from "starknet";

type AutoRenewalModalProps = {
handleClose: () => void;
isModalOpen: boolean;
callDataEncodedDomain: (number | string)[];
identity?: Identity;
isEnabled?: boolean;
};

const AutoRenewalModal: FunctionComponent<AutoRenewalModalProps> = ({
handleClose,
isModalOpen,
callDataEncodedDomain,
identity,
isEnabled,
}) => {
const [price, setPrice] = useState<string>("0");
const { contract: pricingContract } = usePricingContract();
const { data: priceData, error: priceError } = useContractRead({
address: pricingContract?.address as string,
abi: pricingContract?.abi as Abi,
functionName: "compute_renew_price",
args: [callDataEncodedDomain[1], 365],
});

useEffect(() => {
if (priceError || !priceData) setPrice("0");
else {
setPrice(
priceData?.["price"].low
.add(priceData?.["price"].high.mul(new BN(2).pow(new BN(128))))
.toString(10)
);
}
}, [priceData, priceError]);

const renew_calls = [
{
contractAddress: process.env.NEXT_PUBLIC_ETHER_CONTRACT as string,
entrypoint: "approve",
calldata: [
process.env.NEXT_PUBLIC_RENEWAL_CONTRACT as string,
isEnabled ? 0 : price,
0,
],
},
{
contractAddress: process.env.NEXT_PUBLIC_RENEWAL_CONTRACT as string,
entrypoint: "toggle_renewals",
calldata: [callDataEncodedDomain[1]],
},
];

const { writeAsync: enableAutoRenewal } = useContractWrite({
calls: renew_calls,
});

return (
<Modal
disableAutoFocus
open={isModalOpen}
onClose={handleClose}
aria-labelledby="modal-modal-title"
aria-describedby="modal-modal-description"
>
<div className={styles.menu}>
<button className={styles.menu_close} onClick={handleClose}>
<svg viewBox="0 0 24 24">
<path
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth="2"
d="M6 18L18 6M6 6l12 12"
></path>
</svg>
</button>
<p className={styles.menu_title}>
{isEnabled ? "Disable" : "Enable"} auto renewal for {identity?.domain}
</p>
<p className="break-all mt-5">
To avoid loosing your domain, you can enable auto renewals so your
domain is renewed automatically. Auto renewals happen one month before
your expiry date is reached.
</p>
Copy link
Contributor

Choose a reason for hiding this comment

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

Change text to

Avoid losing your domain and renew it automatically each year one month before it expires! (You can disable this option when you want.)

<div className="mt-5 flex flex-col justify-center">
{identity?.domain_expiry && (
<p className="break-all">
<strong>Expiry date :</strong>&nbsp;
<span>
{timestampToReadableDate(identity?.domain_expiry ?? 0)}
</span>
</p>
)}
{identity?.domain_expiry && (
<p className="break-all">
<strong>Auto renewal date :</strong>&nbsp;
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you make it really strong using the className strong in global.css ? Because right now it's not bold

<span>
{timestampToReadableDate(
identity?.domain_expiry - 2592000 ?? 0
)}
</span>
</p>
)}
Copy link
Contributor

Choose a reason for hiding this comment

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

Here you can show the price like so:

            <p className="break-all">
              <strong>Price :</strong>&nbsp;
              <span>
                {price}/year
              </span>
            </p>

<div className={styles2.cardCenter}>
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this is useful.

Capture d’écran 2023-05-28 à 18 47 02

<p className="text">
Price :&nbsp;
<span className="font-semibold text-brown">
{Math.round(Number(price) * 0.000000000000000001 * 10000) /
10000}
&nbsp; ETH
</span>
</p>
</div>
<div className="mt-5 flex justify-center">
<Button
onClick={() => {
enableAutoRenewal();
}}
>
{isEnabled ? "Disable" : "Enable"} auto renewal
</Button>
</div>
</div>
</div>
</Modal>
);
};

export default AutoRenewalModal;
Loading