From 3ba99e66565acabc391ce5a568256f347e8d0968 Mon Sep 17 00:00:00 2001 From: DIYgod Date: Wed, 27 Jul 2022 21:46:35 +0100 Subject: [PATCH] feat: use custom connect button --- src/components/common/ConnectButton.tsx | 59 +++++++++++++++++++++++++ src/components/main/MainLayout.tsx | 4 +- src/components/site/SiteHeader.tsx | 2 + src/models/site.model.ts | 15 ++++++- src/pages/index.tsx | 2 +- 5 files changed, 77 insertions(+), 5 deletions(-) create mode 100644 src/components/common/ConnectButton.tsx diff --git a/src/components/common/ConnectButton.tsx b/src/components/common/ConnectButton.tsx new file mode 100644 index 00000000..7c191c80 --- /dev/null +++ b/src/components/common/ConnectButton.tsx @@ -0,0 +1,59 @@ +import { ConnectButton as RainbowConnectButton } from "@rainbow-me/rainbowkit" +import { useGetUserSites } from "~/queries/site" +import { useAccount } from "wagmi" +import { Avatar } from "~/components/ui/Avatar"; + +export const ConnectButton = () => { + const { data: viewer } = useAccount() + const userSites = useGetUserSites(viewer?.address) + + return ( + + {({ + account, + chain, + openAccountModal, + openChainModal, + openConnectModal, + mounted, + }) => { + + return ( +
+ {(() => { + if (!mounted || !account || !chain) { + return ( + + ); + } + return ( +
+ +
+ ); + })()} +
+ ); + }} +
+ ); +}; \ No newline at end of file diff --git a/src/components/main/MainLayout.tsx b/src/components/main/MainLayout.tsx index 5662893e..5d952d52 100644 --- a/src/components/main/MainLayout.tsx +++ b/src/components/main/MainLayout.tsx @@ -9,7 +9,7 @@ import { import { useStore } from "~/lib/store" import { SEOHead } from "../common/SEOHead" import { UniLink } from "../ui/UniLink" -import { ConnectButton } from '@rainbow-me/rainbowkit' +import { ConnectButton } from "../common/ConnectButton" export function MainLayout({ children, @@ -28,7 +28,7 @@ export function MainLayout({

{APP_NAME}

-
+
diff --git a/src/components/site/SiteHeader.tsx b/src/components/site/SiteHeader.tsx index c1de9061..531d5fb2 100644 --- a/src/components/site/SiteHeader.tsx +++ b/src/components/site/SiteHeader.tsx @@ -12,6 +12,7 @@ import { Avatar } from "../ui/Avatar" import { Button } from "../ui/Button" import { UniLink } from "../ui/UniLink" import { Profile } from "unidata.js" +import { ConnectButton } from "../common/ConnectButton" export type HeaderLinkType = { icon?: React.ReactNode @@ -86,6 +87,7 @@ export const SiteHeader: React.FC<{ return })}
+
diff --git a/src/models/site.model.ts b/src/models/site.model.ts index 090bd8c8..4452c31d 100644 --- a/src/models/site.model.ts +++ b/src/models/site.model.ts @@ -38,14 +38,25 @@ export const checkSubdomain = async ({ } } -export const getUserSites = async (address: string) => { +export const getUserSites = async (address?: string) => { + if (!address) { + return null + } const profiles = await unidata.profiles.get({ source: 'Crossbell Profile', identity: address, platform: 'Ethereum', }); - const sites = profiles.list?.sort((a, b) => +new Date(b.date_updated || 0) - +new Date(a.date_updated || 0)).map((profile) => { + const sites = profiles.list?.sort((a, b) => { + if (a.metadata?.primary) { + return -1 + } else if (b.metadata?.primary) { + return 1 + } else { + return +new Date(b.date_updated || 0) - +new Date(a.date_updated || 0) + } + }).map((profile) => { profile.name = profile.name || profile.username; return profile }) diff --git a/src/pages/index.tsx b/src/pages/index.tsx index ac6c400a..a37d433f 100644 --- a/src/pages/index.tsx +++ b/src/pages/index.tsx @@ -7,7 +7,7 @@ import { getAuthUser } from "~/lib/auth.server" import { FLY_REGION } from "~/lib/env.server" import { useStore } from "~/lib/store" import { useAccount } from 'wagmi' -import { ConnectButton } from '@rainbow-me/rainbowkit' +import { ConnectButton } from "~/components/common/ConnectButton" export const getServerSideProps: GetServerSideProps = async (ctx) => { return {