diff --git a/govtool/frontend/src/hooks/queries/useGetProposalsQuery.ts b/govtool/frontend/src/hooks/queries/useGetProposalsQuery.ts index 27f349615..da62db474 100644 --- a/govtool/frontend/src/hooks/queries/useGetProposalsQuery.ts +++ b/govtool/frontend/src/hooks/queries/useGetProposalsQuery.ts @@ -10,11 +10,18 @@ export const useGetProposalsQuery = ({ filters = [], searchPhrase, sorting, - enabled, + enabled = true, }: GetProposalsArguments) => { const { dRepID } = useCardano(); const { voter } = useGetVoterInfo(); +// Determine if voter is ready to be used in the query +const voterReady = + !!dRepID && (voter?.isRegisteredAsDRep || voter?.isRegisteredAsSoleVoter); + +// Only run the query if enabled externally and voter info is ready +const shouldFetch = enabled && voterReady; + const fetchProposals = async (): Promise => { const allProposals = await Promise.all( filters.map((filter) => @@ -45,7 +52,7 @@ export const useGetProposalsQuery = ({ ], fetchProposals, { - enabled, + enabled: shouldFetch, refetchOnWindowFocus: true, keepPreviousData: true, },