Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 6 - Resolve Show connected wallet info #23

Closed
Closed
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
4 changes: 4 additions & 0 deletions packages/nextjs/components/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import React, { useCallback, useRef, useState } from "react";
import Image from "next/image";
import Link from "next/link";
import { usePathname } from "next/navigation";
import { BatchWalletInfo } from "./scaffold-eth/BatchWalletInfo";
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 @@ -101,6 +102,9 @@ export const Header = () => {
<HeaderMenuLinks />
</ul>
</div>
<div className="flex justify-center">
<BatchWalletInfo />
</div>
<div className="navbar-end flex-grow mr-4">
<RainbowKitCustomConnectButton />
<FaucetButton />
Expand Down
44 changes: 44 additions & 0 deletions packages/nextjs/components/scaffold-eth/BatchWalletInfo.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { useAccount } from "wagmi";
import { useScaffoldReadContract } from "~~/hooks/scaffold-eth";

type Text = {
title: string;
message: string;
};

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

const { data: isAllowed } = useScaffoldReadContract({
contractName: "BatchRegistry",
functionName: "allowList",
args: [address?.toString()],
});
const { data: checkedIn } = useScaffoldReadContract({
contractName: "BatchRegistry",
functionName: "yourContractAddress",
args: [address?.toString()],
});

if (address == undefined) {
return;
}

const hasCheckedIn = "0x0000000000000000000000000000000000000000" != checkedIn;

let textToShow: Text = { title: "", message: "" };
if (isAllowed && hasCheckedIn) {
textToShow = { title: "", message: "You are an up to date builder🥇 " };
} else if (isAllowed && !hasCheckedIn) {
textToShow = { title: "Hey builder 🏗️!", message: "Remember to checkIn :)" };
} else if ((!isAllowed && !hasCheckedIn) || (!isAllowed && hasCheckedIn)) {
textToShow = { title: "Oops!", message: "Reach us to be a builder" };
}

return (
<div className="bg-base-300 p-4 rounded shadow-lg">
<p className="text-lg m-0">{textToShow.title}</p>
<p className="text-sm m-0">{textToShow.message}</p>
</div>
);
};