Skip to content

Conversation

@matallui
Copy link
Contributor

@matallui matallui commented Nov 11, 2025

Description

This PR migrates the Predict feature flag from a simple boolean flag to a version-gated feature flag structure, aligning it with the pattern used by Perps and other features.

What is the reason for the change?
The Predict feature needs version gating to ensure users have the minimum required app version (7.60.0) before accessing the feature. The previous implementation used a simple boolean flag (predictEnabled) which didn't support version checking.

What is the improvement/solution?

  • Changed flag name from predictEnabled to predictTradingEnabled to follow naming conventions
  • Implemented version-gated structure with enabled and minimumVersion properties
  • Added environment variable fallback (MM_PREDICT_ENABLED) for local development
  • Updated all references across the codebase (selectors, tests, mocks, E2E helpers)
  • Ensured backward compatibility by maintaining the same boolean return type

Changelog

CHANGELOG entry: null

Related issues

Fixes:

Manual testing steps

Feature: Predict feature flag version gating

  Scenario: user with app version below minimum cannot access Predict
    Given user has app version 7.59.0
    And remote feature flag predictTradingEnabled is enabled with minimumVersion "7.60.0"

    When user navigates to Wallet screen
    Then Predict feature should not be visible/accessible

  Scenario: user with app version at or above minimum can access Predict
    Given user has app version 7.60.0 or higher
    And remote feature flag predictTradingEnabled is enabled with minimumVersion "7.60.0"

    When user navigates to Wallet screen
    Then Predict feature should be visible and accessible

  Scenario: local environment variable overrides when remote flag unavailable
    Given remote feature flags are empty or invalid
    And MM_PREDICT_ENABLED environment variable is set to "true"

    When app initializes
    Then Predict feature should be enabled based on local flag

  Scenario: remote flag takes precedence over local flag
    Given remote feature flag predictTradingEnabled is explicitly disabled
    And MM_PREDICT_ENABLED environment variable is set to "true"

    When app initializes
    Then Predict feature should be disabled (remote flag overrides local)

Screenshots/Recordings

Not applicable - This is an internal refactoring with no UI changes.

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.

Technical Details

Files Modified (7 total)

  1. app/components/UI/Predict/selectors/featureFlags/index.ts

    • Migrated from boolean flag to VersionGatedFeatureFlag structure
    • Changed flag name: predictEnabledpredictTradingEnabled
    • Added environment variable fallback: MM_PREDICT_ENABLED
    • Added comprehensive JSDoc documentation
  2. app/components/UI/Predict/selectors/featureFlags/index.test.ts

    • Rewrote tests following unit testing guidelines (AAA pattern)
    • Added comprehensive test coverage for version gating
    • Added tests for remote flag precedence over local flags
    • Added tests for invalid flag scenarios
    • All 19 tests passing ✅
  3. app/components/UI/Predict/mocks/remoteFeatureFlagMocks.ts

    • Updated mock structure to version-gated format
  4. app/components/Views/Wallet/index.test.tsx

    • Updated 5 occurrences of predictEnabledpredictTradingEnabled
  5. .js.env.example

    • Added MM_PREDICT_ENABLED environment variable example
  6. e2e/api-mocking/helpers/remoteFeatureFlagsHelper.ts

    • Updated default mock to version-gated structure
  7. e2e/api-mocking/mock-responses/feature-flags-mocks.ts

    • Updated remoteFeatureFlagPredictEnabled function

Key Implementation Details

  • Flag Structure: { enabled: boolean, minimumVersion: string }
  • Backend Flag Name: predictTradingEnabled
  • Minimum Version: 7.60.0
  • Local Fallback: MM_PREDICT_ENABLED environment variable (defaults to false)
  • Validation: Uses validatedVersionGatedFeatureFlag() utility for type checking and version validation

Test Coverage

  • ✅ Remote flag precedence over local flags
  • ✅ Version gating validation
  • ✅ Invalid flag type handling
  • ✅ Fallback to local environment variable
  • ✅ Edge cases (null, undefined, empty objects)

Breaking Changes

None - The selector maintains the same boolean return type, ensuring backward compatibility with existing code.


Note

Migrates Predict flag to version-gated predictTradingEnabled (with minimumVersion and MM_PREDICT_ENABLED fallback) and updates selectors, tests, and mocks accordingly.

  • Predict feature flag:
    • Rename predictEnabledpredictTradingEnabled.
    • Adopt version-gated structure { enabled, minimumVersion } (min app 7.60.0).
    • Update selector to validate remote flag and fallback to MM_PREDICT_ENABLED.
  • Tests:
    • Add/expand unit tests for precedence, version gating, and invalid scenarios in selectors/featureFlags.
    • Update Wallet tests to use predictTradingEnabled objects.
  • Mocks/E2E:
    • Update Predict mocks and remote flags helpers to new structure.
    • Add MM_PREDICT_ENABLED to .js.env.example.

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

@github-actions
Copy link
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.

@metamaskbot metamaskbot added the team-predict Predict team label Nov 11, 2025
@matallui matallui marked this pull request as ready for review November 11, 2025 22:37
@matallui matallui requested a review from a team as a code owner November 11, 2025 22:37
Copy link
Contributor

@caieu caieu left a comment

Choose a reason for hiding this comment

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

LGTM

@matallui matallui enabled auto-merge November 11, 2025 22:56
@sonarqubecloud
Copy link

@matallui matallui added this pull request to the merge queue Nov 11, 2025
Merged via the queue into main with commit cabf6d9 Nov 11, 2025
86 checks passed
@matallui matallui deleted the predict/version-feature-flag branch November 11, 2025 23:33
@github-actions github-actions bot locked and limited conversation to collaborators Nov 11, 2025
@metamaskbot metamaskbot added the release-7.60.0 Issue or pull request that will be included in release 7.60.0 label Nov 11, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

release-7.60.0 Issue or pull request that will be included in release 7.60.0 size-M team-predict Predict team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants