diff --git a/apps/wallet-mobile/src/features/Portfolio/common/PortfolioProvider.tsx b/apps/wallet-mobile/src/features/Portfolio/common/PortfolioProvider.tsx index fd267fdcab..1a339f5c34 100644 --- a/apps/wallet-mobile/src/features/Portfolio/common/PortfolioProvider.tsx +++ b/apps/wallet-mobile/src/features/Portfolio/common/PortfolioProvider.tsx @@ -56,13 +56,7 @@ const PortfolioContext = React.createContext( ...defaultActions, }) -export const PortfolioProvider = ({ - children, - initialState, -}: { - children: React.ReactNode - initialState?: Partial -}) => { +const useIsTokenHistoryApiAvailable = () => { const { networkManager: {tokenManager}, } = useSelectedNetwork() @@ -78,7 +72,17 @@ export const PortfolioProvider = ({ return false }, }) - const isTokenHistoryApiAvailable = data ?? false + return data ?? false +} + +export const PortfolioProvider = ({ + children, + initialState, +}: { + children: React.ReactNode + initialState?: Partial +}) => { + const isTokenHistoryApiAvailable = useIsTokenHistoryApiAvailable() const [portfolioState, dispatch] = React.useReducer(portfolioReducer, {...defaultState, ...initialState}) const actions = React.useRef({ diff --git a/apps/wallet-mobile/src/features/Portfolio/common/hooks/useGetPortfolioTokenChart.ts b/apps/wallet-mobile/src/features/Portfolio/common/hooks/useGetPortfolioTokenChart.ts index f0442af26a..51c5ac09e4 100644 --- a/apps/wallet-mobile/src/features/Portfolio/common/hooks/useGetPortfolioTokenChart.ts +++ b/apps/wallet-mobile/src/features/Portfolio/common/hooks/useGetPortfolioTokenChart.ts @@ -96,7 +96,7 @@ export const useGetPortfolioTokenChart = ( enabled: tokenInfo && isPrimaryToken(tokenInfo.info), staleTime: time.oneMinute, ...options, - queryKey: ['useGetPortfolioTokenChart', '.', timeInterval, currency], + queryKey: ['useGetPortfolioTokenChart', 'pt', timeInterval, currency], queryFn: async () => { // force queryFn to be async, otherwise it takes longer and doesn't show isFetching await delay(0) diff --git a/apps/wallet-mobile/src/kernel/query-client.ts b/apps/wallet-mobile/src/kernel/query-client.ts index 4980730918..9ed88aa570 100644 --- a/apps/wallet-mobile/src/kernel/query-client.ts +++ b/apps/wallet-mobile/src/kernel/query-client.ts @@ -5,19 +5,23 @@ import {ptPriceQueryFn, TokenChartInterval} from '../features/Portfolio/common/h const queryClient = new QueryClient() -Object.values(TokenChartInterval).forEach((TokenChartInterval) => { - queryClient.prefetchQuery< - Awaited>, - Error, - Awaited>, - ['ptPriceHistory', TokenChartInterval] - >({ - queryKey: ['ptPriceHistory', TokenChartInterval], - queryFn: ptPriceQueryFn, - cacheTime: Infinity, - staleTime: Infinity, +const prefetchPtPriceHistory = () => { + Object.values(TokenChartInterval).forEach((TokenChartInterval) => { + queryClient.prefetchQuery< + Awaited>, + Error, + Awaited>, + ['ptPriceHistory', TokenChartInterval] + >({ + queryKey: ['ptPriceHistory', TokenChartInterval], + queryFn: ptPriceQueryFn, + cacheTime: Infinity, + staleTime: Infinity, + }) }) -}) +} + +prefetchPtPriceHistory() const keyToPersist = 'persist' /*