From 296a452dfb49e21b8b2552011ba3c7bbffcd7b72 Mon Sep 17 00:00:00 2001 From: lemu Date: Thu, 23 Nov 2023 16:10:19 -0300 Subject: [PATCH] chore: refetch proposals votes after voting (#1414) --- src/hooks/useProposalsCachedVotes.ts | 4 +++- src/pages/proposal.tsx | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/hooks/useProposalsCachedVotes.ts b/src/hooks/useProposalsCachedVotes.ts index c96ba261a..a395756e3 100644 --- a/src/hooks/useProposalsCachedVotes.ts +++ b/src/hooks/useProposalsCachedVotes.ts @@ -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, }) diff --git a/src/pages/proposal.tsx b/src/pages/proposal.tsx index 9e6429577..5b666d66e 100644 --- a/src/pages/proposal.tsx +++ b/src/pages/proposal.tsx @@ -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' @@ -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' @@ -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,