Skip to content

feat(predict): Add React Query hook usePredictMarketList#30986

Merged
MarioAslau merged 3 commits into
mainfrom
predict/add-react-query-usePredictMarketList
Jun 3, 2026
Merged

feat(predict): Add React Query hook usePredictMarketList#30986
MarioAslau merged 3 commits into
mainfrom
predict/add-react-query-usePredictMarketList

Conversation

@MarioAslau

@MarioAslau MarioAslau commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

Description

Adds a React Query (useInfiniteQuery) market-list hook, usePredictMarketList, for the redesigned Predict homepage sections and generic feed screens (epic PRED-834 — IA & Navigation Overhaul).

Reason for the change: the existing usePredictMarketData hook fetches with local useState/useEffect, a hand-rolled retry loop, manual cursor tracking, and manual dedupe. The redesigned feed is built on the generic, category-free PredictController.listMarkets API (added previously), and needs a data hook that is declarative, cache-backed, and reusable across many sections driven only by params.

Solution: a new hook built on useInfiniteQuery that:

  • Calls PredictController.listMarkets (not the category-based getMarkets).
  • Supports cursor pagination via the response nextCursor (getNextPageParam).
  • Flattens pages and applies the existing feed hygiene: filterStandaloneMarkets, cross-page dedupe by id, and getVisiblePredictMarkets.
  • Exposes React Query states (isLoading, isFetching, isFetchingNextPage, error, hasNextPage) plus refetch / fetchNextPage, and an enabled option to disable fetching.
  • Uses a normalized, stable query key (fixed field order; sorted tags/series; trimmed/blank search and live: false collapse to absent).

Scope / constraints:

  • Additive only. The legacy usePredictMarketData (category / getMarkets) is not removed and remains the old/fallback feed path.
  • Plumbing only: there is no UI consumer in this PR. Section-specific curation (Up/Down series collapsing, Live Now interleaving/window-filtering/caps) intentionally lives in the consuming section components, not in this generic hook.
  • No changes to getMarkets / listMarkets server-side code.

Files:

  • app/components/UI/Predict/queries/marketList.ts (new) — normalizeMarketListParams, predictMarketListKeys, predictMarketListOptions.
  • app/components/UI/Predict/queries/index.ts — registered predictQueries.marketList.
  • app/components/UI/Predict/hooks/usePredictMarketList.ts (new) — the hook.
  • app/components/UI/Predict/queries/marketList.test.ts and app/components/UI/Predict/hooks/usePredictMarketList.test.ts (new) — tests.

Changelog

CHANGELOG entry: null

Related issues

Refs: PRED-834 (IA & Navigation Overhaul)

Manual testing steps

This is a non-UI data hook; behavior is covered by unit tests with a QueryClient wrapper (mocking PredictController.listMarkets).

Feature: usePredictMarketList data hook

  Scenario: initial load returns markets
    Given a consumer mounts the hook with enabled params
    When listMarkets resolves with a page of markets
    Then isLoading transitions from true to false
    And markets contains the visible, deduped markets

  Scenario: cursor pagination accumulates pages
    Given the first page resolves with a nextCursor
    When the consumer calls fetchNextPage
    Then listMarkets is called with afterCursor set to the prior nextCursor
    And markets contains both pages with duplicates removed by id

  Scenario: disabled hook does not fetch
    Given the hook is mounted with enabled: false
    Then listMarkets is not called
    And isLoading is false (no permanent skeleton)

  Scenario: error then recovery
    Given listMarkets rejects
    Then error is exposed as an Error
    When the consumer calls refetch and listMarkets resolves
    Then error becomes null and markets is populated

To run locally:

yarn jest app/components/UI/Predict/queries/marketList.test.ts app/components/UI/Predict/hooks/usePredictMarketList.test.ts

Result: 18 passed. yarn lint:tsc and ESLint on the changed files are clean.

Screenshots/Recordings

N/A — no UI changes in this PR (data hook only).

Before

N/A

After

N/A

Pre-merge author checklist

  • I've followed MetaMask Contributor Docs and MetaMask Mobile Coding Standards.
  • I've completed the PR template to the best of my ability.
  • I've included tests if applicable (unit tests for the hook and query options).
  • I've documented my code using JSDoc format if applicable.
  • I've applied the right labels on the PR (add team-predict + no-changelog).

Performance checks (if applicable)

  • I've tested on Android — N/A (no UI/runtime path exercised yet; no consumer).
  • I've tested with a power user scenario — N/A (no UI consumer).
  • I've instrumented key operations with Sentry traces — the underlying listMarkets controller call is already wrapped in withTrace (TraceName.PredictListMarkets); the hook adds error reporting via Logger.error.

Pre-merge reviewer checklist

  • I've manually tested the PR (run the app, test code being changed).
  • I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence.

Note

Low Risk
Additive data-layer plumbing with no production UI consumer; legacy market data path is untouched.

Overview
Adds React Query–backed infinite market listing for the redesigned Predict feed: a new predictQueries.marketList layer and usePredictMarketList, which call PredictController.listMarkets with param-driven filters and cursor pagination instead of the legacy category/getMarkets path.

The query module normalizes list params (sorted tags/series, trimmed search, live only when true, default page size) so cache keys stay stable. The hook flattens pages with per-page filterStandaloneMarkets + getVisiblePredictMarkets, dedupes by market id, exposes pagination/refetch/enabled, maps isLoading to isInitialLoading so enabled: false does not show a stuck skeleton, and logs fetch errors. No UI is wired yet; usePredictMarketData is unchanged. Unit tests cover the query helpers and hook behavior.

Reviewed by Cursor Bugbot for commit bc96b50. Bugbot is set up for automated code reviews on this repo. Configure here.

@github-actions

github-actions Bot commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes.

@MarioAslau MarioAslau added the team-predict Predict team label Jun 3, 2026
@MarioAslau MarioAslau marked this pull request as ready for review June 3, 2026 04:34
@MarioAslau MarioAslau requested a review from a team as a code owner June 3, 2026 04:34
@github-actions github-actions Bot added the size-L label Jun 3, 2026
});

return getVisiblePredictMarkets(deduped);
}, [queryResult.data]);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Disabled hook keeps cached markets

Medium Severity

When enabled is false, markets is still built from cached queryResult.data pages, so a section that was previously loaded can keep showing the old list after a feature flag or gate turns off. Sibling hooks like usePredictSearchMarketData return an empty list when disabled; legacy usePredictMarketData also clears data when enabled becomes false.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 0232247. Configure here.

@github-actions github-actions Bot added the risk:low AI analysis: low risk label Jun 3, 2026
caieu
caieu previously approved these changes Jun 3, 2026

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

There are 2 total unresolved issues (including 1 from previous review).

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 1f7d892. Configure here.

Comment thread app/components/UI/Predict/hooks/usePredictMarketList.ts Outdated
caieu
caieu previously approved these changes Jun 3, 2026
@github-actions

github-actions Bot commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

🔍 Smart E2E Test Selection

  • Selected E2E tags: SmokePredictions, SmokeWalletPlatform, SmokeConfirmations
  • Selected Performance tags: @PerformancePredict
  • Risk Level: low
  • AI Confidence: 88%
click to see 🤖 AI reasoning details

E2E Test Selection:
All 5 changed files are purely additive — new files added to the Predict feature area with no modifications to existing code. The new usePredictMarketList hook and marketList query implement cursor-based infinite pagination for the Predict market list feed. The only modification to an existing file is queries/index.ts, which only adds a new export without changing existing exports. The new hook is not yet consumed by any UI component (only its own test file imports it), so no existing user flows are affected. SmokePredictions is selected to validate existing Predict flows still work after the queries/index.ts change. Per tag dependencies: SmokePredictions requires SmokeWalletPlatform (Trending section) and SmokeConfirmations (on-chain transactions).

Performance Test Selection:
The new usePredictMarketList hook introduces infinite query pagination for market list loading using React Query's useInfiniteQuery. This directly impacts how prediction market lists are fetched and rendered, which is covered by @PerformancePredict (prediction market list loading, market details, deposit flows, and balance display). While the hook is not yet wired to UI, the query infrastructure change warrants a performance baseline check.

View GitHub Actions results

@github-actions github-actions Bot added risk:medium AI analysis: medium risk and removed risk:low AI analysis: low risk labels Jun 3, 2026
@MarioAslau MarioAslau self-assigned this Jun 3, 2026
@MarioAslau MarioAslau requested a review from caieu June 3, 2026 18:53
@MarioAslau MarioAslau added this pull request to the merge queue Jun 3, 2026
Merged via the queue into main with commit addb6b7 Jun 3, 2026
356 of 362 checks passed
@MarioAslau MarioAslau deleted the predict/add-react-query-usePredictMarketList branch June 3, 2026 19:26
@github-actions github-actions Bot locked and limited conversation to collaborators Jun 3, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

risk:medium AI analysis: medium risk size-L team-predict Predict team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants