Skip to content

fix: reject predictDepositAndOrder before opening Add Funds flow#30508

Merged
OGPoyraz merged 1 commit into
mainfrom
ogp/predict-add-action-fix
May 21, 2026
Merged

fix: reject predictDepositAndOrder before opening Add Funds flow#30508
OGPoyraz merged 1 commit into
mainfrom
ogp/predict-add-action-fix

Conversation

@OGPoyraz

@OGPoyraz OGPoyraz commented May 21, 2026

Copy link
Copy Markdown
Member

Description

When the user taps "Add" on the Predict balance row in the pay-with picker during a predictDepositAndOrder confirmation, the existing flow creates a predictDeposit transaction on top of the active predictDepositAndOrder confirmation. This causes two issues:

  1. Stacking confirmations is unsafe - we assume a single active transaction at a time
  2. The pay-with modal doesn't work on the second confirmation because it's on the wrong navigation stack

Fix

Mirror the Perps pattern (usePerpsBalanceTokenFilter):

  1. dismissActivePreviewSheet() - instantly removes the PredictPreviewSheet overlay (module-level function that calls setBuyParams(null) on the active provider)
  2. onReject() - rejects the existing predictDepositAndOrder approval
  3. navigation.navigate(ADD_FUNDS_SHEET) - opens the deposit flow cleanly

Changes

  • usePredictBalanceTokenFilter.ts - handleAddFunds now calls dismissActivePreviewSheet() + onReject() before navigating to Add Funds
  • PredictPreviewSheetContext.tsx - Extended SheetModeProviderEntry with dismissPreviewSheet callback; added exported dismissActivePreviewSheet() function that dismisses the active provider's sheet from anywhere (including outside the context tree)
  • contexts/index.ts - Export dismissActivePreviewSheet
  • usePredictBalanceTokenFilter.test.ts - Updated test to mock useApprovalRequest, usePredictDeposit, and assert onReject is called

Manual testing steps

  1. Open a prediction market and tap a bet outcome
  2. In the buy sheet, tap "Pay with" to open the token picker
  3. Tap "Add" next to "Predict balance"
  4. Verify: the buy sheet and predictDepositAndOrder confirmation are dismissed
  5. Verify: the Add Prediction Funds flow opens cleanly on top

Screenshots/Recordings

Before

predict.add.funds.before.mp4

After

predict.add.funds.after.mov

Pre-merge author checklist

  • I've followed MetaMask Contributor Docs
  • 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
  • I've applied the right labels on the PR
  • I've properly set the title of this PR
  • If applicable, I've included the Run Smoke E2E and/or Run Full E2E label to run smoke/full E2E tests

Note

Medium Risk
Changes Predict confirmation flow by programmatically dismissing the active preview sheet and rejecting the current approval before starting the Add Funds navigation; mistakes could interrupt user order/confirmation state or leave UI in an inconsistent dismissal state.

Overview
Prevents stacking a new Add Funds deposit flow on top of an active predictDepositAndOrder confirmation when users tap Add on the Predict balance row.

Introduces a module-level dismissActivePreviewSheet() in PredictPreviewSheetContext (tracked per active provider) and updates usePredictBalanceTokenFilter to call onReject() + dismissActivePreviewSheet() before navigating to ADD_FUNDS_SHEET; associated unit test now mocks useApprovalRequest and asserts both calls occur.

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

@OGPoyraz OGPoyraz requested a review from a team as a code owner May 21, 2026 10:50
@metamaskbotv2 metamaskbotv2 Bot added the team-confirmations Push issues to confirmations team label May 21, 2026
@OGPoyraz OGPoyraz added the team-predict Predict team label May 21, 2026
@OGPoyraz OGPoyraz changed the title fix: reject predictDepositAndOrder before opening Add Funds flow fix: reject predictDepositAndOrder before opening Add Funds flow May 21, 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 2 potential issues.

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 5d1aa3c. Configure here.

Comment thread app/components/UI/Predict/hooks/usePredictBalanceTokenFilter.test.ts Outdated
@OGPoyraz OGPoyraz force-pushed the ogp/predict-add-action-fix branch from 5d1aa3c to f4d9f81 Compare May 21, 2026 10:58
@github-actions

Copy link
Copy Markdown
Contributor

🔍 Smart E2E Test Selection

  • Selected E2E tags: SmokePredictions, SmokeWalletPlatform, SmokeConfirmations
  • Selected Performance tags: None (no tests recommended)
  • Risk Level: medium
  • AI Confidence: 88%
click to see 🤖 AI reasoning details

E2E Test Selection:
The changes are scoped to the Predict feature (Polymarket integration):

  1. PredictPreviewSheetContext.tsx: Added dismissPreviewSheet to the context interface and a new exported dismissActivePreviewSheet() utility function that allows external callers to dismiss the active preview sheet.

  2. usePredictBalanceTokenFilter.ts: Modified handleAddFunds to now call onReject() (reject current approval request) and dismissActivePreviewSheet() before navigating to ADD_FUNDS_SHEET. This is a behavioral change in the "Add Funds" flow within Predict confirmations.

  3. Test file: Updated to verify the new rejection + dismissal behavior.

Tag selection rationale:

  • SmokePredictions: Primary tag - directly tests the Predict/Polymarket feature including position opening flows that involve the preview sheet and add funds flow.
  • SmokeWalletPlatform: Required per SmokePredictions description - Predictions is a section inside the Trending tab, so changes to Predictions views affect Trending.
  • SmokeConfirmations: Required per SmokePredictions description - opening/closing positions are on-chain transactions. Additionally, the change modifies how approval requests are rejected (onReject() is now called in the Add Funds flow), which directly touches the confirmation/approval system.

The risk is medium because the change modifies a user flow (Add Funds from within a prediction confirmation) by adding approval rejection before navigation, which could affect the confirmation state machine if not handled correctly.

Performance Test Selection:
The changes are behavioral/flow fixes within the Predict feature - adding approval rejection and sheet dismissal before navigation. These are not performance-sensitive operations (no list rendering changes, no data loading changes, no state management architecture changes). No performance tests are warranted.

View GitHub Actions results

@OGPoyraz OGPoyraz added the no-changelog no-changelog Indicates no external facing user changes, therefore no changelog documentation needed label May 21, 2026
@sonarqubecloud

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
58.3% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

@OGPoyraz OGPoyraz added the skip-sonar-cloud Only used for bypassing sonar cloud when failures are not relevant to the changes. label May 21, 2026
@metamaskbotv2 metamaskbotv2 Bot added the INVALID-PR-TEMPLATE PR's body doesn't match template label May 21, 2026
@OGPoyraz OGPoyraz enabled auto-merge May 21, 2026 13:46
@OGPoyraz OGPoyraz added this pull request to the merge queue May 21, 2026
Merged via the queue into main with commit 255c7b9 May 21, 2026
249 of 268 checks passed
@OGPoyraz OGPoyraz deleted the ogp/predict-add-action-fix branch May 21, 2026 14:08
@github-actions github-actions Bot locked and limited conversation to collaborators May 21, 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 21, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

INVALID-PR-TEMPLATE PR's body doesn't match template no-changelog no-changelog Indicates no external facing user changes, therefore no changelog documentation needed release-7.79.0 Issue or pull request that will be included in release 7.79.0 size-S skip-sonar-cloud Only used for bypassing sonar cloud when failures are not relevant to the changes. team-confirmations Push issues to confirmations team team-predict Predict team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants