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

Add front - wagmi #10

Merged
merged 2 commits into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
117 changes: 100 additions & 17 deletions frontend/app/admin/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<main className="flex justify-center items-center flex-col mb-80">
<form id="artistForm" className="flex justify-center items-center gap-4">
<label for="artistName" className="text-2xl">
Artist:
<main className="flex justify-center items-center flex-col mb-60 gap-8">
<form
id="adminForm"
className="flex justify-center items-center flex-col gap-4"
>
<label for="admin" className="text-2xl">
Admin
</label>
<div className="flex gap-4">
<input
type="text"
id="artistName"
name="artistName"
className="text-[#15141a] p-1 rounded"
required
/>
<button
type="submit"
className="bg-[#cef54b] text-[#15141a] rounded p-1"
onClick={createSuperAdmin}
>
Submit
</button>
</div>
</form>

<form
id="artistForm"
className="flex justify-center items-center flex-col gap-4"
>
<label for="artist" className="text-2xl">
Artist
</label>
<input
type="text"
id="artistName"
name="artistName"
className="p-1"
required
/>
<button
type="submit"
className="bg-[#cef54b] text-[#15141a] rounded p-1"
>
Ajouter
</button>
<div className="flex gap-4">
<input
type="text"
id="artistName"
name="artistName"
className="text-[#15141a] p-1 rounded"
required
/>
<button
type="submit"
className="bg-[#cef54b] text-[#15141a] rounded p-1"
>
Submit
</button>
</div>
</form>
</main>
);
Expand Down
Loading
Loading