Skip to content

fix(predict): filter stale markets from discovery feeds#30405

Merged
matallui merged 10 commits into
mainfrom
predict/PRED-747-filter-dead-resolved-markets-from-predict-feed-4-layer-staleness-system
May 20, 2026
Merged

fix(predict): filter stale markets from discovery feeds#30405
matallui merged 10 commits into
mainfrom
predict/PRED-747-filter-dead-resolved-markets-from-predict-feed-4-layer-staleness-system

Conversation

@caieu

@caieu caieu commented May 19, 2026

Copy link
Copy Markdown
Contributor

Description

This PR prevents stale or effectively settled Predict markets from occupying discovery feed surfaces.

  • Adds an isolated marketStaleness utility for probability thresholds, formal market status, daily/game expiry, time penalties, ranking penalties, and highlighted-market exceptions.
  • Applies the shared filter at hook/view-model boundaries for Predict feed data, search results, featured carousel data, and the World Cup feed without changing fetch parameters, page size, cursors, or backfill behavior.
  • Preserves highlighted-market metadata from PredictController.getMarkets, keeping open highlighted markets pinned first while still excluding closed/resolved highlighted markets.
  • Removes the old PredictMarketMultiple exact 0/1 outcome filter so display components render the outcomes already prepared by the shared feed model.

Branch review summary:

  • Base: main
  • Branch: predict/PRED-747-filter-dead-resolved-markets-from-predict-feed-4-layer-staleness-system
  • Changed files: 16
  • Commits: 7 scoped commits covering plan, utility, integration, tests, and component cleanup

Automated coverage added/updated:

  • Pure staleness policy tests for outcome thresholds, invalid probabilities, outcome groups, formal status, time expiry, ranking penalties, and highlighted-market behavior.
  • Hook integration tests for feed, search, carousel, and World Cup filtering.
  • Controller tests for highlighted-market metadata and closed/resolved highlight exclusion.
  • Component regression coverage confirming PredictMarketMultiple no longer owns price-based stale filtering.

Changelog

CHANGELOG entry: Fixed stale Predict markets appearing in discovery feeds and search results.

Related issues

Fixes: PRED-747

Related: PRED-707, PRED-533, PRED-744

Manual testing steps

Feature: Predict discovery staleness filtering

  Scenario: user views Predict discovery surfaces with stale and live markets
    Given Predict discovery data includes live markets, markets where all outcomes are at or beyond the dead probability thresholds, partially stale markets, and highlighted open markets

    When user opens the Trending tab, Predict search, featured carousel, or World Cup feed
    Then markets with no displayable live outcomes are not shown
    And partially stale markets show only live outcomes
    And open highlighted markets remain pinned first
    And closed or resolved highlighted markets are not shown
    And pagination state, cursors, and page sizes remain unchanged

Screenshots/Recordings

N/A - this is feed data filtering/ranking behavior covered by automated tests, with no intended layout or visual styling change.

Before Left / After Right

after-github.mov
before-github.mov

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
  • I've documented my code using JSDoc format if applicable - N/A, no new public API requiring JSDoc.
  • I've applied the right labels on the PR (see labeling guidelines). Not required for external contributors. Label application should be confirmed when creating the GitHub PR.

Performance checks (if applicable)

  • I've tested on Android - N/A, no native or platform-specific rendering change; automated JS coverage was added for the affected data paths.
    • Ideally on a mid-range device; emulator is acceptable
  • I've tested with a power user scenario - N/A, change is scoped to Predict feed market filtering and does not touch wallet/account/token scale paths.
    • 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 - N/A, no new network operation or long-running production operation was introduced.

For performance guidelines and tooling, see the Performance Guide.

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.

Verification

yarn jest app/components/UI/Predict/utils/marketStaleness.test.ts app/components/UI/Predict/hooks/usePredictMarketData.test.tsx app/components/UI/Predict/hooks/usePredictSearchMarketData.test.tsx app/components/UI/Predict/hooks/useFeaturedCarouselData.test.ts app/components/UI/Predict/hooks/usePredictWorldCup.test.ts app/components/UI/Predict/components/PredictMarketMultiple/PredictMarketMultiple.test.tsx --runInBand --coverage=false
yarn jest app/components/UI/Predict/controllers/PredictController.test.ts -t "getMarkets with market highlights" --runInBand --coverage=false

Note

Medium Risk
Changes Predict discovery data shaping by filtering/reshaping outcomes and re-ranking markets (including a new isHighlighted flag), which can affect what users see and pagination behavior across multiple surfaces.

Overview
Prevents stale/settled Predict markets from appearing in discovery surfaces by introducing a shared marketStaleness policy (getVisiblePredictMarkets) that drops closed/expired markets and prunes “dead” outcomes (probability near 0/1), while re-ranking remaining markets.

Applies this visibility filter in usePredictMarketData, useFeaturedCarouselData, usePredictWorldCupMarkets, and the empty-query fallback path in usePredictSearchMarketData, with tests asserting pagination/cursors remain unchanged.

Updates PredictController.getMarkets to tag fetched highlight markets with isHighlighted (kept pinned and exempt from staleness filtering), and removes PredictMarketMultiple’s old price-based outcome filtering so the UI renders outcomes as provided by the feed model.

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

@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.

@metamaskbotv2 metamaskbotv2 Bot added the team-predict Predict team label May 19, 2026
@caieu caieu marked this pull request as ready for review May 20, 2026 12:12
@caieu caieu requested a review from a team as a code owner May 20, 2026 12:12
Comment thread app/components/UI/Predict/utils/marketStaleness.ts Outdated
Comment thread PREDICT_STALENESS_FILTER_PLAN.md Outdated
@github-actions github-actions Bot added size-L and removed size-XL labels May 20, 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.

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

Comment thread app/components/UI/Predict/utils/marketStaleness.ts
@github-actions github-actions Bot added size-XL and removed size-L labels May 20, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🔍 Smart E2E Test Selection

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

E2E Test Selection:
All 15 changed files are within the app/components/UI/Predict/ directory, exclusively affecting the Predictions feature:

  1. New marketStaleness.ts utility: Introduces market staleness filtering logic with probability thresholds, time penalties, and highlighted market handling. This is a significant new filtering layer that determines which markets are visible to users.

  2. PredictController.ts: Now marks highlighted markets with isHighlighted: true so they bypass staleness filtering and always appear.

  3. types/index.ts: Adds isHighlighted?: boolean to PredictMarket type to support the new flag.

  4. PredictMarketMultiple.tsx: Removes component-level filtering of resolved outcomes (price 0 or 1) — this filtering is now centralized in marketStaleness.ts. This changes what outcomes are displayed in multi-outcome markets.

  5. Hooks (usePredictMarketData, useFeaturedCarouselData, usePredictSearchMarketData, usePredictWorldCup): All now use getVisiblePredictMarkets() to filter markets before display, replacing or augmenting previous filtering logic.

Tag selection rationale:

  • SmokePredictions: Directly affected — market listing, filtering, featured carousel, search, and World Cup views all changed. Core prediction market display logic is modified.
  • SmokeWalletPlatform: Required per SmokePredictions tag description — Predictions is a section inside the Trending tab, and changes to Predictions views affect Trending.
  • SmokeConfirmations: Required per SmokePredictions tag description — opening/closing positions are on-chain transactions that go through confirmations.

No other feature areas (accounts, swaps, network, browser, snaps, etc.) are affected by these changes.

Performance Test Selection:
The new marketStaleness.ts utility introduces sorting and filtering logic (probability calculations, time penalties, ranking scores) that runs on every market list render. The getVisiblePredictMarkets function maps, filters, and sorts market arrays which could impact rendering performance for large market lists. @PerformancePredict covers prediction market list loading and balance display, making it relevant to validate that the new staleness filtering doesn't introduce performance regressions.

View GitHub Actions results

@sonarqubecloud

Copy link
Copy Markdown

@matallui matallui added this pull request to the merge queue May 20, 2026
Merged via the queue into main with commit 3bc2d99 May 20, 2026
160 of 173 checks passed
@matallui matallui deleted the predict/PRED-747-filter-dead-resolved-markets-from-predict-feed-4-layer-staleness-system branch May 20, 2026 23:13
@github-actions github-actions Bot locked and limited conversation to collaborators May 20, 2026
@metamaskbotv2 metamaskbotv2 Bot added the release-7.79.0 Issue or pull request that will be included in release 7.79.0 label May 20, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

release-7.79.0 Issue or pull request that will be included in release 7.79.0 size-XL team-predict Predict team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants