Commit 5524c8d5 authored by Max Alekseenko's avatar Max Alekseenko

replace ref with state to fix test

parent 9a47831c
...@@ -57,15 +57,16 @@ export default function useMarketplaceApps( ...@@ -57,15 +57,16 @@ export default function useMarketplaceApps(
const apiFetch = useApiFetch(); const apiFetch = useApiFetch();
// Update favorite apps only when selectedCategoryId changes to avoid sortApps to be called on each favorite app click // Update favorite apps only when selectedCategoryId changes to avoid sortApps to be called on each favorite app click
const lastFavoriteAppsRef: React.MutableRefObject<Array<string> | undefined> = React.useRef(); const [ snapshotFavoriteApps, setSnapshotFavoriteApps ] = React.useState<Array<string> | undefined>();
React.useEffect(() => { React.useEffect(() => {
if (isFavoriteAppsLoaded) { if (isFavoriteAppsLoaded) {
lastFavoriteAppsRef.current = favoriteApps; setSnapshotFavoriteApps(favoriteApps);
} }
}, [ selectedCategoryId, isFavoriteAppsLoaded ]); // eslint-disable-line react-hooks/exhaustive-deps }, [ selectedCategoryId, isFavoriteAppsLoaded ]); // eslint-disable-line react-hooks/exhaustive-deps
const { isPlaceholderData, isError, error, data } = useQuery<unknown, ResourceError<unknown>, Array<MarketplaceAppOverview>>({ const { isPlaceholderData, isError, error, data } = useQuery<unknown, ResourceError<unknown>, Array<MarketplaceAppOverview>>({
queryKey: [ 'marketplace-dapps', lastFavoriteAppsRef.current, favoriteApps ], queryKey: [ 'marketplace-dapps', snapshotFavoriteApps, favoriteApps ],
queryFn: async() => { queryFn: async() => {
if (!feature.isEnabled) { if (!feature.isEnabled) {
return []; return [];
...@@ -75,10 +76,10 @@ export default function useMarketplaceApps( ...@@ -75,10 +76,10 @@ export default function useMarketplaceApps(
return apiFetch('marketplace_dapps', { pathParams: { chainId: config.chain.id } }); return apiFetch('marketplace_dapps', { pathParams: { chainId: config.chain.id } });
} }
}, },
select: (data) => sortApps(data as Array<MarketplaceAppOverview>, lastFavoriteAppsRef.current || []), select: (data) => sortApps(data as Array<MarketplaceAppOverview>, snapshotFavoriteApps || []),
placeholderData: feature.isEnabled ? Array(9).fill(MARKETPLACE_APP) : undefined, placeholderData: feature.isEnabled ? Array(9).fill(MARKETPLACE_APP) : undefined,
staleTime: Infinity, staleTime: Infinity,
enabled: feature.isEnabled && (!favoriteApps || Boolean(lastFavoriteAppsRef.current)), enabled: feature.isEnabled && (!favoriteApps || Boolean(snapshotFavoriteApps)),
}); });
const displayedApps = React.useMemo(() => { const displayedApps = React.useMemo(() => {
......
...@@ -18,7 +18,7 @@ const test = base.extend({ ...@@ -18,7 +18,7 @@ const test = base.extend({
]) as any, ]) as any,
}); });
test('base view +@dark-mode', async({ mount, page }) => { test('base view +@mobile +@dark-mode', async({ mount, page }) => {
await page.route(MARKETPLACE_CONFIG_URL, (route) => route.fulfill({ await page.route(MARKETPLACE_CONFIG_URL, (route) => route.fulfill({
status: 200, status: 200,
body: JSON.stringify(appsMock), body: JSON.stringify(appsMock),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment