Skip to content

Commit

Permalink
Merge pull request #15 from melanke/batch11-badges
Browse files Browse the repository at this point in the history
Showing badges for members - for issue #5
  • Loading branch information
phipsae authored Nov 23, 2024
2 parents 5c0359d + bb37d1e commit 33eb3cf
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
5 changes: 5 additions & 0 deletions packages/nextjs/components/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import React, { useCallback, useRef, useState } from "react";
import Image from "next/image";
import Link from "next/link";
import { usePathname } from "next/navigation";
import { UserBadges } from "./UserBadges";
import { useAccount } from "wagmi";
import { Bars3Icon, BugAntIcon } from "@heroicons/react/24/outline";
import { FaucetButton, RainbowKitCustomConnectButton } from "~~/components/scaffold-eth";
import { useOutsideClick } from "~~/hooks/scaffold-eth";
Expand Down Expand Up @@ -58,6 +60,8 @@ export const HeaderMenuLinks = () => {
export const Header = () => {
const [isDrawerOpen, setIsDrawerOpen] = useState(false);
const burgerMenuRef = useRef<HTMLDivElement>(null);
const { isConnected } = useAccount();

useOutsideClick(
burgerMenuRef,
useCallback(() => setIsDrawerOpen(false), []),
Expand Down Expand Up @@ -102,6 +106,7 @@ export const Header = () => {
</ul>
</div>
<div className="navbar-end flex-grow mr-4">
{isConnected && <UserBadges />}
<RainbowKitCustomConnectButton />
<FaucetButton />
</div>
Expand Down
39 changes: 39 additions & 0 deletions packages/nextjs/components/UserBadges.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { useAccount } from "wagmi";
import { BookmarkSquareIcon, IdentificationIcon, SignalSlashIcon } from "@heroicons/react/24/outline";
import { useScaffoldReadContract } from "~~/hooks/scaffold-eth";

export const UserBadges = () => {
const { address } = useAccount();

const { data: isBuilderOfBatch11 } = useScaffoldReadContract({
contractName: "BatchRegistry",
functionName: "allowList",
args: [address],
});

const { data: contractAddress } = useScaffoldReadContract({
contractName: "BatchRegistry",
functionName: "yourContractAddress",
args: [address],
});

const madeCheckin = contractAddress && contractAddress !== "0x0000000000000000000000000000000000000000";

return (
<div className="flex gap-2 mr-2">
{madeCheckin ? (
<div className="tooltip tooltip-bottom" data-tip="A builder of batch 11 with confirmed checkin">
<BookmarkSquareIcon className="h-7 w-7 p-1 bg-secondary-content text-secondary rounded-full" />
</div>
) : isBuilderOfBatch11 ? (
<div className="tooltip tooltip-bottom" data-tip="A builder of batch 11">
<IdentificationIcon className="h-7 w-7 p-1 bg-secondary-content text-secondary rounded-full" />
</div>
) : (
<div className="tooltip tooltip-bottom" data-tip="Not a builder of batch 11">
<SignalSlashIcon className="h-7 w-7 p-1 opacity-50" />
</div>
)}
</div>
);
};

0 comments on commit 33eb3cf

Please sign in to comment.