Skip to content
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

Hide community/council governing power when appropriate #1838

Merged
merged 1 commit into from
Sep 27, 2023
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
20 changes: 18 additions & 2 deletions components/GovernancePower/GovernancePowerCard.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { ChevronRightIcon } from '@heroicons/react/solid'
import { useGovernancePowerAsync } from '@hooks/queries/governancePower'
import { useRealmConfigQuery } from '@hooks/queries/realmConfig'
import useQueryContext from '@hooks/useQueryContext'
import useWalletOnePointOh from '@hooks/useWalletOnePointOh'
import { GoverningTokenType } from '@solana/spl-governance'
import Link from 'next/link'
import { useRouter } from 'next/router'
import GovernancePowerForRole from './GovernancePowerForRole'
Expand Down Expand Up @@ -42,6 +44,8 @@ const GovernancePowerCard = () => {
communityPower.result.isZero() &&
councilPower.result.isZero()

const realmConfig = useRealmConfigQuery().data?.result

return (
<div>
<GovernancePowerTitle />
Expand All @@ -60,8 +64,20 @@ const GovernancePowerCard = () => {
</div>
) : (
<div className="flex flex-col gap-2">
<GovernancePowerForRole role="community" />
<GovernancePowerForRole role="council" />
{realmConfig?.account.communityTokenConfig.tokenType ===
GoverningTokenType.Dormant ? null : (
<GovernancePowerForRole role="community" />
)}
{realmConfig?.account.councilTokenConfig.tokenType ===
GoverningTokenType.Dormant ? null : (
<GovernancePowerForRole
role="council"
hideIfZero={
realmConfig?.account.communityTokenConfig.tokenType !==
GoverningTokenType.Dormant
}
/>
)}
</div>
)}
</div>
Expand Down
13 changes: 6 additions & 7 deletions components/GovernancePower/GovernancePowerForRole.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import classNames from 'classnames'

import useWalletOnePointOh from '@hooks/useWalletOnePointOh'
import { useAsync } from 'react-async-hook'
import { determineVotingPowerType } from '@hooks/queries/governancePower'
Expand All @@ -15,6 +13,7 @@ export default function GovernancePowerForRole({
...props
}: {
role: 'community' | 'council'
hideIfZero?: boolean
className?: string
}) {
const { connection } = useConnection()
Expand All @@ -30,17 +29,17 @@ export default function GovernancePowerForRole({
return determineVotingPowerType(connection, realmPk, role)
}, [connection, realmPk, role])

if (connected && kind === undefined) {
if (connected && kind === undefined && !props.hideIfZero) {
return (
<div className="animate-pulse bg-bkg-1 col-span-1 h-[76px] rounded-lg" />
)
}

return (
<div className={classNames(props.className)}>
<>
{role === 'community' ? (
kind === 'vanilla' ? (
<VanillaVotingPower role="community" />
<VanillaVotingPower role="community" {...props} />
) : kind === 'VSR' ? (
<LockedCommunityVotingPower />
) : kind === 'NFT' ? (
Expand All @@ -49,8 +48,8 @@ export default function GovernancePowerForRole({
<LockedCommunityNFTRecordVotingPower />
) : null
) : kind === 'vanilla' ? (
<VanillaVotingPower role="council" />
<VanillaVotingPower role="council" {...props} />
) : null}
</div>
</>
)
}
48 changes: 30 additions & 18 deletions components/GovernancePower/Vanilla/VanillaVotingPower.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { BigNumber } from 'bignumber.js'
import { useMemo } from 'react'
import classNames from 'classnames'

import useRealm from '@hooks/useRealm'

Expand All @@ -20,15 +19,24 @@ import { getMintMetadata } from '@components/instructions/programs/splToken'
import VotingPowerPct from '@components/ProposalVotingPower/VotingPowerPct'
import { useSelectedDelegatorStore } from 'stores/useSelectedDelegatorStore'
import { abbreviateAddress } from '@utils/formatting'
import clsx from 'clsx'
import { useRealmConfigQuery } from '@hooks/queries/realmConfig'
import { GoverningTokenType } from '@solana/spl-governance'

interface Props {
className?: string
role: 'community' | 'council'
hideIfZero?: boolean
}

export default function VanillaVotingPower({ role, ...props }: Props) {
export default function VanillaVotingPower({
role,
hideIfZero,
...props
}: Props) {
const realm = useRealmQuery().data?.result
const { realmInfo } = useRealm()
const realmConfig = useRealmConfigQuery().data?.result

const { data: communityTOR } = useAddressQuery_CommunityTokenOwner()
const { data: councilTOR } = useAddressQuery_CouncilTokenOwner()
Expand Down Expand Up @@ -100,27 +108,31 @@ export default function VanillaVotingPower({ role, ...props }: Props) {
const tokenName =
getMintMetadata(relevantMint)?.name ?? realm?.account.name ?? ''

if (!(realm && realmInfo)) {
return (
<div
className={classNames(props.className, 'rounded-md bg-bkg-1 h-[76px]')}
/>
)
}
const disabled =
role === 'community'
? realmConfig?.account.communityTokenConfig.tokenType ===
GoverningTokenType.Dormant
: realmConfig?.account.councilTokenConfig.tokenType ===
GoverningTokenType.Dormant

return (
<div className={props.className}>
{totalAmount === undefined || totalAmount.isZero() ? (
<div className={'text-xs text-fgd-3'}>
You do not have any voting power in this dao.
</div>
) : (
<div
className={clsx(
props.className,
hideIfZero && totalAmount.isZero() && 'hidden',
disabled && 'hidden'
)}
>
{
<div className={'p-3 rounded-md bg-bkg-1'}>
<div className="text-fgd-3 text-xs">{tokenName} Votes</div>
<div className="text-fgd-3 text-xs">
{tokenName}
{role === 'council' ? ' Council' : ''} Votes
</div>
<div className="flex items-center justify-between mt-1">
<div className=" flex flex-row gap-x-2">
<div className="text-xl font-bold text-fgd-1 hero-text">
{formattedTotal}
{formattedTotal ?? 0}
</div>
<div className="text-xs text-fgd-3">
{selectedDelegator !== undefined ? (
Expand All @@ -141,7 +153,7 @@ export default function VanillaVotingPower({ role, ...props }: Props) {
)}
</div>
</div>
)}
}
<Deposit role={role} />
</div>
)
Expand Down