-
Notifications
You must be signed in to change notification settings - Fork 22
/
useRefreshGovProposals.ts
58 lines (51 loc) · 1.68 KB
/
useRefreshGovProposals.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import { useQueryClient } from '@tanstack/react-query'
import { useCallback } from 'react'
import { useSetRecoilState } from 'recoil'
import { chainQueries, indexerQueries } from '@dao-dao/state/query'
import { refreshGovProposalsAtom } from '@dao-dao/state/recoil'
import { useChain } from '@dao-dao/stateless'
export const useRefreshGovProposals = () => {
const { chainId } = useChain()
const queryClient = useQueryClient()
const setRefreshProposal = useSetRecoilState(refreshGovProposalsAtom(chainId))
const refreshProposal = useCallback(() => {
// Search/List
queryClient.invalidateQueries({
queryKey: chainQueries.searchGovProposals({
chainId,
}).queryKey,
})
queryClient.invalidateQueries({
queryKey: chainQueries.searchAndDecodeGovProposals(queryClient, {
chainId,
}).queryKey,
})
queryClient.invalidateQueries({
queryKey: chainQueries.govProposals(queryClient, {
chainId,
}).queryKey,
})
// Proposal
queryClient.invalidateQueries({
queryKey: indexerQueries.queryGeneric(queryClient, {
chainId,
formula: 'gov/proposal',
}).queryKey,
})
queryClient.invalidateQueries({
queryKey: ['chain', 'govProposal', { chainId }],
})
queryClient.invalidateQueries({
queryKey: ['chain', 'govProposalTally', { chainId }],
})
queryClient.invalidateQueries({
queryKey: ['chain', 'govProposalVote', { chainId }],
})
queryClient.invalidateQueries({
queryKey: ['chain', 'govProposalVotes', { chainId }],
})
// Recoil
setRefreshProposal((id) => id + 1)
}, [setRefreshProposal, queryClient, chainId])
return refreshProposal
}