Skip to content

fix(predict): prevent token selector from using stale approvals from other flows cp-7.73.0#28685

Merged
caieu merged 6 commits intomainfrom
predict/enable-selector-when-ready
Apr 10, 2026
Merged

fix(predict): prevent token selector from using stale approvals from other flows cp-7.73.0#28685
caieu merged 6 commits intomainfrom
predict/enable-selector-when-ready

Conversation

@caieu
Copy link
Copy Markdown
Contributor

@caieu caieu commented Apr 10, 2026

Description

A user reported that the "Pay with" token selector on PredictBuyWithAnyTokenwasn't allowing to select a different token. A transaction is needed to that work and the current logic could pick up pending approvals from unrelated flows (bridge, swap, send, etc.), allowing them to select tokens from the wrong transaction context.

Root cause: initPayWithAnyToken() calls addTransactionBatch() directly without first rejecting existing pending approvals — unlike the standalone predictDeposit flow which goes through useConfirmNavigation and rejects all unapproved transactions before creating its own. When stale approvals existed, useApprovalRequest() returned the first (wrong) approval, and PredictPayWithRow enabled token selection based on a generic transactionMeta truthiness check.

Fix (defense-in-depth):

  1. usePredictBuyActions — added rejectPendingTransactions() in the transitionEnd handler before initPayWithAnyToken(), mirroring the cleanup pattern from useConfirmNavigation.
  2. PredictPayWithRow — replaced the generic transactionMeta truthiness check with hasTransactionType(transactionMeta, [TransactionType.predictDepositAndOrder]), so the selector only enables for the correct transaction type.

This branch also includes prior commits that handle no-quotes blocking alerts in the buy flow and disable the pay-with selector until transaction metadata is ready.

Changelog

CHANGELOG entry: null

Related issues

Fixes:

Manual testing steps

Feature: Predict buy-with-any-token token selector isolation

  Scenario: token selector stays disabled when a non-predict approval is pending
    Given user has an unconfirmed swap or bridge transaction pending
    And user navigates to a Predict market buy screen

    When the buy screen finishes loading
    Then the "Pay with" row does not show an arrow icon
    And tapping the "Pay with" row does not open the token selection modal

  Scenario: token selector enables after deposit-and-order batch is created
    Given user has no pending transactions
    And user navigates to a Predict market buy screen

    When the buy screen finishes loading and initPayWithAnyToken completes
    Then the "Pay with" row shows the arrow icon
    And tapping the "Pay with" row opens the token selection modal

  Scenario: stale approvals are rejected on buy screen entry
    Given user has an unconfirmed transaction from another flow
    And user navigates to a Predict market buy screen

    When the screen transition completes
    Then the stale unconfirmed transaction is rejected
    And a new deposit-and-order batch is created as the only pending approval

Screenshots/Recordings

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 transaction/approval handling in the Predict buy flow by programmatically rejecting unapproved transactions and tightening when the pay-with selector is enabled; regressions could affect in-flight approvals or block token selection.

Overview
Prevents the PredictBuyWithAnyToken pay-with token selector from latching onto stale approvals from other flows.

On screen entry, usePredictBuyActions now rejects all unapproved transactions before calling initPayWithAnyToken, and PredictPayWithRow only enables navigation/UI affordances when the current transactionMeta is a TransactionType.predictDepositAndOrder (otherwise it disables press, hides the arrow, and removes the muted background). The buy flow also propagates blocking pay alerts (insufficient balance / no quotes) via usePredictBuyInfo into usePredictBuyConditions and usePredictBuyError to disable placing bets and surface the correct blocking message, with updated tests.

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

caieu added 3 commits April 10, 2026 12:56
The component change guards the selector behind transactionMeta existence, preventing users from opening the pay modal before the transaction is initialized — which would show incomplete state (missing Predict balance). The styling condition was also aligned to use canEdit consistently.
Adds useNoPayTokenQuotesAlert to the buy conditions and error hooks, matching the Perps pay-with-any-token error handling. When a relay quote fails or returns empty, users now see a blocking error instead of an indefinite loading state.
…other flows

Reject pending unapproved transactions before initializing the deposit-and-order
batch, and guard the pay-with row so it only enables for predictDepositAndOrder
transactions — preventing the token selector from picking up unrelated approvals.
@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 Apr 10, 2026
@caieu caieu changed the title fix(predict): prevent token selector from using stale approvals from other flows fix(predict): prevent token selector from using stale approvals from other flows cp-7.73.0 Apr 10, 2026
@caieu caieu marked this pull request as ready for review April 10, 2026 21:33
@caieu caieu requested a review from a team as a code owner April 10, 2026 21:33
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 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 8b7f9c5. Configure here.

@github-actions github-actions bot added the risk-medium Moderate testing recommended · Possible bug introduction risk label Apr 10, 2026
@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: 90%
click to see 🤖 AI reasoning details

E2E Test Selection:
All 11 changed files are within the Predict (Polymarket) feature area, specifically the PredictBuyWithAnyToken flow. Key changes include:

  1. usePredictBuyActions.ts: Added rejectPendingTransactions() that clears unapproved transactions via TransactionController and ApprovalController before initializing the "pay with any token" flow. This is a functional fix to prevent stale approvals from interfering with new deposit-and-order batches.

  2. usePredictBuyInfo.ts: Expanded blocking alert detection to include both useInsufficientPayTokenBalanceAlert and a new useNoPayTokenQuotesAlert, unifying them into blockingPayAlerts. Returns blockingPayAlertMessage and hasBlockingPayAlerts to downstream hooks.

  3. usePredictBuyConditions.ts: Refactored to accept hasBlockingPayAlerts as a prop, simplified isPayFeesLoading logic (removed dependency on quotes length), and removed direct alert hook dependency.

  4. usePredictBuyError.ts: Refactored to accept blockingPayAlertMessage as a prop instead of computing it internally.

  5. PredictPayWithRow.tsx: Added hasTransactionType(transactionMeta, [TransactionType.predictDepositAndOrder]) check so the "Pay With" row is only editable when the transaction is of the correct type. Fixed background styling to use !canEdit instead of disabled.

Tag selection rationale:

  • SmokePredictions: Directly covers the Polymarket prediction market feature, including opening positions which uses the modified buy flow.
  • SmokeWalletPlatform: Per tag description, Predictions is a section inside the Trending tab; changes to Predictions views affect Trending.
  • SmokeConfirmations: Per SmokePredictions tag description, opening/closing positions are on-chain transactions. Additionally, usePredictBuyActions directly interacts with TransactionController and ApprovalController (Engine controllers), which are part of the confirmation infrastructure.

No other tags are needed as changes are fully contained within the Predict feature and don't touch shared navigation, account management, network, swap, or other unrelated flows.

Performance Test Selection:
The changes are functional refactoring of hooks within the Predict buy flow - consolidating alert handling, adding transaction rejection cleanup, and fixing editability logic. These are logic/correctness fixes, not UI rendering or data loading performance changes. No significant performance impact is expected, so no performance tests are needed.

View GitHub Actions results

@sonarqubecloud
Copy link
Copy Markdown

@github-actions
Copy link
Copy Markdown
Contributor

E2E Fixture Validation — Schema is up to date
17 value mismatches detected (expected — fixture represents an existing user).
View details

@caieu caieu enabled auto-merge April 10, 2026 22:48
@caieu caieu added this pull request to the merge queue Apr 10, 2026
Merged via the queue into main with commit 43b030d Apr 10, 2026
103 checks passed
@caieu caieu deleted the predict/enable-selector-when-ready branch April 10, 2026 23:02
@github-actions github-actions bot locked and limited conversation to collaborators Apr 10, 2026
@metamaskbot metamaskbot added the release-7.74.0 Issue or pull request that will be included in release 7.74.0 label Apr 10, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

release-7.74.0 Issue or pull request that will be included in release 7.74.0 risk-medium Moderate testing recommended · Possible bug introduction risk size-M team-predict Predict team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants