Skip to content

feat: Default predict withdraw token from last used selection or from feature flags#27532

Merged
dan437 merged 5 commits into
mainfrom
post-quote-default-token
Mar 18, 2026
Merged

feat: Default predict withdraw token from last used selection or from feature flags#27532
dan437 merged 5 commits into
mainfrom
post-quote-default-token

Conversation

@dan437

@dan437 dan437 commented Mar 17, 2026

Copy link
Copy Markdown
Contributor

Description

This PR updates Predict withdraw token auto-selection to prefer the user’s most recent withdraw destination token before falling back to the remote preferred token configuration.

Changelog

CHANGELOG entry: Updated Predict withdraw to default to the user’s last used destination token before falling back to the remote preferred token.

Related issues

Fixes: MetaMask-planning#7081

Manual testing steps

Feature: Predict withdraw default destination token

  Scenario: user sees the last used withdraw token preselected
    Given the user has previously completed a Predict withdraw to BNB
    And the user has a valid preferred withdraw token configured in remote feature flags
    When the user opens the Predict withdraw flow again
    Then the withdraw screen preselects BNB instead of the remote preferred token

  Scenario: user falls back to the preferred token from feature flags
    Given the user has not completed any previous Predict withdraw with metamaskPay destination metadata
    And the remote feature flag `confirmations_pay_tokens.preferredTokens.overrides.predictWithdraw` is set to mUSD on Ethereum
    When the user opens the Predict withdraw flow
    Then the withdraw screen preselects mUSD on Ethereum

Screenshots/Recordings

Before

N/A

After

Pre-selected token from the last withdraw:
image

Pre-selected token from feature flags:
image

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.

Tests I ran:
- `npx jest app/selectors/transactionController.test.ts --no-coverage`
- `npx jest app/components/Views/confirmations/hooks/pay/useAutomaticTransactionPayToken.test.ts --no-coverage`

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> **Medium Risk**
> Changes automatic pay-token selection for withdraw flows by introducing transaction-history based defaults and new filtering, which could affect which token is preselected for users in post-quote transactions.
> 
> **Overview**
> Updates `useAutomaticTransactionPayToken` to treat post-quote/withdraw transactions differently: it now uses `getPostQuoteTransactionType`, applies a withdraw-specific token filter (`useWithdrawTokenFilter`), and prefers the **last used withdraw destination token** (from transaction history) before falling back to feature-flag preferred tokens. It also avoids repeatedly auto-setting the token by keying the update guard to `transactionId` and skipping when `payToken` is already set.
> 
> Adds `selectLastWithdrawTokenByType` to `transactionController` selectors to extract the most recent `metamaskPay` `tokenAddress`/`chainId` for a given (including nested) transaction type, and extends unit tests to cover nested `predictWithdraw` history selection and selector behavior.
> 
> <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit f90f5c36f551b03fe076abc9fb6d5bb62dc02e8d. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->

@dan437 dan437 requested a review from a team as a code owner March 17, 2026 12:56
@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-confirmations Push issues to confirmations team label Mar 17, 2026
@github-actions github-actions Bot added size-M risk-high Extensive testing required · High bug introduction risk labels Mar 17, 2026
Comment thread app/selectors/transactionController.ts
jpuri
jpuri previously approved these changes Mar 17, 2026
@dan437 dan437 force-pushed the post-quote-default-token branch from f31a227 to c56e198 Compare March 18, 2026 10:20
@github-actions github-actions Bot added risk-high Extensive testing required · High bug introduction risk and removed risk-high Extensive testing required · High bug introduction risk labels Mar 18, 2026
dan437 added 4 commits March 18, 2026 13:30
Signed-off-by: dan437 <80175477+dan437@users.noreply.github.com>
Signed-off-by: dan437 <80175477+dan437@users.noreply.github.com>
Signed-off-by: dan437 <80175477+dan437@users.noreply.github.com>
@dan437 dan437 force-pushed the post-quote-default-token branch from c56e198 to 0775e87 Compare March 18, 2026 12:31
@github-actions github-actions Bot added risk-medium Moderate testing recommended · Possible bug introduction risk and removed risk-high Extensive testing required · High bug introduction risk labels Mar 18, 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 1 potential issue.

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.

Comment thread app/selectors/transactionController.ts
Signed-off-by: dan437 <80175477+dan437@users.noreply.github.com>
@github-actions github-actions Bot added risk-medium Moderate testing recommended · Possible bug introduction risk and removed risk-medium Moderate testing recommended · Possible bug introduction risk labels Mar 18, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🔍 Smart E2E Test Selection

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

E2E Test Selection:
The changes are limited to transactionController selectors and the useAutomaticTransactionPayToken hook within the confirmations flow. This directly impacts how transaction data and automatic pay token selection logic are derived and consumed in the confirmation UI. Since TransactionController is part of the transaction domain (Phase 5 in Engine architecture) and tightly coupled with confirmation rendering, gas/payment token logic, and smart transaction flows (including EIP-7702 gas fee token payments), the most relevant E2E coverage is SmokeConfirmations.

No changes were made to Engine initialization order, messenger configuration, or other controllers (e.g., NetworkController, KeyringController). The modifications appear scoped to selector logic and confirmation pay token behavior, meaning the blast radius is limited to transaction confirmation flows rather than wallet-wide functionality.

SmokeConfirmations covers:

  • Native and ERC-20 transaction sending
  • Gas fee customization and display
  • Smart transaction flows and gas fee token payments
  • Signature flows and confirmation UI rendering

This provides sufficient coverage to validate selector changes and automatic pay token behavior without unnecessarily running unrelated suites (accounts, network management, trade, etc.).

Performance Test Selection:
The changes affect selector logic and a confirmation hook for automatic transaction pay token selection. There are no modifications to rendering-heavy components, large lists, app launch logic, account lists, swaps, predictions, or perps performance-critical paths. The changes are functional rather than structural or performance-sensitive, so no performance test suites are required.

View GitHub Actions results

@sonarqubecloud

Copy link
Copy Markdown

@github-actions

Copy link
Copy Markdown
Contributor

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

@dan437 dan437 enabled auto-merge March 18, 2026 14:20
@dan437 dan437 added this pull request to the merge queue Mar 18, 2026
Merged via the queue into main with commit 0d326cb Mar 18, 2026
244 of 246 checks passed
@dan437 dan437 deleted the post-quote-default-token branch March 18, 2026 14:47
@github-actions github-actions Bot locked and limited conversation to collaborators Mar 18, 2026
@metamaskbot metamaskbot added the release-7.71.0 Issue or pull request that will be included in release 7.71.0 label Mar 18, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

release-7.71.0 Issue or pull request that will be included in release 7.71.0 risk-medium Moderate testing recommended · Possible bug introduction risk size-M team-confirmations Push issues to confirmations team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants