-
Notifications
You must be signed in to change notification settings - Fork 73
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
Changes from 6 commits
1de7bb6
8ff2af4
b306ad5
7eeaaa2
0fb5c2f
9f631a6
3694c25
7bdd1cf
2e5f981
20de379
bea6bdb
617c8a9
a01e439
5375598
adec78a
237be56
baa697a
e15d9e2
5596149
eeb59d4
97fa6e5
428a408
86212ac
56db0d5
456af20
b11e7e1
f82baef
85558d6
3740150
7afa8b0
4c2b728
2849259
2260882
b15b794
aa42228
b685578
8ecd3ea
afe8762
9783924
6a30e73
8e9339a
f81cb3f
9415a1f
9e65b7d
6cea34c
bcaff5c
8863cd9
59488b0
4207628
b9a37da
e357ff2
408d4b9
31dd9dc
1a1270e
890a241
e0f3c74
bc2cf95
8838f7c
8282500
ccc0180
4661e6a
9ce54ff
6cc7956
a7d39b8
a0f3278
99331c5
d4a56ec
e1f7a23
41aa43e
fcfcd87
493b4e5
bdb10ae
c84623d
ea982b3
1d5fca6
d8524cf
ab9b131
0b22a58
eae84e8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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" | ||
} | ||
] |
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"; | ||
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> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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> | ||
<span> | ||
{timestampToReadableDate(identity?.domain_expiry ?? 0)} | ||
</span> | ||
</p> | ||
)} | ||
{identity?.domain_expiry && ( | ||
<p className="break-all"> | ||
<strong>Auto renewal date :</strong> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you make it really strong using the className strong in |
||
<span> | ||
{timestampToReadableDate( | ||
identity?.domain_expiry - 2592000 ?? 0 | ||
)} | ||
</span> | ||
</p> | ||
)} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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>
<span>
{price}/year
</span>
</p> |
||
<div className={styles2.cardCenter}> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
<p className="text"> | ||
Price : | ||
<span className="font-semibold text-brown"> | ||
{Math.round(Number(price) * 0.000000000000000001 * 10000) / | ||
10000} | ||
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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename
homeStyles
instead ofstyles2