diff --git a/VoteStakeRegistry/components/TokenBalance/VSRVotingPower.tsx b/VoteStakeRegistry/components/TokenBalance/VSRVotingPower.tsx index 0836e2d6de..e169b3a00a 100644 --- a/VoteStakeRegistry/components/TokenBalance/VSRVotingPower.tsx +++ b/VoteStakeRegistry/components/TokenBalance/VSRVotingPower.tsx @@ -98,7 +98,7 @@ export default function VSRCommunityVotingPower(props: Props) { totalDelegatorPower && new BigNumber(totalDelegatorPower.toString()).shiftedBy(-mint.decimals) - const totalPower = votingPower.add(totalDelegatorPower ?? new BN(0)) + //const totalPower = votingPower.add(totalDelegatorPower ?? new BN(0)) if (isLoading || mint === undefined || votingPowerLoading) { return ( diff --git a/components/ProposalVotingPower/LockedCommunityVotingPower.tsx b/components/ProposalVotingPower/LockedCommunityVotingPower.tsx index 5df7263eec..f866a8b002 100644 --- a/components/ProposalVotingPower/LockedCommunityVotingPower.tsx +++ b/components/ProposalVotingPower/LockedCommunityVotingPower.tsx @@ -1,6 +1,6 @@ import useRealm from '@hooks/useRealm' import { BigNumber } from 'bignumber.js' -import { useCallback } from 'react' +import { useCallback, useMemo } from 'react' import classNames from 'classnames' import useDepositStore from 'VoteStakeRegistry/stores/useDepositStore' @@ -13,12 +13,16 @@ import { getMintMetadata } from '../instructions/programs/splToken' import depositTokensVSR from './depositTokensVSR' import useWalletOnePointOh from '@hooks/useWalletOnePointOh' import { useRealmQuery } from '@hooks/queries/realm' -import { useUserCommunityTokenOwnerRecord } from '@hooks/queries/tokenOwnerRecord' +import { + useTokenOwnerRecordsDelegatedToUser, + useUserCommunityTokenOwnerRecord, +} from '@hooks/queries/tokenOwnerRecord' import { useRealmCommunityMintInfoQuery } from '@hooks/queries/mintInfo' import { useConnection } from '@solana/wallet-adapter-react' import BN from 'bn.js' import { useVsrGovpower } from '@hooks/queries/plugins/vsr' import VSRCommunityVotingPower from 'VoteStakeRegistry/components/TokenBalance/VSRVotingPower' +import { useSelectedDelegatorStore } from 'stores/useSelectedDelegatorStore' interface Props { className?: string @@ -104,6 +108,25 @@ export default function LockedCommunityVotingPower(props: Props) { wallet, ]) + const delegatedTors = useTokenOwnerRecordsDelegatedToUser() + const selectedDelegator = useSelectedDelegatorStore( + (s) => s.communityDelegator + ) + // memoize useAsync inputs to prevent constant refetch + const relevantDelegators = useMemo( + () => + selectedDelegator !== undefined // ignore delegators if any delegator is selected + ? [] + : delegatedTors + ?.filter( + (x) => + x.account.governingTokenMint.toString() === + realm?.account.communityMint.toString() + ) + .map((x) => x.account.governingTokenOwner), + [delegatedTors, realm?.account.communityMint, selectedDelegator] + ) + if (isLoading || !(votingPower && mint)) { return (
- + {amount.isZero() && (relevantDelegators?.length ?? 0) < 1 ? ( +
+ You do not have any voting power in this dao. +
+ ) : ( + + )} {depositAmount.isGreaterThan(0) && ( <>