Skip to content

chore(predict): migrate to keyset paginated endpoints#30159

Open
matallui wants to merge 6 commits into
mainfrom
predict/pred-881-keyset-endpoints
Open

chore(predict): migrate to keyset paginated endpoints#30159
matallui wants to merge 6 commits into
mainfrom
predict/pred-881-keyset-endpoints

Conversation

@matallui
Copy link
Copy Markdown
Contributor

@matallui matallui commented May 13, 2026

Description

Migrates the Predict market feed from Polymarket legacy offset-based list endpoints to the new keyset/cursor endpoints before deprecation.

This PR:

  • Changes Predict feed pagination from offset to afterCursor / nextCursor.
  • Migrates market feed, series, and child-event list fetches to /events/keyset.
  • Removes unused legacy /markets?condition_ids=... list helper usage.
  • Splits search out of getMarkets into searchMarkets, while keeping /public-search unchanged.
  • Adds usePredictSearchMarketData for search overlay and Trending predictions search behavior.
  • Updates controller/provider contracts, action types, tests, and component-view mocks for the new result shape.

Changelog

CHANGELOG entry: null

Related issues

Fixes: PRED-881

Manual testing steps

Feature: Predict market feed cursor pagination

  Scenario: user browses Predict markets
    Given Predict is enabled and the user opens the Predict feed

    When the feed loads the first page of markets
    Then markets are displayed using the Polymarket keyset events endpoint

    When user scrolls to the end of the feed
    Then the next page is requested with the returned cursor

  Scenario: user searches Predict markets
    Given the user opens the Predict search overlay

    When user enters a non-empty search query
    Then search results are requested through public-search

    When user clears the search query
    Then trending suggestions are shown

Screenshots/Recordings

N/A — API/data pagination migration with no intended UI changes.

Before

N/A

After

N/A

Pre-merge author checklist

Performance checks (if applicable)

  • I've tested on Android
    • Ideally on a mid-range device; emulator is acceptable
  • I've tested with a power user scenario
    • Use these power-user SRPs to import wallets with many accounts and tokens
  • I've instrumented key operations with Sentry traces for production performance metrics
    • Existing Predict controller traces were preserved/updated for cursor/search context.

For performance guidelines and tooling, see the Performance Guide.

Testing performed

  • yarn generate-method-action-types
  • yarn lint:tsc
  • NODE_OPTIONS='--max-old-space-size=12288' yarn eslint <changed files> — no errors; existing deprecation warnings only
  • CI=true NODE_OPTIONS=--max-old-space-size=8192 yarn jest app/components/UI/Predict/providers/polymarket/utils.test.ts app/components/UI/Predict/providers/polymarket/PolymarketProvider.test.ts app/components/UI/Predict/controllers/PredictController.test.ts app/components/UI/Predict/hooks/usePredictMarketData.test.tsx app/components/UI/Predict/hooks/usePredictSearchMarketData.test.tsx app/components/UI/Predict/views/PredictFeed/PredictFeed.test.tsx --runInBand --forceExit
  • CI=true NODE_OPTIONS=--max-old-space-size=8192 yarn jest -c jest.config.view.js app/components/UI/Predict/views/PredictFeed/PredictFeed.view.test.tsx --runInBand --silent --coverage=false --forceExit
  • rg "/events\\?|/events/pagination|/markets\\?" app/components/UI/Predict — no matches

Pre-merge reviewer checklist

  • I've manually tested the PR (e.g. pull and build branch, 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 such as recordings and or screenshots.

Note

Medium Risk
Medium risk due to widespread contract changes to getMarkets (new { markets, nextCursor } shape and afterCursor pagination) across controller/provider/hooks, plus new search path (searchMarkets) that affects Predict and Trending search UX and API calls.

Overview
Updates Predict market fetching to use keyset/cursor pagination instead of offset pagination: GetMarketsParams swaps offset for afterCursor, getMarkets now returns GetMarketsResult ({ markets, nextCursor }), and Polymarket requests move to gamma-api /events/keyset with parsing/typing updates.

Splits search out of getMarkets into a new PredictController.searchMarkets/PredictProvider.searchMarkets flow backed by /public-search, and adds usePredictSearchMarketData to drive the Predict feed search overlay and Trending predictions search; UI logic is adjusted to avoid showing “no results”/error states before a query is entered.

World Cup and other consumers/tests/mocks are updated to the new cursor-based contract, including new keyset API mocks and react-query test wrappers/cleanup to prevent query cache leakage.

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

@metamaskbotv2 metamaskbotv2 Bot added the team-predict Predict team label May 13, 2026
@github-actions
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.

@matallui matallui changed the title Migrate Predict markets to cursor pagination chore(predict): migrate to keyset paginated endpoints May 13, 2026
@matallui matallui marked this pull request as ready for review May 13, 2026 22:17
@matallui matallui requested review from a team as code owners May 13, 2026 22:17
Comment thread app/components/UI/Predict/hooks/usePredictSearchMarketData.tsx Outdated
Comment thread app/components/UI/Predict/hooks/usePredictSearchMarketData.tsx Outdated
Comment thread app/components/UI/Predict/views/PredictFeed/PredictFeed.tsx
Comment thread app/components/UI/Predict/views/PredictFeed/PredictFeed.test.tsx
Comment thread app/components/UI/Predict/views/PredictFeed/PredictFeed.tsx
@matallui matallui force-pushed the predict/pred-881-keyset-endpoints branch from 8b4bc37 to 40ab49d Compare May 15, 2026 21:22
Copy link
Copy Markdown
Contributor

@cursor cursor Bot left a comment

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.

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 d094762. Configure here.

queryParams,
limit: pageSize,
offset: typeof pageParam === 'number' ? pageParam : 0,
afterCursor: typeof pageParam === 'string' ? pageParam : null,
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.

World Cup infinite scroll re-fetches first page repeatedly

High Severity

World Cup infinite scroll pagination is fully broken. getNextPageParam still returns a numeric offset (allPages.length * pageSize), but fetchInfiniteWorldCupMarketsPage now expects a string cursor (typeof pageParam === 'string' ? pageParam : null). Since the page param is a number, afterCursor is always null, so every subsequent page re-fetches the first page. Additionally, fetchPredictWorldCupMarkets discards the nextCursor from the getMarkets response, so no cursor is ever available to getNextPageParam.

Additional Locations (2)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit d094762. Configure here.

@github-actions
Copy link
Copy Markdown
Contributor

🔍 Smart E2E Test Selection

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

E2E Test Selection:
The PR introduces significant architectural changes to the Predictions/Polymarket data fetching layer:

  1. API endpoint migration: The core market fetching has been migrated from /events/pagination (offset-based) to /events/keyset (cursor-based pagination). This is a breaking change in the API contract that affects all market listing flows.

  2. New searchMarkets method: A dedicated search method has been added to both PredictController and PolymarketProvider, separating search from browsing. The getMarkets method no longer accepts a q search parameter.

  3. Return type change: getMarkets now returns GetMarketsResult ({markets, nextCursor}) instead of PredictMarket[] - this is a breaking change that required updates across hooks, providers, and test mocks.

  4. New usePredictSearchMarketData hook: A new React Query-based hook was created for search functionality, replacing the previous approach of passing q to usePredictMarketData.

  5. E2E mock infrastructure updated: The polymarket mock files have been updated to support the new /events/keyset endpoint format, including the POLYMARKET_API_DOWN mock and POLYMARKET_MARKET_FEEDS_MOCKS. The default API mocks also added the new keyset endpoint.

Tags selected:

  • SmokePredictions: Directly affected - all prediction market flows (open position, cash out, claim winnings, geo restriction, withdraw) rely on the market fetching infrastructure that has been completely refactored. The E2E mocks have been updated to match the new API format.
  • SmokeWalletPlatform: The Trending view embeds Predictions as a section. The usePredictionsFeed hook used by TrendingView has been updated to use the new separate hooks. The component view test renderers for trending have also been updated with QueryClient wrappers.
  • SmokeConfirmations: Per SmokePredictions tag description, opening/closing positions are on-chain transactions that go through the confirmations flow. When selecting SmokePredictions, SmokeConfirmations should also be selected.

Performance Test Selection:
The changes introduce cursor-based pagination for market data fetching (replacing offset-based), a new dedicated search hook using React Query, and significant refactoring of the PolymarketProvider's data fetching pipeline. These changes could impact the performance of the Predictions market list loading, market data fetching latency, and the search experience. The @PerformancePredict tag covers prediction market list loading, market details, deposit flows, and balance display - all of which are affected by the new keyset-based pagination and search architecture.

View GitHub Actions results

@sonarqubecloud
Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant