diff --git a/web/hooks/use-contracts.ts b/web/hooks/use-contracts.ts index 4d7d2f79..2f3bea7b 100644 --- a/web/hooks/use-contracts.ts +++ b/web/hooks/use-contracts.ts @@ -13,6 +13,7 @@ import { getUserBetContractsQuery, } from 'web/lib/firebase/contracts' import { useQueryClient } from 'react-query' +import { MINUTE_MS } from 'common/util/time' export const useContracts = () => { const [contracts, setContracts] = useState() @@ -96,8 +97,10 @@ export const useUpdatedContracts = (contracts: Contract[] | undefined) => { export const usePrefetchUserBetContracts = (userId: string) => { const queryClient = useQueryClient() - return queryClient.prefetchQuery(['contracts', 'bets', userId], () => - getUserBetContracts(userId) + return queryClient.prefetchQuery( + ['contracts', 'bets', userId], + () => getUserBetContracts(userId), + { staleTime: 5 * MINUTE_MS } ) } diff --git a/web/hooks/use-portfolio-history.ts b/web/hooks/use-portfolio-history.ts index 1945eb7a..6cc1a84e 100644 --- a/web/hooks/use-portfolio-history.ts +++ b/web/hooks/use-portfolio-history.ts @@ -1,6 +1,6 @@ import { useQueryClient } from 'react-query' import { useFirestoreQueryData } from '@react-query-firebase/firestore' -import { DAY_MS, HOUR_MS } from 'common/util/time' +import { DAY_MS, HOUR_MS, MINUTE_MS } from 'common/util/time' import { getPortfolioHistory, getPortfolioHistoryQuery, @@ -15,8 +15,10 @@ const getCutoff = (period: Period) => { export const usePrefetchPortfolioHistory = (userId: string, period: Period) => { const queryClient = useQueryClient() const cutoff = getCutoff(period) - return queryClient.prefetchQuery(['portfolio-history', userId, cutoff], () => - getPortfolioHistory(userId, cutoff) + return queryClient.prefetchQuery( + ['portfolio-history', userId, cutoff], + () => getPortfolioHistory(userId, cutoff), + { staleTime: 15 * MINUTE_MS } ) } @@ -24,7 +26,9 @@ export const usePortfolioHistory = (userId: string, period: Period) => { const cutoff = getCutoff(period) const result = useFirestoreQueryData( ['portfolio-history', userId, cutoff], - getPortfolioHistoryQuery(userId, cutoff) + getPortfolioHistoryQuery(userId, cutoff), + {}, + { staleTime: 15 * MINUTE_MS } ) return result.data } diff --git a/web/hooks/use-user-bets.ts b/web/hooks/use-user-bets.ts index 8f0bd9f7..3731fb07 100644 --- a/web/hooks/use-user-bets.ts +++ b/web/hooks/use-user-bets.ts @@ -7,10 +7,15 @@ import { getUserBetsQuery, listenForUserContractBets, } from 'web/lib/firebase/bets' +import { MINUTE_MS } from 'common/util/time' export const usePrefetchUserBets = (userId: string) => { const queryClient = useQueryClient() - return queryClient.prefetchQuery(['bets', userId], () => getUserBets(userId)) + return queryClient.prefetchQuery( + ['bets', userId], + () => getUserBets(userId), + { staleTime: MINUTE_MS } + ) } export const useUserBets = (userId: string) => {