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

Added member status to the home page #24

Merged
merged 10 commits into from
Nov 4, 2024
83 changes: 72 additions & 11 deletions packages/nextjs/app/page.tsx
phipsae marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,46 @@

import Link from "next/link";
import type { NextPage } from "next";
import { useAccount } from "wagmi";
import { BugAntIcon, MagnifyingGlassIcon } from "@heroicons/react/24/outline";
import { useScaffoldReadContract } from "~~/hooks/scaffold-eth";

const Home: NextPage = () => {
const { address: connectedAddress } = useAccount();

const {
data: checkedInCounter,
error,
isLoading: contractLoading,
error: counterError,
isLoading: counterLoading,
} = useScaffoldReadContract({
contractName: "BatchRegistry",
functionName: "checkedInCounter",
});

const {
data: isAllowListed,
error: allowListError,
isLoading: allowListLoading,
} = useScaffoldReadContract({
contractName: "BatchRegistry",
functionName: "allowList",
args: [connectedAddress],
});

const {
data: userContractAddress,
error: checkInError,
isLoading: checkInLoading,
} = useScaffoldReadContract({
contractName: "BatchRegistry",
functionName: "yourContractAddress",
args: [connectedAddress],
});

const error = counterError || allowListError || checkInError;
const isLoading = counterLoading || allowListLoading || checkInLoading;
const isCheckedIn = userContractAddress && userContractAddress !== "0x0000000000000000000000000000000000000000";

return (
<>
<div className="flex items-center flex-col flex-grow pt-10">
Expand All @@ -30,16 +57,50 @@ const Home: NextPage = () => {
<p>Error fetching contract data: {error.message}</p>
</div>
) : (
<div className="text-lg flex gap-2 justify-center">
<span className="font-bold">Checked in builders count:</span>
{contractLoading ? (
<span className="animate-pulse">
<div className="h-6 bg-gray-200 rounded w-12"></div>
</span>
) : (
<span>{checkedInCounter !== undefined ? Number(checkedInCounter) : "0"}</span>
<>
<div className="text-lg flex gap-2 justify-center mb-4">
<span className="font-bold">Checked in builders count:</span>
{counterLoading ? (
<span className="animate-pulse">
<div className="h-6 bg-gray-200 rounded w-12"></div>
</span>
) : (
<span>{checkedInCounter !== undefined ? Number(checkedInCounter) : "0"}</span>
)}
</div>

{connectedAddress && (
<div className="mt-6 p-4 rounded-lg bg-base-200">
<h2 className="text-xl font-bold mb-3">Your Status</h2>
{isLoading ? (
<div className="space-y-2">
<div className="h-6 bg-gray-200 rounded w-48 animate-pulse" />
<div className="h-6 bg-gray-200 rounded w-36 animate-pulse" />
</div>
) : (
<div className="space-y-2">
<div className="flex items-center gap-2">
<div className={`w-3 h-3 rounded-full ${isAllowListed ? "bg-green-500" : "bg-red-500"}`} />
<span>
{isAllowListed ? "You are a member of Batch 10" : "You are not a member of Batch 10"}
</span>
</div>
<div className="flex items-center gap-2">
<div className={`w-3 h-3 rounded-full ${isCheckedIn ? "bg-green-500" : "bg-yellow-500"}`} />
<span>
{isCheckedIn
? `Checked in with contract: ${userContractAddress?.slice(
0,
6,
)}...${userContractAddress?.slice(-4)}`
: "Not checked in yet"}
</span>
</div>
</div>
)}
</div>
)}
</div>
</>
)}
</div>

Expand Down
Loading