-
Notifications
You must be signed in to change notification settings - Fork 16
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
Feat: show connected wallet info #22
Merged
derrekcoleman
merged 5 commits into
BuidlGuidl:main
from
DimaKush:feat--Show-connected-wallet-info
Jan 22, 2025
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
6965ab7
feat: show-connected-wallet-info
DimaKush d7a3aa5
feat(show connected wallet info) Added UserStateInBatch component at …
DimaKush b00cb02
feat(Show connected wallet info): Move batch status to Header
DimaKush b9e3dcd
refactor: improve wallet disconnected state UX and reduce code duplic…
DimaKush 79aadb4
feat: add wrong network state handling
DimaKush File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { showBuilderNotification } from "./builderState/BuilderNotification"; | ||
import { BuilderStateIcon } from "./builderState/BuilderStateIcon"; | ||
import { useBuilderStateConfig } from "~~/hooks/useBuilderState"; | ||
|
||
export const BuilderStateInBatch = () => { | ||
const { state, config } = useBuilderStateConfig(); | ||
|
||
return ( | ||
<div className="flex items-center"> | ||
<BuilderStateIcon | ||
type={state} | ||
tooltip={config.tooltip} | ||
onClick={() => showBuilderNotification(config.notification)} | ||
/> | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
packages/nextjs/components/builderState/BuilderNotification.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { notification } from "~~/utils/scaffold-eth"; | ||
|
||
type NotificationLink = { | ||
text: string; | ||
url: string; | ||
}; | ||
|
||
type NotificationConfig = { | ||
message: string; | ||
link?: NotificationLink; | ||
type?: "info" | "success" | "warning"; | ||
}; | ||
|
||
export const showBuilderNotification = ({ message, link, type = "info" }: NotificationConfig) => { | ||
const content = ( | ||
<div> | ||
{message} | ||
{link && ( | ||
<> | ||
{" "} | ||
<a href={link.url} target="_blank" className="underline"> | ||
{link.text} | ||
</a> | ||
</> | ||
)} | ||
</div> | ||
); | ||
|
||
notification[type](content); | ||
}; |
28 changes: 28 additions & 0 deletions
28
packages/nextjs/components/builderState/BuilderStateIcon.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { WalletIcon } from "@heroicons/react/24/outline"; | ||
import { CheckCircleIcon, UserGroupIcon } from "@heroicons/react/24/solid"; | ||
|
||
type BuilderStateIconProps = { | ||
type: "disconnected" | "notAllowlisted" | "notCheckedIn" | "checkedIn" | "wrongNetwork"; | ||
onClick: () => void; | ||
tooltip: string; | ||
}; | ||
|
||
export const BuilderStateIcon = ({ type, onClick, tooltip }: BuilderStateIconProps) => { | ||
const baseStyles = "h-6 w-6 cursor-pointer"; | ||
const warningStyles = `${baseStyles} text-warning animate-pulse`; | ||
const walletStyles = `${warningStyles} mr-2`; | ||
|
||
const icons = { | ||
notAllowlisted: <UserGroupIcon className={warningStyles} />, | ||
notCheckedIn: <CheckCircleIcon className={warningStyles} />, | ||
checkedIn: <CheckCircleIcon className={`${baseStyles} text-success`} />, | ||
disconnected: <WalletIcon className={walletStyles} />, | ||
wrongNetwork: <WalletIcon className={walletStyles} />, | ||
Comment on lines
+16
to
+20
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
}; | ||
|
||
return ( | ||
<div className="tooltip tooltip-bottom" data-tip={tooltip} onClick={onClick}> | ||
{icons[type]} | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import { useScaffoldReadContract } from "./scaffold-eth/useScaffoldReadContract"; | ||
import { Address } from "viem"; | ||
import { useAccount, useChainId } from "wagmi"; | ||
|
||
type BuilderState = "disconnected" | "notAllowlisted" | "notCheckedIn" | "checkedIn" | "wrongNetwork"; | ||
|
||
const stateConfigs = { | ||
disconnected: { | ||
tooltip: "Please connect your wallet", | ||
notification: { | ||
message: "Please connect your wallet to check your builder status", | ||
type: "warning", | ||
}, | ||
}, | ||
notAllowlisted: { | ||
tooltip: "Connected wallet is not allowlisted. Please apply to the next batch.", | ||
notification: { | ||
message: "Connected wallet is not allowlisted. Please ", | ||
link: { text: "apply to the next batch", url: "https://buidlguidl.com/batches" }, | ||
}, | ||
}, | ||
notCheckedIn: { | ||
tooltip: "You need to check in to start building", | ||
notification: { | ||
message: "You need to check in to start building. Follow instructions in ", | ||
link: { text: "this GitHub issue", url: "https://github.com/BuidlGuidl/batch12.buidlguidl.com/issues/12" }, | ||
}, | ||
}, | ||
checkedIn: { | ||
tooltip: "You are checked in and ready to build! Check ", | ||
notification: { | ||
message: "You are checked in and ready to build! Check ", | ||
link: { text: "GitHub issues", url: "https://github.com/BuidlGuidl/batch12.buidlguidl.com/issues/12" }, | ||
type: "success" as const, | ||
}, | ||
}, | ||
wrongNetwork: { | ||
tooltip: "Switch to Optimism network", | ||
notification: { | ||
message: "Please switch to Optimism network", | ||
type: "warning" as const, | ||
}, | ||
}, | ||
} as const; | ||
|
||
export const useBuilderState = (address?: Address) => { | ||
const { data: isAllowListed } = useScaffoldReadContract({ | ||
contractName: "BatchRegistry", | ||
functionName: "allowList", | ||
args: [address], | ||
}); | ||
|
||
const { data: contractAddress } = useScaffoldReadContract({ | ||
contractName: "BatchRegistry", | ||
functionName: "yourContractAddress", | ||
args: [address], | ||
}); | ||
|
||
const isCheckedIn = contractAddress && contractAddress !== "0x0000000000000000000000000000000000000000"; | ||
|
||
return { isAllowListed, isCheckedIn }; | ||
}; | ||
|
||
export const useBuilderStateConfig = () => { | ||
const { address } = useAccount(); | ||
const chainId = useChainId(); | ||
const { isAllowListed, isCheckedIn } = useBuilderState(address); | ||
|
||
const getState = (): BuilderState => { | ||
if (!address) return "disconnected"; | ||
if (chainId !== 10) return "wrongNetwork"; | ||
if (!isAllowListed) return "notAllowlisted"; | ||
if (!isCheckedIn) return "notCheckedIn"; | ||
return "checkedIn"; | ||
}; | ||
|
||
const state = getState(); | ||
return { state, config: stateConfigs[state] }; | ||
}; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tailwind purists will say not to do it this way, but I think this kind of "inheritance" pattern is easy to read, understand, and maintain in this case!