From 8983d68aba60cd38bb9380ab97676b8461215dd0 Mon Sep 17 00:00:00 2001 From: Joseph Chalabi Date: Tue, 14 Jan 2025 00:10:28 -0700 Subject: [PATCH] chore: only render admin selector in all navs if part of admin group --- components/react/mobileNav.tsx | 19 +++++++++++++++++-- components/react/sideNav.tsx | 19 +++++++++++++++++-- 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/components/react/mobileNav.tsx b/components/react/mobileNav.tsx index 52eaa7d..9273746 100644 --- a/components/react/mobileNav.tsx +++ b/components/react/mobileNav.tsx @@ -15,10 +15,25 @@ import { import { WalletSection } from '../wallet'; import { RiMenuUnfoldFill } from 'react-icons/ri'; import { useState } from 'react'; -import { MdOutlineNetworkPing, MdContacts } from 'react-icons/md'; +import { MdContacts } from 'react-icons/md'; import env from '@/config/env'; +import { useChain } from '@cosmos-kit/react'; +import { usePoaGetAdmin } from '@/hooks'; +import { useGroupsByAdmin } from '@/hooks'; export default function MobileNav() { + const { address } = useChain(env.chain); + + const { poaAdmin } = usePoaGetAdmin(); + + const { groupByAdmin } = useGroupsByAdmin( + poaAdmin ?? 'manifest1afk9zr2hn2jsac63h4hm60vl9z3e5u69gndzf7c99cqge3vzwjzsfmy9qj' + ); + + const group = groupByAdmin?.groups?.[0]; + + const isMember = group?.members?.some(member => member?.member?.address === address); + const closeDrawer = () => { const drawer = document.getElementById('my-drawer') as HTMLInputElement; if (drawer) drawer.checked = false; @@ -88,7 +103,7 @@ export default function MobileNav() {
- + {isMember && }
diff --git a/components/react/sideNav.tsx b/components/react/sideNav.tsx index 0900bd5..4b21a7c 100644 --- a/components/react/sideNav.tsx +++ b/components/react/sideNav.tsx @@ -19,6 +19,9 @@ import { import { MdContacts } from 'react-icons/md'; import { getRealLogo } from '@/utils'; import env from '@/config/env'; +import { useGroupsByAdmin } from '@/hooks'; +import { usePoaGetAdmin } from '@/hooks'; +import { useChain } from '@cosmos-kit/react'; interface SideNavProps { isDrawerVisible: boolean; @@ -28,6 +31,17 @@ interface SideNavProps { export default function SideNav({ isDrawerVisible, setDrawerVisible }: SideNavProps) { const { toggleTheme, theme } = useTheme(); const [isContactsOpen, setContactsOpen] = useState(false); + const { address } = useChain(env.chain); + + const { poaAdmin } = usePoaGetAdmin(); + + const { groupByAdmin } = useGroupsByAdmin( + poaAdmin ?? 'manifest1afk9zr2hn2jsac63h4hm60vl9z3e5u69gndzf7c99cqge3vzwjzsfmy9qj' + ); + + const group = groupByAdmin?.groups?.[0]; + + const isMember = group?.members?.some(member => member?.member?.address === address); const toggleDrawer = () => setDrawerVisible(!isDrawerVisible); const version = packageInfo.version; @@ -72,7 +86,8 @@ export default function SideNav({ isDrawerVisible, setDrawerVisible }: SideNavPr
    - + {isMember && } +
@@ -144,7 +159,7 @@ export default function SideNav({ isDrawerVisible, setDrawerVisible }: SideNavPr
    - + {isMember && }