Skip to content
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
71 changes: 71 additions & 0 deletions packages/nextjs/components/BatchStatusIndicators.tsx
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, it’s almost perfect!
There’s just a small problem:
The content is overflowing the page’s width. Now, with the addition of your component, the page has an unnecessary horizontal scrollbar.
Maybe this is happening because of the tooltips, but that’s just a guess.
You can try different ways to fix it, but I believe you could either tweak the tooltip position or move the badges to the left of the connect button.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed, please review

Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
"use client";

import { zeroAddress } from "viem";
import { useAccount } from "wagmi";
import { CheckCircleIcon, UserGroupIcon, XCircleIcon } from "@heroicons/react/24/solid";
import { useScaffoldReadContract } from "~~/hooks/scaffold-eth";

export const BatchStatusIndicators = () => {
const { address: userAddress } = useAccount();

// Check if address is in allowList (batch member)
const { data: allowListStatus, isLoading: isLoadingAllowList } = useScaffoldReadContract({
contractName: "BatchRegistry",
functionName: "allowList",
args: [userAddress ?? zeroAddress],
chainId: 42161,
});

// Check if address has checked in
const { data: contractAddress, isLoading: isLoadingContractAddress } = useScaffoldReadContract({
contractName: "BatchRegistry",
functionName: "yourContractAddress",
args: [userAddress ?? zeroAddress],
chainId: 42161,
});

const isInBatch = !!allowListStatus;
const isCheckedIn = contractAddress && contractAddress !== zeroAddress;

if (!userAddress) return null;

const isLoading = isLoadingAllowList || isLoadingContractAddress;

return (
<div className="flex items-center space-x-2 mx-1">
{isLoading ? (
<div className="loading loading-spinner loading-xs"></div>
) : (
<>
{/* Batch Membership Indicator */}
<div
className={`tooltip tooltip-bottom ${!isInBatch ? "tooltip-error" : ""}`}
data-tip={isInBatch ? "Batch Member" : "Not a Batch Member"}
>
<div
className={`flex items-center justify-center w-6 h-6 rounded-full ${isInBatch ? "bg-primary/20" : "bg-error/20"}`}
>
<UserGroupIcon className={`h-5 w-5 ${isInBatch ? "text-primary font-bold" : "text-error"}`} />
</div>
</div>

{/* Check-in Status Indicator */}
<div
className={`tooltip tooltip-bottom ${!isCheckedIn ? "tooltip-error" : ""}`}
data-tip={isCheckedIn ? "Checked In" : "Not Checked In"}
>
<div
className={`flex items-center justify-center w-6 h-6 rounded-full ${isCheckedIn ? "bg-success/20" : "bg-error/20"}`}
>
{isCheckedIn ? (
<CheckCircleIcon className="h-4 w-4 text-success" />
) : (
<XCircleIcon className="h-4 w-4 text-error" />
)}
</div>
</div>
</>
)}
</div>
);
};
6 changes: 5 additions & 1 deletion packages/nextjs/components/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import Link from "next/link";
import { usePathname } from "next/navigation";
import { hardhat } from "viem/chains";
import { Bars3Icon, BugAntIcon, UserGroupIcon } from "@heroicons/react/24/outline";
import { BatchStatusIndicators } from "~~/components/BatchStatusIndicators";
import { FaucetButton, RainbowKitCustomConnectButton } from "~~/components/scaffold-eth";
import { useOutsideClick, useTargetNetwork } from "~~/hooks/scaffold-eth";

Expand Down Expand Up @@ -100,7 +101,10 @@ export const Header = () => {
</ul>
</div>
<div className="navbar-end grow mr-4">
<RainbowKitCustomConnectButton />
<div className="flex items-center gap-2">
<BatchStatusIndicators />
<RainbowKitCustomConnectButton />
</div>
{isLocalNetwork && <FaucetButton />}
</div>
</div>
Expand Down