From 78f6dab8cc49e28631e2d84823358ebd5d70e6b0 Mon Sep 17 00:00:00 2001 From: arjanjohan Date: Wed, 11 Sep 2024 20:18:58 +0200 Subject: [PATCH 1/4] batch details in header --- .../BatchDetails.tsx | 36 +++++++++++++++++++ .../RainbowKitCustomConnectButton/index.tsx | 4 +++ 2 files changed, 40 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..ee84558 --- /dev/null +++ b/packages/nextjs/components/scaffold-eth/RainbowKitCustomConnectButton/BatchDetails.tsx @@ -0,0 +1,36 @@ +import { Address } from "viem"; +import { useScaffoldReadContract } from "~~/hooks/scaffold-eth"; + +type BatchProps = { + address: Address; +}; + +const zeroAddress = "0x0000000000000000000000000000000000000000"; + +export const BatchDetails = ({ address }: BatchProps) => { + console.log(address); + + const { data: allowListed, isLoading: allowListLoading } = useScaffoldReadContract({ + contractName: "BatchRegistry", + functionName: "allowList", + args: [address], + }); + + const { data: checkedIn, isLoading: checkedInLoading } = useScaffoldReadContract({ + contractName: "BatchRegistry", + functionName: "yourContractAddress", + args: [address], + }); + console.log(allowListed, checkedIn); + + return ( + <> + {!allowListLoading && !checkedInLoading && ( +
+ {allowListed ?

✅ Allow Listed

:

❌ Not Allow Listed

}
+ {checkedIn != zeroAddress ?

✅ Checked in

:

❌ Not checked in

}
+
+ )} + + ); +}; 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 ( <> +
+ +
From 2209f96017e4ed7ce7d1a6b253399aa2e7eb21ce Mon Sep 17 00:00:00 2001 From: arjanjohan Date: Thu, 12 Sep 2024 09:46:38 +0200 Subject: [PATCH 2/4] remove console.log --- .../RainbowKitCustomConnectButton/BatchDetails.tsx | 3 --- 1 file changed, 3 deletions(-) diff --git a/packages/nextjs/components/scaffold-eth/RainbowKitCustomConnectButton/BatchDetails.tsx b/packages/nextjs/components/scaffold-eth/RainbowKitCustomConnectButton/BatchDetails.tsx index ee84558..e2b6956 100644 --- a/packages/nextjs/components/scaffold-eth/RainbowKitCustomConnectButton/BatchDetails.tsx +++ b/packages/nextjs/components/scaffold-eth/RainbowKitCustomConnectButton/BatchDetails.tsx @@ -8,8 +8,6 @@ type BatchProps = { const zeroAddress = "0x0000000000000000000000000000000000000000"; export const BatchDetails = ({ address }: BatchProps) => { - console.log(address); - const { data: allowListed, isLoading: allowListLoading } = useScaffoldReadContract({ contractName: "BatchRegistry", functionName: "allowList", @@ -21,7 +19,6 @@ export const BatchDetails = ({ address }: BatchProps) => { functionName: "yourContractAddress", args: [address], }); - console.log(allowListed, checkedIn); return ( <> From ad5e062e0eb4092a52ad603111255a2aaf443014 Mon Sep 17 00:00:00 2001 From: danieltomefernandez Date: Tue, 17 Sep 2024 21:06:12 +0200 Subject: [PATCH 3/4] Added a single message depending on state --- .../BatchDetails.tsx | 37 ++++++++++++++----- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/packages/nextjs/components/scaffold-eth/RainbowKitCustomConnectButton/BatchDetails.tsx b/packages/nextjs/components/scaffold-eth/RainbowKitCustomConnectButton/BatchDetails.tsx index e2b6956..f9e8b33 100644 --- a/packages/nextjs/components/scaffold-eth/RainbowKitCustomConnectButton/BatchDetails.tsx +++ b/packages/nextjs/components/scaffold-eth/RainbowKitCustomConnectButton/BatchDetails.tsx @@ -5,10 +5,15 @@ type BatchProps = { address: Address; }; +type Text = { + title: string; + message: string; +}; + const zeroAddress = "0x0000000000000000000000000000000000000000"; export const BatchDetails = ({ address }: BatchProps) => { - const { data: allowListed, isLoading: allowListLoading } = useScaffoldReadContract({ + const { data: isAllowListed, isLoading: allowListLoading } = useScaffoldReadContract({ contractName: "BatchRegistry", functionName: "allowList", args: [address], @@ -20,14 +25,28 @@ export const BatchDetails = ({ address }: BatchProps) => { args: [address], }); + const hasCheckedIn = zeroAddress !== checkedIn; + + const getTextToShow = (): Text => { + if (isAllowListed) { + if (hasCheckedIn) { + return { title: "", message: "You are an up to date builder🥇" }; + } + return { title: "Hey builder 🏗️!", message: "Remember to check in :)" }; + } + return { title: "Oops!", message: "Reach us to be a builder" }; + }; + + const textToShow = getTextToShow(); + + if (allowListLoading || checkedInLoading) { + return null; + } + return ( - <> - {!allowListLoading && !checkedInLoading && ( -
- {allowListed ?

✅ Allow Listed

:

❌ Not Allow Listed

}
- {checkedIn != zeroAddress ?

✅ Checked in

:

❌ Not checked in

}
-
- )} - +
+

{textToShow.title}

+

{textToShow.message}

+
); }; From 202c4d42ec9d4429feb5c66f2230f53f634442b6 Mon Sep 17 00:00:00 2001 From: arjanjohan Date: Wed, 18 Sep 2024 09:06:23 +0200 Subject: [PATCH 4/4] clean code --- .../BatchDetails.tsx | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/packages/nextjs/components/scaffold-eth/RainbowKitCustomConnectButton/BatchDetails.tsx b/packages/nextjs/components/scaffold-eth/RainbowKitCustomConnectButton/BatchDetails.tsx index f9e8b33..b08b1aa 100644 --- a/packages/nextjs/components/scaffold-eth/RainbowKitCustomConnectButton/BatchDetails.tsx +++ b/packages/nextjs/components/scaffold-eth/RainbowKitCustomConnectButton/BatchDetails.tsx @@ -5,6 +5,12 @@ 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; @@ -28,15 +34,15 @@ export const BatchDetails = ({ address }: BatchProps) => { const hasCheckedIn = zeroAddress !== checkedIn; const getTextToShow = (): Text => { - if (isAllowListed) { - if (hasCheckedIn) { - return { title: "", message: "You are an up to date builder🥇" }; - } - return { title: "Hey builder 🏗️!", message: "Remember to check in :)" }; + switch (true) { + case !isAllowListed: + return TEXT_COMBINATIONS.NOT_ALLOWED; + case hasCheckedIn: + return TEXT_COMBINATIONS.CHECKED_IN; + default: + return TEXT_COMBINATIONS.NOT_CHECKED_IN; } - return { title: "Oops!", message: "Reach us to be a builder" }; }; - const textToShow = getTextToShow(); if (allowListLoading || checkedInLoading) {