Skip to content
This repository has been archived by the owner on Feb 9, 2025. It is now read-only.

show members tab if council exists #2076

Merged
merged 2 commits into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 25 additions & 12 deletions components/RealmHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ import { getRealmExplorerHost } from 'tools/routing'
import { tryParsePublicKey } from '@tools/core/pubkey'
import { useRealmQuery } from '@hooks/queries/realm'
import { useRealmConfigQuery } from '@hooks/queries/realmConfig'
import { NFT_PLUGINS_PKS } from '@constants/plugins'
import { GoverningTokenType } from '@solana/spl-governance'
import { determineVotingPowerType } from '@hooks/queries/governancePower'
import { useAsync } from 'react-async-hook'
import useSelectedRealmPubkey from '@hooks/selectedRealm/useSelectedRealmPubkey'
import { useConnection } from '@solana/wallet-adapter-react'

const RealmHeader = () => {
const { fmtUrlWithCluster } = useQueryContext()
Expand All @@ -25,6 +29,18 @@ const RealmHeader = () => {

const [isBackNavVisible, setIsBackNavVisible] = useState(true)

const { connection } = useConnection()
const realmPk = useSelectedRealmPubkey()

const { result: kind } = useAsync(async () => {
if (realmPk === undefined) return undefined
return determineVotingPowerType(connection, realmPk, 'community')
}, [connection, realmPk])
const membersTabIsCouncilOnly = !(kind === 'vanilla' || kind === 'NFT')
const councilExists =
realm?.account.config.councilMint !== undefined &&
config?.account.councilTokenConfig?.tokenType !== GoverningTokenType.Dormant

useEffect(() => {
setIsBackNavVisible(realmInfo?.symbol !== REALM)
}, [realmInfo?.symbol, REALM])
Expand Down Expand Up @@ -68,17 +84,6 @@ const RealmHeader = () => {
<div className="w-40 h-10 rounded-md animate-pulse bg-bkg-3" />
)}
<div className="flex items-center space-x-4">
{(!config?.account.communityTokenConfig.voterWeightAddin ||
NFT_PLUGINS_PKS.includes(
config?.account.communityTokenConfig.voterWeightAddin.toBase58()
)) && (
<Link href={fmtUrlWithCluster(`/dao/${symbol}/members`)}>
<a className="flex items-center text-sm cursor-pointer default-transition text-fgd-2 hover:text-fgd-3">
<UsersIcon className="flex-shrink-0 w-5 h-5 mr-1" />
Members
</a>
</Link>
)}
{vsrMode === 'default' && (
<Link href={fmtUrlWithCluster(`/dao/${symbol}/token-stats`)}>
<a className="flex items-center text-sm cursor-pointer default-transition text-fgd-2 hover:text-fgd-3">
Expand All @@ -90,6 +95,14 @@ const RealmHeader = () => {
</a>
</Link>
)}
{(!membersTabIsCouncilOnly || councilExists) && (
<Link href={fmtUrlWithCluster(`/dao/${symbol}/members`)}>
<a className="flex items-center text-sm cursor-pointer default-transition text-fgd-2 hover:text-fgd-3">
<UsersIcon className="flex-shrink-0 w-5 h-5 mr-1" />
{membersTabIsCouncilOnly ? 'Council' : 'Members'}
</a>
</Link>
)}
<Link href={fmtUrlWithCluster(`/dao/${symbol}/params`)}>
<a className="flex items-center text-sm cursor-pointer default-transition text-fgd-2 hover:text-fgd-3">
<CogIcon className="flex-shrink-0 w-5 h-5 mr-1" />
Expand Down
28 changes: 25 additions & 3 deletions pages/dao/[symbol]/members/Members.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import useRealm from '@hooks/useRealm'
import { useEffect, useRef, useState } from 'react'
import { useEffect, useMemo, useRef, useState } from 'react'
import MemberOverview from '@components/Members/MemberOverview'
import { PlusCircleIcon, SearchIcon, UsersIcon } from '@heroicons/react/outline'
import useGovernanceAssets from '@hooks/useGovernanceAssets'
Expand All @@ -15,6 +15,10 @@ import { Member } from '@utils/uiTypes/members'
import PaginationComponent from '@components/Pagination'
import useWalletOnePointOh from '@hooks/useWalletOnePointOh'
import { useMembersQuery } from '@components/Members/useMembers'
import { useConnection } from '@solana/wallet-adapter-react'
import useSelectedRealmPubkey from '@hooks/selectedRealm/useSelectedRealmPubkey'
import { determineVotingPowerType } from '@hooks/queries/governancePower'
import { useAsync } from 'react-async-hook'

const Members = () => {
const {
Expand All @@ -25,7 +29,6 @@ const Members = () => {
const pagination = useRef<{ setPage: (val) => void }>(null)
const membersPerPage = 10

const { data: activeMembers } = useMembersQuery()
const wallet = useWalletOnePointOh()
const connected = !!wallet?.connected
const {
Expand All @@ -38,6 +41,25 @@ const Members = () => {
const [searchString, setSearchString] = useState('')
const [filteredMembers, setFilteredMembers] = useState<Member[]>([])

const { connection } = useConnection()
const realmPk = useSelectedRealmPubkey()
const { data: activeMembersData } = useMembersQuery()

const { result: kind } = useAsync(async () => {
if (realmPk === undefined) return undefined
return determineVotingPowerType(connection, realmPk, 'community')
}, [connection, realmPk])

// if this is not vanilla or NFT, this view is used only to show council. filter accordingly.
const councilOnly = !(kind === 'vanilla' || kind === 'NFT')
const activeMembers = useMemo(
() =>
councilOnly
? activeMembersData?.filter((x) => x.councilVotes.gtn(0))
: activeMembersData,
[activeMembersData, councilOnly]
)

const filterMembers = (v) => {
if (activeMembers !== undefined) {
setSearchString(v)
Expand Down Expand Up @@ -98,7 +120,7 @@ const Members = () => {
) : null}
<div>
<p>{realmInfo?.displayName}</p>
<h1 className="mb-0">Members</h1>
<h1 className="mb-0">{councilOnly ? 'Council ' : ''}Members</h1>
</div>
</div>
<div className="flex space-x-3">
Expand Down
12 changes: 1 addition & 11 deletions pages/dao/[symbol]/members/index.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,8 @@
import { NFT_PLUGINS_PKS } from '@constants/plugins'
import Members from './Members'
import { useRealmConfigQuery } from '@hooks/queries/realmConfig'
const MembersPage = () => {
const config = useRealmConfigQuery().data?.result
const currentPluginPk = config?.account.communityTokenConfig.voterWeightAddin
const isNftMode =
(currentPluginPk &&
NFT_PLUGINS_PKS.includes(currentPluginPk?.toBase58())) ||
false
return (
<div>
{!config?.account.communityTokenConfig.voterWeightAddin || isNftMode ? (
<Members />
) : null}
<Members />
</div>
)
}
Expand Down
Loading