|
| 1 | +"use client"; |
| 2 | + |
| 3 | +import { zeroAddress } from "viem"; |
| 4 | +import { useAccount } from "wagmi"; |
| 5 | +import { CheckCircleIcon, UserGroupIcon, XCircleIcon } from "@heroicons/react/24/solid"; |
| 6 | +import { useScaffoldReadContract } from "~~/hooks/scaffold-eth"; |
| 7 | + |
| 8 | +export const BatchStatusIndicators = () => { |
| 9 | + const { address: userAddress } = useAccount(); |
| 10 | + |
| 11 | + // Check if address is in allowList (batch member) |
| 12 | + const { data: allowListStatus, isLoading: isLoadingAllowList } = useScaffoldReadContract({ |
| 13 | + contractName: "BatchRegistry", |
| 14 | + functionName: "allowList", |
| 15 | + args: [userAddress ?? zeroAddress], |
| 16 | + chainId: 42161, |
| 17 | + }); |
| 18 | + |
| 19 | + // Check if address has checked in |
| 20 | + const { data: contractAddress, isLoading: isLoadingContractAddress } = useScaffoldReadContract({ |
| 21 | + contractName: "BatchRegistry", |
| 22 | + functionName: "yourContractAddress", |
| 23 | + args: [userAddress ?? zeroAddress], |
| 24 | + chainId: 42161, |
| 25 | + }); |
| 26 | + |
| 27 | + const isInBatch = !!allowListStatus; |
| 28 | + const isCheckedIn = contractAddress && contractAddress !== zeroAddress; |
| 29 | + |
| 30 | + if (!userAddress) return null; |
| 31 | + |
| 32 | + const isLoading = isLoadingAllowList || isLoadingContractAddress; |
| 33 | + |
| 34 | + return ( |
| 35 | + <div className="flex items-center space-x-2 mx-1"> |
| 36 | + {isLoading ? ( |
| 37 | + <div className="loading loading-spinner loading-xs"></div> |
| 38 | + ) : ( |
| 39 | + <> |
| 40 | + {/* Batch Membership Indicator */} |
| 41 | + <div |
| 42 | + className={`tooltip tooltip-bottom ${!isInBatch ? "tooltip-error" : ""}`} |
| 43 | + data-tip={isInBatch ? "Batch Member" : "Not a Batch Member"} |
| 44 | + > |
| 45 | + <div |
| 46 | + className={`flex items-center justify-center w-6 h-6 rounded-full ${isInBatch ? "bg-primary/20" : "bg-error/20"}`} |
| 47 | + > |
| 48 | + <UserGroupIcon className={`h-5 w-5 ${isInBatch ? "text-primary font-bold" : "text-error"}`} /> |
| 49 | + </div> |
| 50 | + </div> |
| 51 | + |
| 52 | + {/* Check-in Status Indicator */} |
| 53 | + <div |
| 54 | + className={`tooltip tooltip-bottom ${!isCheckedIn ? "tooltip-error" : ""}`} |
| 55 | + data-tip={isCheckedIn ? "Checked In" : "Not Checked In"} |
| 56 | + > |
| 57 | + <div |
| 58 | + className={`flex items-center justify-center w-6 h-6 rounded-full ${isCheckedIn ? "bg-success/20" : "bg-error/20"}`} |
| 59 | + > |
| 60 | + {isCheckedIn ? ( |
| 61 | + <CheckCircleIcon className="h-4 w-4 text-success" /> |
| 62 | + ) : ( |
| 63 | + <XCircleIcon className="h-4 w-4 text-error" /> |
| 64 | + )} |
| 65 | + </div> |
| 66 | + </div> |
| 67 | + </> |
| 68 | + )} |
| 69 | + </div> |
| 70 | + ); |
| 71 | +}; |
0 commit comments