Skip to content

feat(predict): Enable Bottom Sheet via Explore page cp-7.78.0#30481

Merged
MarioAslau merged 2 commits into
mainfrom
predict/enable-bottom-explore
May 20, 2026
Merged

feat(predict): Enable Bottom Sheet via Explore page cp-7.78.0#30481
MarioAslau merged 2 commits into
mainfrom
predict/enable-bottom-explore

Conversation

@MarioAslau

@MarioAslau MarioAslau commented May 20, 2026

Copy link
Copy Markdown
Contributor

Description

Predict market cards on the Explore feed now open the Buy/Sell preview as an in-place bottom sheet (matching the dedicated Predict feed) when the predictBottomSheet feature flag is on, instead of routing to the full-page bet slip.

What changed

  1. Mounted PredictPreviewSheetProvider at the HomeTabs level in app/components/Nav/Main/MainNavigator.js, wrapping the Tab.Navigator. The provider was previously only mounted inside PredictScreenStack, so triggering openBuySheet/openSellSheet from any other tab fell back to navigation. Mounting at HomeTabs makes the sheet usable from Explore (and any future tab that needs it) while keeping the existing in-Predict behavior untouched (PredictScreenStack still mounts its own provider; the inner one shadows the outer for usage).

  2. Why mount at HomeTabs and not inside the tab itself? BottomSheet from @metamask/design-system-react-native uses absolute inset-0 for its container. If the provider is mounted inside an individual tab's content area, the sheet's parent is smaller than the viewport and the sheet gets clipped at the top of the screen and below by the bottom tab bar. Mounting at HomeTabs puts the sheet's parent at the full-viewport Home Stack.Screen card, which is the smallest level above the tab bar that gives correct dimensions.

  3. Fixed a duplicate-toast and stale-suppression bug that the new placement exposes. With both HomeTabs and PredictScreenStack providers now mounted simultaneously while the user is inside the Predict stack, both used to:

    • independently fire the state-based "Try again" failure toast on activeOrder.error transitions (no dedup in ToastService);
    • increment the same _providerSheetModeCount counter that gates shouldSuppressLegacyOrderFailureToast(), which then swallowed the legacy failure toast in tabs/flows where the active provider could not actually fire its own toast (e.g. Wallet/Trade/Money/Rewards, or HomepageDiscoveryTabs which mounts in disableBottomSheet mode).

    Replaced the module-level counter with a registration stack (_sheetModeProviders). Each entry holds the provider's id and a hasBuyParams() getter. The topmost (most recently mounted, innermost in the tree) entry is the only "active" one:

    • The state-based toast effect in PredictPreviewSheetContext.tsx bails out unless the current provider is active — so only the innermost provider fires the Retry toast.
    • shouldSuppressLegacyOrderFailureToast() now consults the active entry's hasBuyParams(), so the legacy toast is only suppressed when the active provider will actually surface its own toast.
  4. Test coverage for the multi-provider scenario in PredictPreviewSheetContext.test.tsx:

    • Topmost provider fires the failure toast exactly once when both are mounted.
    • Outer provider becomes active again after the inner unmounts.
    • Outer (sheet-mode) provider still fires when the inner provider is mounted with disableBottomSheet.
    • shouldSuppressLegacyOrderFailureToast correctly tracks the topmost provider across mount/unmount.
  5. Added PredictPreviewSheetProvider to the Predict barrel (app/components/UI/Predict/index.ts) for consistency, and a rationale comment in MainNavigator.js explaining why the wrap lives at HomeTabs (so a future maintainer doesn't move it back inside a tab).

Files touched

  • app/components/Nav/Main/MainNavigator.js
  • app/components/Nav/Main/MainNavigator.test.tsx (mock update)
  • app/components/UI/Predict/contexts/PredictPreviewSheetContext.tsx
  • app/components/UI/Predict/contexts/PredictPreviewSheetContext.test.tsx
  • app/components/UI/Predict/index.ts

Changelog

CHANGELOG entry: Added in-place buy/sell bottom sheet to Predict market cards on the Explore feed when the predictBottomSheet feature flag is enabled.

Related issues

Fixes:

Manual testing steps

Feature: Predict bottom sheet on Explore feed

  Scenario: open buy sheet from Explore with feature flag ON
    Given the predictBottomSheet feature flag is enabled
    And the user is on the Explore tab
    And the Explore feed is showing Predict market cards

    When the user taps "Yes" on a Predict market card
    Then a buy preview bottom sheet opens in place
    And the sheet is anchored above the bottom tab bar (no clipping at the top or bottom)
    And the user can swipe the sheet down to dismiss it

  Scenario: navigation fallback when feature flag is OFF
    Given the predictBottomSheet feature flag is disabled
    And the user is on the Explore tab

    When the user taps "Yes" on a Predict market card
    Then the app navigates to the full-page bet slip (legacy behavior, unchanged)

  Scenario: Predict tab behavior is unchanged
    Given the predictBottomSheet feature flag is enabled
    And the user is on the Predict tab

    When the user taps an outcome on a market card
    Then the buy preview bottom sheet opens in place (existing behavior)
    And there is exactly one Retry toast if the order subsequently fails

  Scenario: only the topmost provider fires the failure toast
    Given the predictBottomSheet feature flag is enabled
    And the user opened and dismissed a buy sheet from Explore
    And the user navigated to the Predict tab and opened/dismissed another buy sheet
    And the user is now on the Predict tab with both sheets dismissed

    When the active Predict order transitions to a failed state
    Then the user sees exactly one "Try again" toast (not two)
    And tapping Retry reopens the most recently used sheet's market context

Screenshots/Recordings

Before

After

bottomSheetExplore.mov

Pre-merge author checklist

Performance checks (if applicable)

  • I've tested on Android
  • I've tested with a power user scenario
  • I've instrumented key operations with Sentry traces for production performance metrics

Performance checks N/A: this PR only repositions an existing React provider higher in the tree and refactors a module-level counter into a registration stack. No new subscriptions/renders on hot paths; the failure-toast effect now does strictly less work in non-active providers.

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 top-level navigation composition and refactors module-scoped toast suppression/dedup logic for Predict order failures; regressions could affect bottom sheet rendering or toast behavior across tabs.

Overview
Enables Predict market cards opened outside the Predict tab (e.g. Explore) to use the in-place Buy/Sell preview bottom sheet by mounting PredictPreviewSheetProvider above the home Tab.Navigator.

Refactors PredictPreviewSheetContext to handle multiple simultaneously-mounted providers via a registration stack: only the topmost sheet-mode provider can fire the state-driven Retry toast, and legacy order-failure toast suppression now depends on the active provider having remembered buy params (reducing stale suppression). Tests are updated/added to cover multi-provider dedup and the new suppression behavior, and PredictPreviewSheetProvider is exported from the Predict barrel.

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

@MarioAslau MarioAslau self-assigned this May 20, 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.

@metamaskbotv2 metamaskbotv2 Bot added the team-predict Predict team label 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: 88%
click to see 🤖 AI reasoning details

E2E Test Selection:
The PR makes three key changes:

  1. MainNavigator.js: Wraps the entire HomeTabs component (which contains all tab screens: Home, Explore/Trending, Trade, Activity/Money, Rewards) with a new PredictPreviewSheetProvider. This is a structural navigation change, but the provider is a React context that only activates for Predict-related actions (opening buy/sell sheets). It has no side effects on non-Predict flows. The change is necessary so the BottomSheet renders inside the full-viewport stack card rather than being clipped by an individual tab's content area.

  2. PredictPreviewSheetContext.tsx: Refactors the provider registration from a simple counter to a stack-based system (_sheetModeProviders). This fixes a bug where both the outer (HomeTabs) and inner (PredictScreenStack) providers would fire duplicate failure toasts. The shouldSuppressLegacyOrderFailureToast() function now checks if the topmost provider has remembered buy params.

  3. Predict/index.ts: Exports PredictPreviewSheetProvider for use in MainNavigator.js.

Tag selection rationale:

  • SmokePredictions: Directly tests the Predictions feature. The context change affects how prediction market buy/sell sheets are displayed and how failure toasts are managed. This is the primary area of change.
  • SmokeWalletPlatform: Predictions is a section inside the Trending tab (which is part of SmokeWalletPlatform). The MainNavigator structural change wraps the Trending tab's parent navigator. Also covers the navigation structure validation.
  • SmokeConfirmations: Per SmokePredictions tag description, opening/closing positions are on-chain transactions that go through confirmations. When selecting SmokePredictions, SmokeConfirmations should also be selected.

The MainNavigator change is low-risk for other flows (SmokeAccounts, SmokeSwap, SmokeBrowser, etc.) since the PredictPreviewSheetProvider is a passive context provider that only activates for Predict-specific actions and has no impact on other navigation flows.

Performance Test Selection:
The PredictPreviewSheetContext refactoring changes how providers are registered and managed at the module level (using a stack array instead of a counter). The MainNavigator.js change adds a new provider wrapper around the entire HomeTabs component. While these are primarily correctness fixes, the new provider registration/deregistration logic runs on every mount/unmount cycle and could theoretically impact performance of the Predict flow. @PerformancePredict covers prediction market list loading, deposit flows, and balance display which are directly affected by this context change.

View GitHub Actions results

@MarioAslau MarioAslau marked this pull request as ready for review May 20, 2026 21:45
@MarioAslau MarioAslau requested a review from a team as a code owner May 20, 2026 21:46
@matallui matallui changed the title feat(predict): Enable Bottom Sheet via Explore page feat(predict): Enable Bottom Sheet via Explore page cp-7.78.0 May 20, 2026
@MarioAslau MarioAslau enabled auto-merge May 20, 2026 22:05
@sonarqubecloud

Copy link
Copy Markdown

@MarioAslau MarioAslau added this pull request to the merge queue May 20, 2026
@MarioAslau MarioAslau added the release-7.79.0 Issue or pull request that will be included in release 7.79.0 label May 20, 2026
@MarioAslau MarioAslau changed the title feat(predict): Enable Bottom Sheet via Explore page cp-7.78.0 feat(predict): Enable Bottom Sheet via Explore page cp-7.79.0 May 20, 2026
@MarioAslau MarioAslau changed the title feat(predict): Enable Bottom Sheet via Explore page cp-7.79.0 feat(predict): Enable Bottom Sheet via Explore page cp-7.78.0 May 20, 2026
@MarioAslau MarioAslau added release-7.78.0 Issue or pull request that will be included in release 7.78.0 and removed release-7.79.0 Issue or pull request that will be included in release 7.79.0 labels May 20, 2026
Merged via the queue into main with commit 22e0934 May 20, 2026
261 of 303 checks passed
@MarioAslau MarioAslau deleted the predict/enable-bottom-explore branch May 20, 2026 22:42
@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.78.0 Issue or pull request that will be included in release 7.78.0 release-7.79.0 Issue or pull request that will be included in release 7.79.0 size-M team-predict Predict team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants