Skip to content

refactor(predict): consolidate feature flag resolution and provider interface#26703

Merged
matallui merged 5 commits into
mainfrom
predict/permit2-pr1
Feb 27, 2026
Merged

refactor(predict): consolidate feature flag resolution and provider interface#26703
matallui merged 5 commits into
mainfrom
predict/permit2-pr1

Conversation

@matallui

@matallui matallui commented Feb 27, 2026

Copy link
Copy Markdown
Contributor

Description

Consolidates scattered feature flag resolution in PredictController into a single resolveFeatureFlags() method and injects flags into PolymarketProvider via a constructor callback.

Problem: Feature flags (liveSportsLeagues, feeCollection, marketHighlights) were resolved independently in 3 separate PredictController methods (getMarkets, getMarket, previewOrder), each calling RemoteFeatureFlagController:getState and unwrapping flags ad-hoc. These flags were then passed as method parameters to PolymarketProvider.

Solution:

  • New PredictFeatureFlags type consolidating all predict feature flags
  • New resolveFeatureFlags() private method on PredictController — single resolution point
  • PolymarketProvider now takes a getFeatureFlags callback in constructor and reads flags internally
  • Cleaned PredictProvider interface — removed per-method flag parameters (liveSportsLeagues, feeCollection)
  • Removed liveSportsLeagues from GetMarketsParams (internal concern, not caller-facing)

This is a pure refactor — zero behavior changes. Foundation for upcoming Permit2 fee authorization support.

Changelog

CHANGELOG entry: null

Related issues

Fixes: https://consensyssoftware.atlassian.net/browse/PRED-715

Manual testing steps

Feature: Predict feature flag resolution refactor

  Scenario: user places prediction market orders as before
    Given user has Predict feature enabled and is in a supported region

    When user browses markets, views market details, and previews/places orders
    Then all functionality works identically to before (no behavior changes)

Screenshots/Recordings

N/A — pure refactor, no UI changes.

Before

N/A

After

N/A

Pre-merge author checklist

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
Touches Predict market fetching and order preview paths by changing how feature flags are resolved and threaded into the Polymarket provider. Risk is mainly around mismatched defaults or missing flag injection impacting live sports overlays, highlights ordering, or fee collection in previews.

Overview
Refactors Predict feature-flag plumbing by introducing PredictFeatureFlags and a single PredictController.resolveFeatureFlags() that reads remote flags (live sports leagues, market highlights, fee collection) and supplies them to PolymarketProvider via a getFeatureFlags constructor callback.

PolymarketProvider now consumes flags internally (no longer accepts liveSportsLeagues/feeCollection as method params), and the PredictProvider/GetMarketsParams types are simplified accordingly. Tests are updated to match the new provider constructor + method signatures and to assert fee collection defaults are applied during previewOrder and highlight fetching.

Written by Cursor Bugbot for commit fdb4a95. This will update automatically on new commits. Configure here.

@matallui matallui added the team-predict Predict team label Feb 27, 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 added the no-changelog no-changelog Indicates no external facing user changes, therefore no changelog documentation needed label Feb 27, 2026
@matallui matallui marked this pull request as ready for review February 27, 2026 18:50
@matallui matallui requested a review from a team as a code owner February 27, 2026 18:50
Comment thread app/components/UI/Predict/constants/flags.ts Outdated
Comment thread app/components/UI/Predict/providers/polymarket/PolymarketProvider.ts Outdated
Introduce a consolidated PredictFeatureFlags interface that groups all
predict feature flags (feeCollection, liveSportsLeagues, marketHighlightsFlag)
into a single type. Add DEFAULT_PREDICT_FEATURE_FLAGS constant.

Clean PredictProvider interface by removing per-method flag parameters
(liveSportsLeagues, feeCollection) — these will be read internally by
the provider via a getFeatureFlags callback.

Remove liveSportsLeagues from GetMarketsParams since it is an internal
concern, not a caller-facing parameter.
@matallui matallui force-pushed the predict/permit2-pr1 branch from 6da4fb1 to 085e3be Compare February 27, 2026 19:06
Comment thread app/components/UI/Predict/providers/polymarket/PolymarketProvider.test.ts Outdated
caieu
caieu previously approved these changes Feb 27, 2026

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

LGTM

…vider

PolymarketProvider now receives a getFeatureFlags callback via its
constructor instead of receiving flags as per-method parameters.

The provider reads liveSportsLeagues, feeCollection, and other flags
internally, eliminating the need for callers to resolve and pass them.
…roller

Replace scattered RemoteFeatureFlagController:getState calls across
getMarkets(), getMarket(), and previewOrder() with a single
resolveFeatureFlags() method that returns a PredictFeatureFlags object.

This eliminates ~35 lines of duplicated flag resolution code from 3
separate methods and centralizes it in one reusable private method.
Comment thread app/components/UI/Predict/controllers/PredictController.ts Outdated
…ghtsFlag

resolveFeatureFlags() already validates the version gate and falls back
to DEFAULT_MARKET_HIGHLIGHTS_FLAG when invalid. The second call to
validatedVersionGatedFeatureFlag() in getMarkets() was redundant.

Replace with a check on highlights.length, which is the actual semantic
guard — the resolver guarantees the flag is always valid.

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

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

Comment thread app/components/UI/Predict/controllers/PredictController.ts Outdated
Extract highlights with ?? [] fallback before accessing .length to
prevent TypeError if remote flag data is malformed (passes version
validation but lacks highlights property). Reuse the guarded variable
in both the shouldFetchHighlights check and the market ID lookup.
@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: 85%
click to see 🤖 AI reasoning details

E2E Test Selection:
This PR refactors how feature flags are passed to the PolymarketProvider in the Predict feature. The changes include:

  1. PredictController.ts: Creates a new resolveFeatureFlags() method and passes a getFeatureFlags callback to PolymarketProvider constructor instead of passing flags as parameters to individual methods like getMarkets(), getMarketDetails(), and previewOrder().

  2. PolymarketProvider.ts: Now accepts a getFeatureFlags callback in constructor and internally calls it when needed, simplifying method signatures.

  3. Type changes: New PredictFeatureFlags interface, updated PredictProvider interface to remove feature flag parameters.

This is an internal refactoring that doesn't change user-facing functionality but affects the core prediction market controller. The changes are well-tested with updated unit tests.

Tag Selection Rationale:

  • SmokePredictions: Directly tests Polymarket prediction market integration - opening positions, cashing out, claiming winnings, balance synchronization. This is the primary affected feature.
  • SmokeWalletPlatform: Per tag description, Predictions is a section inside the Trending tab, so changes to Predictions views affect this tag.
  • SmokeConfirmations: Per SmokePredictions tag description, opening/closing positions are on-chain transactions that require confirmations.

Performance Test Selection:
The changes affect how the PredictController and PolymarketProvider handle feature flags. While this is primarily a refactoring, the change from passing feature flags as method parameters to using a callback that resolves flags lazily could potentially affect the performance of prediction market operations (loading markets, previewing orders, etc.). The @PerformancePredict tag covers prediction market list loading, market details, deposit flows, and balance display - all of which are affected by this refactoring.

View GitHub Actions results

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

LGTM

@matallui matallui added this pull request to the merge queue Feb 27, 2026
Merged via the queue into main with commit 9bfc6fa Feb 27, 2026
97 checks passed
@matallui matallui deleted the predict/permit2-pr1 branch February 27, 2026 21:40
@github-actions github-actions Bot locked and limited conversation to collaborators Feb 27, 2026
@metamaskbot metamaskbot added the release-7.69.0 Issue or pull request that will be included in release 7.69.0 label Feb 27, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

no-changelog no-changelog Indicates no external facing user changes, therefore no changelog documentation needed release-7.69.0 Issue or pull request that will be included in release 7.69.0 size-M team-predict Predict team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants