-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7233032
commit ab1fa04
Showing
8 changed files
with
106 additions
and
5 deletions.
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,69 @@ | ||
import { cn } from "@repo/ui/lib/utils"; | ||
import makeBlockie from "ethereum-blockies-base64"; | ||
import Image from "next/image"; | ||
import { useMemo } from "react"; | ||
import { isAddress } from "viem"; | ||
import { normalize } from "viem/ens"; | ||
import { useEnsAddress, useEnsAvatar, useEnsName } from "wagmi"; | ||
import { mainnetConfig } from "../utils/wallet"; | ||
|
||
const transparentPixel = | ||
"data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7"; | ||
|
||
function AddressAvatar({ | ||
addressOrEns, | ||
size, | ||
}: { addressOrEns: string; size: number }) { | ||
const isEnsName = addressOrEns.endsWith(".eth"); | ||
const isAddr = isAddress(addressOrEns); | ||
|
||
// If addressOrEns is an address, get the ens name | ||
const { data: ensName } = useEnsName({ | ||
address: isAddr ? addressOrEns : undefined, | ||
chainId: 1, | ||
query: { enabled: !isEnsName && isAddr }, | ||
config: mainnetConfig, | ||
}); | ||
|
||
let normalizedName: string | undefined; | ||
try { | ||
normalizedName = isEnsName | ||
? normalize(addressOrEns) | ||
: ensName?.toLowerCase(); | ||
} catch (error) {} | ||
|
||
// If we did not have the address and normalizedName is an ens name, get the ens address | ||
const { data: ensAddress } = useEnsAddress({ | ||
name: normalizedName, | ||
chainId: 1, | ||
query: { enabled: !!normalizedName && !isAddr }, | ||
config: mainnetConfig, | ||
}); | ||
|
||
// If normalizedName is an ens name, get the ens avatar | ||
const { data: ensAvatar, isLoading } = useEnsAvatar({ | ||
name: normalizedName, | ||
chainId: 1, | ||
query: { enabled: !!normalizedName }, | ||
config: mainnetConfig, | ||
}); | ||
const address = ensAddress ?? addressOrEns; | ||
const src = useMemo(() => { | ||
if (isLoading) return transparentPixel; | ||
if (ensAvatar) return ensAvatar; | ||
if (!isLoading && isAddress(address)) return makeBlockie(address); | ||
return transparentPixel; | ||
}, [ensAvatar, address, isLoading]); | ||
|
||
return ( | ||
<Image | ||
src={src} | ||
alt="" | ||
width={size} | ||
height={size} | ||
className={cn("rounded bg-gray-600")} | ||
/> | ||
); | ||
} | ||
|
||
export default AddressAvatar; |
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 |
---|---|---|
@@ -1,5 +1,16 @@ | ||
"use client"; | ||
|
||
import { ConnectButton as RainbowConnectButton } from "@rainbow-me/rainbowkit"; | ||
import { useConnectModal } from "@rainbow-me/rainbowkit"; | ||
import { Button } from "@repo/ui/components/ui/button"; | ||
import { useAccount } from "wagmi"; | ||
|
||
export function ConnectButton() { | ||
return <RainbowConnectButton showBalance={false} />; | ||
const { address } = useAccount(); | ||
const { openConnectModal } = useConnectModal(); | ||
return address ? ( | ||
<RainbowConnectButton showBalance={false} /> | ||
) : ( | ||
<Button onClick={openConnectModal}>Connect Wallet</Button> | ||
); | ||
} |
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
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,3 @@ | ||
export const SITE_NAME = "Councilhaus"; | ||
export const SITE_DESCRIPTION = | ||
"Democratically allocate a budget across projects"; |
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
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
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