From e9d1267584123e2f838769fa0c626bbc7b3f4fff Mon Sep 17 00:00:00 2001 From: Lukman-01 Date: Fri, 25 Oct 2024 10:08:49 +0100 Subject: [PATCH] Added member status to the home page --- packages/nextjs/app/page.tsx | 83 +++++++++++++++++++++++++++++++----- 1 file changed, 72 insertions(+), 11 deletions(-) diff --git a/packages/nextjs/app/page.tsx b/packages/nextjs/app/page.tsx index 2ba44ec..3fc2828 100644 --- a/packages/nextjs/app/page.tsx +++ b/packages/nextjs/app/page.tsx @@ -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 ( <>
@@ -30,16 +57,50 @@ const Home: NextPage = () => {

Error fetching contract data: {error.message}

) : ( -
- Checked in builders count: - {contractLoading ? ( - -
-
- ) : ( - {checkedInCounter !== undefined ? Number(checkedInCounter) : "0"} + <> +
+ Checked in builders count: + {counterLoading ? ( + +
+
+ ) : ( + {checkedInCounter !== undefined ? Number(checkedInCounter) : "0"} + )} +
+ + {connectedAddress && ( +
+

Your Status

+ {isLoading ? ( +
+
+
+
+ ) : ( +
+
+
+ + {isAllowListed ? "You are a member of Batch 10" : "You are not a member of Batch 10"} + +
+
+
+ + {isCheckedIn + ? `Checked in with contract: ${userContractAddress?.slice( + 0, + 6, + )}...${userContractAddress?.slice(-4)}` + : "Not checked in yet"} + +
+
+ )} +
)} -
+ )}