Skip to content

Commit 0c8b2d1

Browse files
author
Nnenna Okoye
committed
feat: show connected wallet info
1 parent d689516 commit 0c8b2d1

File tree

4 files changed

+92
-1
lines changed

4 files changed

+92
-1
lines changed
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
"use client";
2+
3+
import { useEffect, useState } from "react";
4+
import { Address, zeroAddress } from "viem";
5+
import { useAccount, useReadContract } from "wagmi";
6+
import { UserGroupIcon, CheckCircleIcon, XCircleIcon } from "@heroicons/react/24/solid";
7+
import externalContracts from "~~/contracts/externalContracts";
8+
9+
interface BatchStatusIndicatorsProps {
10+
address?: Address;
11+
}
12+
13+
export const BatchStatusIndicators = ({ address }: BatchStatusIndicatorsProps) => {
14+
const { address: connectedAddress } = useAccount();
15+
const userAddress = address || connectedAddress;
16+
17+
const [isInBatch, setIsInBatch] = useState<boolean | null>(null);
18+
const [isCheckedIn, setIsCheckedIn] = useState<boolean | null>(null);
19+
20+
// Get contract details from externalContracts
21+
const batchRegistryContract = externalContracts[42161]?.BatchRegistry;
22+
23+
// Check if address is in allowList (batch member)
24+
const { data: allowListStatus, isLoading: isLoadingAllowList } = useReadContract(
25+
userAddress && batchRegistryContract ? {
26+
address: batchRegistryContract.address,
27+
abi: batchRegistryContract.abi,
28+
functionName: "allowList",
29+
args: [userAddress],
30+
} : undefined
31+
);
32+
33+
// Check if address has checked in
34+
const { data: contractAddress, isLoading: isLoadingContractAddress } = useReadContract(
35+
userAddress && batchRegistryContract ? {
36+
address: batchRegistryContract.address,
37+
abi: batchRegistryContract.abi,
38+
functionName: "yourContractAddress",
39+
args: [userAddress],
40+
} : undefined
41+
);
42+
43+
44+
45+
useEffect(() => {
46+
if (allowListStatus !== undefined) {
47+
setIsInBatch(!!allowListStatus);
48+
}
49+
50+
if (contractAddress !== undefined) {
51+
setIsCheckedIn(contractAddress !== zeroAddress);
52+
}
53+
}, [allowListStatus, contractAddress]);
54+
55+
if (!userAddress) return null;
56+
57+
const isLoading = isLoadingAllowList || isLoadingContractAddress;
58+
59+
return (
60+
<div className="flex items-center space-x-2 mx-1">
61+
{isLoading ? (
62+
<div className="loading loading-spinner loading-xs"></div>
63+
) : (
64+
<>
65+
{/* Batch Membership Indicator */}
66+
<div className={`tooltip tooltip-bottom ${!isInBatch ? "tooltip-error" : ""}`} data-tip={isInBatch ? "Batch Member" : "Not a Batch Member"}>
67+
<div className={`flex items-center justify-center w-6 h-6 rounded-full ${isInBatch ? "bg-primary/20" : "bg-error/20"}`}>
68+
<UserGroupIcon
69+
className={`h-5 w-5 ${isInBatch ? "text-primary font-bold" : "text-error"}`}
70+
/>
71+
</div>
72+
</div>
73+
74+
{/* Check-in Status Indicator */}
75+
<div className={`tooltip tooltip-bottom ${!isCheckedIn ? "tooltip-error" : ""}`} data-tip={isCheckedIn ? "Checked In" : "Not Checked In"}>
76+
<div className={`flex items-center justify-center w-6 h-6 rounded-full ${isCheckedIn ? "bg-success/20" : "bg-error/20"}`}>
77+
{isCheckedIn ? (
78+
<CheckCircleIcon className="h-4 w-4 text-success" />
79+
) : (
80+
<XCircleIcon className="h-4 w-4 text-error" />
81+
)}
82+
</div>
83+
</div>
84+
</>
85+
)}
86+
</div>
87+
);
88+
};

packages/nextjs/components/scaffold-eth/RainbowKitCustomConnectButton/index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
// @refresh reset
44
import { Balance } from "../Balance";
5+
import { BatchStatusIndicators } from "../BatchStatusIndicators";
56
import { AddressInfoDropdown } from "./AddressInfoDropdown";
67
import { AddressQRCodeModal } from "./AddressQRCodeModal";
78
import { WrongNetworkDropdown } from "./WrongNetworkDropdown";
@@ -49,6 +50,7 @@ export const RainbowKitCustomConnectButton = () => {
4950
{chain.name}
5051
</span>
5152
</div>
53+
<BatchStatusIndicators address={account.address as Address} />
5254
<AddressInfoDropdown
5355
address={account.address as Address}
5456
displayName={account.displayName}

packages/nextjs/components/scaffold-eth/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ export * from "./Faucet";
55
export * from "./FaucetButton";
66
export * from "./Input";
77
export * from "./RainbowKitCustomConnectButton";
8+
export * from "./BatchStatusIndicators";

packages/nextjs/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"lucide-react": "^0.510.0",
2929
"next": "^15.2.3",
3030
"next-nprogress-bar": "^2.3.13",
31-
"next-themes": "^0.3.0",
31+
"next-themes": "^0.3.0",
3232
"qrcode.react": "^4.0.1",
3333
"react": "^19.0.0",
3434
"react-dom": "^19.0.0",

0 commit comments

Comments
 (0)