Skip to content

refactor(predict): simplify to single-provider architecture#26031

Merged
matallui merged 13 commits intomainfrom
predict/single-provider
Feb 12, 2026
Merged

refactor(predict): simplify to single-provider architecture#26031
matallui merged 13 commits intomainfrom
predict/single-provider

Conversation

@matallui
Copy link
Copy Markdown
Contributor

@matallui matallui commented Feb 12, 2026

Description

The PredictController was designed with multi-provider support (using a Map<string, PredictProvider>), but we only ever use Polymarket and have no plans to support additional providers. This PR simplifies the entire Predict feature to single-provider architecture.

Changes:

  • Controller core: Replace providers: Map<string, PredictProvider> with a single provider: PolymarketProvider instance. Remove initialization machinery (initializeProviders, performInitialization, isInitialized).
  • State shape: Flatten eligibility, balances, and pendingDeposits by removing the provider-key nesting. accountMeta is left unchanged for backwards compatibility (persisted data).
  • Type interfaces: Remove providerId from all param types (GetMarketsParams, GetPositionsParams, PlaceOrderParams, PreviewOrderParams, GetPriceHistoryParams, GetPriceParams, GetBalanceParams, etc.)
  • Hooks: Remove providerId option from all ~20 hooks
  • Selectors: Update selectPredictBalanceByAddress and selectPredictPendingDepositByAddress to use flat state
  • Components/Views: Remove providerId prop passing throughout UI layer
  • Tests: Update all test files for new state shapes and method signatures

Changelog

CHANGELOG entry: null

Related issues

Fixes:

Manual testing steps

Feature: Predict market functionality

  Scenario: user interacts with prediction markets
    Given user has the Predict feature enabled

    When user browses markets, views positions, places orders, deposits, withdraws, or claims
    Then all functionality works identically to before the refactoring

Screenshots/Recordings

N/A — no UI changes, purely internal refactoring.

Before

Multi-provider architecture with Map<string, PredictProvider> and providerId params throughout.

After

Single PolymarketProvider instance, flat state shapes, no providerId params needed.

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
Broad signature/state refactor across Predict hooks and components could cause subtle runtime breakage if any call sites or controller methods still expect providerId. Risk is mitigated by updated unit tests but warrants focused regression on deposit/claim/cashout flows and price-history fetching.

Overview
Refactors Predict toward a single-provider (Polymarket) model by removing providerId parameters/props from UI calls into Predict hooks (e.g., usePredictActionGuard, usePredictClaim, useUnrealizedPnL, usePredictPriceHistory).

Updates affected components (e.g., balance/add-funds sheets, market cards, picks, position details, game chart) to rely on navigation/market IDs only, and adjusts tests accordingly (replacing hardcoded 'polymarket' strings with POLYMARKET_PROVIDER_ID and deleting coverage for custom provider IDs).

Reworks PredictController.getActivity unit test to construct a real messenger-backed controller and to mock PolymarketProvider directly, validating default selected-address behavior and explicit-address overrides without multi-provider merging/lookup scenarios.

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

…rovider in controller

Replace providers: Map<string, PredictProvider> with a single provider:
PolymarketProvider instance. Remove initialization machinery
(initializeProviders, performInitialization, isInitialized).
Simplify all method signatures to remove providerId param.
Flatten state shape for eligibility, balances, pendingDeposits
(accountMeta left unchanged for backwards compatibility).
Remove providerId from GetMarketsParams, GetPositionsParams,
PlaceOrderParams, PreviewOrderParams, GetPriceHistoryParams,
GetPriceParams, GetBalanceParams. Convert PrepareDepositParams,
PrepareWithdrawParams, GetAccountStateParams, ClaimParams to
empty interfaces. Clean up Omit<..., 'providerId'> patterns in
PredictProvider interface and PolymarketProvider.
Update selectPredictBalanceByAddress and
selectPredictPendingDepositByAddress to take { address }
instead of { providerId, address }. Access flat state
directly (balances[address] instead of
balances[providerId][address]).
Remove providerId from hook option interfaces and all
downstream calls to controller methods and selectors.
Hooks now use the single provider implicitly.
Remove providerId from component props, hook calls, and
child component prop passing across all Predict UI files.
…er architecture

Update PredictController.test.ts, PolymarketProvider.test.ts,
utils.test.ts, and Engine predict-controller index.test.ts to
use flat state shapes and remove providerId from all method
call params. Remove multi-provider test cases.
Remove providerId from all hook test option objects,
controller call assertions, and component test props.
Update mock state shapes for flat eligibility, balances,
and pendingDeposits.
@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.

@metamaskbot metamaskbot added the team-predict Predict team label Feb 12, 2026
@matallui matallui force-pushed the predict/single-provider branch from 9d0900b to 8a8e3fa Compare February 12, 2026 18:23
@matallui matallui marked this pull request as ready for review February 12, 2026 18:24
@matallui matallui requested a review from a team as a code owner February 12, 2026 18:24
Copy link
Copy Markdown

@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 4 potential issues.

Remove obsolete tests for deleted functionality (provider
initialization, performInitialization, provider-not-available
error paths, multi-provider aggregation). Fix remaining tests
to match new flat state shapes and single-provider mock setup.
Rewrite getActivity test to use real controller with mocked
PolymarketProvider constructor.
…le-provider

Update mock state shapes (flat balances, pendingDeposits,
eligibility), remove providerId from toHaveBeenCalledWith
assertions and hook option expectations. Delete tests for
removed custom-providerId behavior.
…ith POLYMARKET_PROVIDER_ID

Replace all 169 occurrences across 34 production and test files
with the POLYMARKET_PROVIDER_ID constant from constants.ts.
@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 is a significant refactoring of the PredictController that removes the multi-provider architecture and simplifies the API by removing the providerId parameter from all hooks and controller methods. The changes include:

  1. PredictController state structure changes: The eligibility, balances, and pendingDeposits state structures have been simplified from provider-keyed objects to direct address-keyed objects.

  2. API changes across all Predict hooks: usePredictBalance, usePredictEligibility, usePredictDeposit, usePredictPositions, usePredictClaim, usePredictWithdraw, usePredictActivity, usePredictMarket, usePredictOrderPreview, and usePredictActionGuard no longer accept providerId.

  3. View components updated: PredictBuyPreview, PredictSellPreview, and PredictMarketDetails views have been updated to use the simplified API.

  4. Test state updated: initial-background-state.json has been updated to reflect the new eligibility structure.

Tag Selection Rationale:

  • SmokePredictions: Required - This is the primary tag for Predictions functionality. All E2E tests in tests/smoke/predict/ test the Predictions feature which is directly affected by these changes.
  • SmokeWalletPlatform: Required per tag description - Predictions is a section inside the Trending tab, and changes to Predictions views affect Trending.
  • SmokeConfirmations: Required per tag description - Opening/closing positions and deposits are on-chain transactions that go through confirmations.

The risk is medium because while this is a significant internal refactoring, it's primarily removing unused multi-provider flexibility rather than changing core functionality. All unit tests have been updated, and the changes are well-contained within the Predict feature.

Performance Test Selection:
The PredictController changes affect how data is fetched and stored for the Predictions feature. While the changes are primarily structural (removing providerId indirection), they could potentially impact performance of balance loading, position fetching, and eligibility checks. The @PerformancePredict tag should be run to verify that the simplified architecture doesn't introduce any performance regressions in prediction market list loading, market details, deposit flows, and balance display.

View GitHub Actions results

@sonarqubecloud
Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
D Reliability Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

@matallui matallui added the skip-sonar-cloud Only used for bypassing sonar cloud when failures are not relevant to the changes. label Feb 12, 2026
@matallui matallui enabled auto-merge February 12, 2026 20:42
@matallui matallui requested a review from caieu February 12, 2026 21:19
Copy link
Copy Markdown
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 added this pull request to the merge queue Feb 12, 2026
Merged via the queue into main with commit 0b6abdb Feb 12, 2026
168 of 173 checks passed
@matallui matallui deleted the predict/single-provider branch February 12, 2026 21:46
@github-actions github-actions bot locked and limited conversation to collaborators Feb 12, 2026
@metamaskbot metamaskbot added the release-7.67.0 Issue or pull request that will be included in release 7.67.0 label Feb 12, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

release-7.67.0 Issue or pull request that will be included in release 7.67.0 size-XL skip-sonar-cloud Only used for bypassing sonar cloud when failures are not relevant to the changes. team-predict Predict team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants