From dcd98760698b81a5d3c778ab7bf0690b43bf8ba2 Mon Sep 17 00:00:00 2001 From: arjanjohan <84233757+arjanjohan@users.noreply.github.com> Date: Thu, 19 Sep 2024 22:39:23 +0200 Subject: [PATCH] Issue 6: Add batch details in header (#20) Co-authored-by: danieltomefernandez --- .../BatchDetails.tsx | 58 +++++++++++++++++++ .../RainbowKitCustomConnectButton/index.tsx | 4 ++ 2 files changed, 62 insertions(+) create mode 100644 packages/nextjs/components/scaffold-eth/RainbowKitCustomConnectButton/BatchDetails.tsx diff --git a/packages/nextjs/components/scaffold-eth/RainbowKitCustomConnectButton/BatchDetails.tsx b/packages/nextjs/components/scaffold-eth/RainbowKitCustomConnectButton/BatchDetails.tsx new file mode 100644 index 0000000..b08b1aa --- /dev/null +++ b/packages/nextjs/components/scaffold-eth/RainbowKitCustomConnectButton/BatchDetails.tsx @@ -0,0 +1,58 @@ +import { Address } from "viem"; +import { useScaffoldReadContract } from "~~/hooks/scaffold-eth"; + +type BatchProps = { + address: Address; +}; + +const TEXT_COMBINATIONS: Record = { + CHECKED_IN: { title: "", message: "You are an up to date builder🥇" }, + NOT_CHECKED_IN: { title: "Hey builder 🏗️!", message: "Remember to check in :)" }, + NOT_ALLOWED: { title: "Oops!", message: "Reach us to be a builder" }, +}; + +type Text = { + title: string; + message: string; +}; + +const zeroAddress = "0x0000000000000000000000000000000000000000"; + +export const BatchDetails = ({ address }: BatchProps) => { + const { data: isAllowListed, isLoading: allowListLoading } = useScaffoldReadContract({ + contractName: "BatchRegistry", + functionName: "allowList", + args: [address], + }); + + const { data: checkedIn, isLoading: checkedInLoading } = useScaffoldReadContract({ + contractName: "BatchRegistry", + functionName: "yourContractAddress", + args: [address], + }); + + const hasCheckedIn = zeroAddress !== checkedIn; + + const getTextToShow = (): Text => { + switch (true) { + case !isAllowListed: + return TEXT_COMBINATIONS.NOT_ALLOWED; + case hasCheckedIn: + return TEXT_COMBINATIONS.CHECKED_IN; + default: + return TEXT_COMBINATIONS.NOT_CHECKED_IN; + } + }; + const textToShow = getTextToShow(); + + if (allowListLoading || checkedInLoading) { + return null; + } + + return ( +
+

{textToShow.title}

+

{textToShow.message}

+
+ ); +}; diff --git a/packages/nextjs/components/scaffold-eth/RainbowKitCustomConnectButton/index.tsx b/packages/nextjs/components/scaffold-eth/RainbowKitCustomConnectButton/index.tsx index 6521200..8dce607 100644 --- a/packages/nextjs/components/scaffold-eth/RainbowKitCustomConnectButton/index.tsx +++ b/packages/nextjs/components/scaffold-eth/RainbowKitCustomConnectButton/index.tsx @@ -4,6 +4,7 @@ import { Balance } from "../Balance"; import { AddressInfoDropdown } from "./AddressInfoDropdown"; import { AddressQRCodeModal } from "./AddressQRCodeModal"; +import { BatchDetails } from "./BatchDetails"; import { WrongNetworkDropdown } from "./WrongNetworkDropdown"; import { ConnectButton } from "@rainbow-me/rainbowkit"; import { Address } from "viem"; @@ -43,6 +44,9 @@ export const RainbowKitCustomConnectButton = () => { return ( <> +
+ +