Skip to content

Commit

Permalink
chore: refetch proposals votes after voting (#1414)
Browse files Browse the repository at this point in the history
  • Loading branch information
1emu authored Nov 23, 2023
1 parent 180dea8 commit 296a452
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/hooks/useProposalsCachedVotes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ import { getVoteSegmentation } from '../entities/Votes/utils'

import { DEFAULT_QUERY_STALE_TIME } from './constants'

export const PROPOSAL_CACHED_VOTES_QUERY_KEY = 'proposalsVotes'

function useProposalsCachedVotes(proposalIds: ProposalAttributes['id'][]) {
const { data: votes, isLoading: isLoadingVotes } = useQuery({
queryKey: [`proposalsVotes#${proposalIds.join('-')}`],
queryKey: [PROPOSAL_CACHED_VOTES_QUERY_KEY, proposalIds.join('-')],
queryFn: () => Governance.get().getCachedVotesByProposals(proposalIds),
staleTime: DEFAULT_QUERY_STALE_TIME,
})
Expand Down
4 changes: 3 additions & 1 deletion src/pages/proposal.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useEffect, useMemo, useRef, useState } from 'react'
import { useEffect, useRef, useState } from 'react'

import { ErrorCode } from '@ethersproject/logger'
import { Web3Provider } from '@ethersproject/providers'
Expand Down Expand Up @@ -64,6 +64,7 @@ import useIsProposalOwner from '../hooks/useIsProposalOwner'
import useProposal from '../hooks/useProposal'
import useProposalUpdates from '../hooks/useProposalUpdates'
import useProposalVotes from '../hooks/useProposalVotes'
import { PROPOSAL_CACHED_VOTES_QUERY_KEY } from '../hooks/useProposalsCachedVotes'
import useSurvey from '../hooks/useSurvey'
import useURLSearchParams from '../hooks/useURLSearchParams'
import { ErrorCategory } from '../utils/errorCategories'
Expand Down Expand Up @@ -234,6 +235,7 @@ export default function ProposalPage() {
confirmSubscription: !votes![account!],
})
await reloadVotes()
await queryClient.invalidateQueries({ queryKey: [PROPOSAL_CACHED_VOTES_QUERY_KEY] })
} catch (error) {
ErrorClient.report('Unable to vote', {
error,
Expand Down

0 comments on commit 296a452

Please sign in to comment.