Skip to content

Commit

Permalink
fix: voting power on proposal fetch (#1059)
Browse files Browse the repository at this point in the history
  • Loading branch information
andyesp committed Jun 29, 2023
1 parent 861f868 commit 2b06632
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ const ProposalVotingSection = ({
totalVpOnProposal,
hasEnoughToVote,
isLoadingVp,
} = useVotingPowerOnProposal(account, delegators, isDelegationResultLoading, votes, proposal)
} = useVotingPowerOnProposal(account, delegators, isDelegationResultLoading, proposal)

const { matchResult } = useVotesMatch(account, delegate)
const voteDifference = matchResult.voteDifference
Expand Down
16 changes: 8 additions & 8 deletions src/hooks/useVotingPowerOnProposal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,23 @@ export default function useVotingPowerOnProposal(
address: string | null,
delegators: string[] | null,
isLoadingDelegators: boolean,
votes?: Record<string, Vote> | null,
proposal?: ProposalAttributes | null
) {
const { vpDistribution, isLoadingVpDistribution } = useVotingPowerDistribution(address, proposal?.snapshot_id)
const { data, isLoading } = useQuery({
queryKey: [`vpDistribution#${address}#${proposal?.snapshot_id}`],
queryKey: [`votingPowerOnProposal#${address}#${proposal?.snapshot_id}`],
queryFn: async () => {
if (!address || !proposal || isLoadingDelegators || isLoadingVpDistribution || !vpDistribution) {
return initialVotingPowerOnProposal
if (proposal?.snapshot_id) {
const votes: SnapshotVote[] = await SnapshotGraphql.get().getProposalVotes(proposal.snapshot_id)
const delegatedVp = getDelegatedVotingPowerOnProposal(vpDistribution, delegators, votes)
const addressVp = vpDistribution.own || 0
return { addressVp, delegatedVp }
}
const votes: SnapshotVote[] = await SnapshotGraphql.get().getProposalVotes(proposal.snapshot_id)
const delegatedVp = getDelegatedVotingPowerOnProposal(vpDistribution, delegators, votes)
const addressVp = vpDistribution.own || 0
return { addressVp, delegatedVp }
},
staleTime: DEFAULT_QUERY_STALE_TIME,
enabled: !!address && !!proposal && !isLoadingDelegators && !isLoadingVpDistribution && !!vpDistribution,
})

const vpOnProposal = data ?? initialVotingPowerOnProposal
const totalVpOnProposal = vpOnProposal.addressVp + vpOnProposal.delegatedVp
const hasEnoughToVote = totalVpOnProposal > MINIMUM_VP_REQUIRED_TO_VOTE && !isLoading
Expand Down

0 comments on commit 2b06632

Please sign in to comment.