diff --git a/frontend/app/admin/page.js b/frontend/app/admin/page.js index 5ce8a58..783d1c1 100644 --- a/frontend/app/admin/page.js +++ b/frontend/app/admin/page.js @@ -14,26 +14,109 @@ import { parseAbiItem } from "viem"; import { usePublicClient } from "wagmi"; import { hardhat } from "viem/chains"; +// Contract's information +import { AdminsABI, contractAddressAdmins } from "@/constants/index"; + const admin = () => { + // Admin Information + + const [superAdmin, setSuperAdmin] = useState(""); + + // Wagmi function / client creation for event listenning + const client = usePublicClient(); + + // Event information + const [grantedEvents, setGrantedEvents] = useState([]); + + // Event handling function + const getGrantedEvents = async () => { + try { + // get.Logs from viem + const logs = await client.getLogs({ + address: contractAddressAdmins, + event: parseAbiItem( + "event Granted (address from, address to, Role role,address contractt);" + ), + fromBlock: 0n, + toBlock: "latest", + }); + + setGrantedEvents(logs.map((log) => log.args.from)); + toast.success("Admin Created"); + } catch (err) { + toast.error(err.message); + } + }; + + const createSuperAdmin = async () => { + try { + const { request } = await prepareWriteContract({ + address: contractAddressAdmins, + abi: AdminsABI, + functionName: "addSuperAdmin", + args: [_addr], + }); + + const { hash } = await writeContract(request); + const data = await waitForTransaction({ + hash: hash, + }); + + getGrantedEvents(); + } catch (err) { + toast.error(err.message); + } + }; + return ( -
-
-