22
33import { useEffect , useState } from "react" ;
44import Link from "next/link" ;
5- import { useQuery } from "@tanstack/react-query" ;
5+ import { useQuery , useQueryClient } from "@tanstack/react-query" ;
66import {
77 AlertCircle ,
88 ArrowLeft ,
@@ -183,6 +183,7 @@ export function BountyDetailView({ initialBounty, chainId, bountyId }: BountyDet
183183 } ) ;
184184
185185 const bounty = data ?. bounty ;
186+ const queryClient = useQueryClient ( ) ;
186187
187188 const { ethPrice } = useEthPrice ( ) ;
188189 const [ joinAmount , setJoinAmount ] = useState ( "0.001" ) ;
@@ -198,6 +199,27 @@ export function BountyDetailView({ initialBounty, chainId, bountyId }: BountyDet
198199 const resolveVoteHook = usePoidhResolveVote ( chainId ) ;
199200 const resetVotingHook = usePoidhResetVotingPeriod ( chainId ) ;
200201
202+ // Refresh bounty state after actions that change on-chain status
203+ const bountyQueryKey = [ "poidh-bounty" , chainId , bountyId ] ;
204+ useEffect ( ( ) => {
205+ if ( submitForVoteHook . isSuccess ) {
206+ queryClient . invalidateQueries ( { queryKey : bountyQueryKey } ) ;
207+ }
208+ // eslint-disable-next-line react-hooks/exhaustive-deps
209+ } , [ submitForVoteHook . isSuccess ] ) ;
210+ useEffect ( ( ) => {
211+ if ( resolveVoteHook . isSuccess ) {
212+ queryClient . invalidateQueries ( { queryKey : bountyQueryKey } ) ;
213+ }
214+ // eslint-disable-next-line react-hooks/exhaustive-deps
215+ } , [ resolveVoteHook . isSuccess ] ) ;
216+ useEffect ( ( ) => {
217+ if ( cancelHook . isSuccess ) {
218+ queryClient . invalidateQueries ( { queryKey : bountyQueryKey } ) ;
219+ }
220+ // eslint-disable-next-line react-hooks/exhaustive-deps
221+ } , [ cancelHook . isSuccess ] ) ;
222+
201223 const deadlineTimestamp = bounty ?. deadline ?? null ;
202224 const countdown = useCountdown ( deadlineTimestamp ) ;
203225
0 commit comments