Skip to content

fix: remove whole redux state pass through for bridge selectors#33529

Merged
GeorgeGkas merged 1 commit into
mainfrom
swaps-4674-selectors
Jul 20, 2026
Merged

fix: remove whole redux state pass through for bridge selectors#33529
GeorgeGkas merged 1 commit into
mainfrom
swaps-4674-selectors

Conversation

@infiniteflower

@infiniteflower infiniteflower commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Description

This PR removes whole Redux-state passthrough inputs from three Bridge account selectors. The selectors now compose granular token and account inputs, preventing result recomputation on unrelated dispatches while preserving selected account-group lookup, destination scope matching, and the existing Set<AccountId> API.

It also adds EVM and non-EVM value coverage plus recomputation and reference-stability tests.

Changelog

CHANGELOG entry: null

Related issues

Fixes: #31269

Manual testing steps

N/A — this is an internal selector memoization change with no UI behavior change.

Automated verification: run yarn jest app/selectors/bridge.test.ts and confirm all 24 tests pass, including the unrelated-state recomputation and stable Set-reference cases.

Screenshots/Recordings

Before

N/A — no UI changes.

After

N/A — no UI changes.

Pre-merge author checklist

Performance checks (if applicable)

  • I've tested on Android
    • Ideally on a mid-range device; emulator is acceptable
  • I've tested with a power user scenario
    • Use these power-user SRPs to import wallets with many accounts and tokens
  • I've instrumented key operations with Sentry traces for production performance metrics

For performance guidelines and tooling, see the Performance Guide.

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
Destination account eligibility logic was rewritten (different data source and anyScopesMatch vs per-scope queries); behavior should match but account picking for bridge is user-facing if wrong.

Overview
Refactors three Bridge account selectors so they no longer depend on the entire RootState, which was forcing recomputation on every unrelated dispatch.

selectSourceWalletAddress and selectBatchSellSourceWalletAddress now compose selectSourceToken / selectBatchSellSourceTokens with selectSelectedInternalAccountByScope instead of calling scope lookup inside a (state) => state input. selectValidDestInternalAccountIds drops createDeepEqualSelector and selectInternalAccountsByScope in favor of selectInternalAccountsById plus anyScopesMatch for destination scope and EVM wildcard (eip155:0) filtering, while still returning a Set<AccountId>.

Tests add shared bridge selector mock state, EVM/Solana coverage, and assertions that unrelated bridge fields (e.g. sourceAmount) do not trigger recomputation or new Set references until the relevant token changes.

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

@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.

@github-actions github-actions Bot added the pr-not-ready-for-e2e Skip E2E and block merging. Remove this label once the PR is ready to run the E2E tests. label Jul 20, 2026
@metamask-ci metamask-ci Bot added the team-swaps-and-bridge Swaps and Bridge team label Jul 20, 2026
@metamask-ci

metamask-ci Bot commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

PR template — items to address before "Ready for review"

Warnings — informational, address before merging:

  • Pre-merge author checklist has unchecked items (e.g. "I've tested on Android"). Every box must be consciously checked — see docs/readme/ready-for-review.md.

See docs/readme/ready-for-review.md for the full Definition of Ready for Review.

@infiniteflower infiniteflower removed the pr-not-ready-for-e2e Skip E2E and block merging. Remove this label once the PR is ready to run the E2E tests. label Jul 20, 2026
@infiniteflower
infiniteflower marked this pull request as ready for review July 20, 2026 15:57
@github-actions

Copy link
Copy Markdown
Contributor

🔍 Smart E2E Test Selection

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

E2E Test Selection:
The changes are in app/selectors/bridge.ts which contains selectors used throughout the bridge/swap flow:

  1. selectSourceWalletAddress: Refactored to use selectSelectedInternalAccountByScope as a direct input selector instead of passing the full state. This selector is used in useBridgeQuoteRequest, useIsHardwareWalletForBridge, useBridgeConfirm, useSubmitBridgeTx, and useQuickBuyController.

  2. selectBatchSellSourceWalletAddress: Similar refactoring, used in useSubmitBatchSellTx and useBatchSellQuoteRequest.

  3. selectValidDestInternalAccountIds: Changed from createDeepEqualSelector to createSelector, and replaced selectInternalAccountsByScope with anyScopesMatch utility. Used in useDestinationAccounts.

These selectors are critical for determining wallet addresses in bridge/swap flows. The refactoring changes how memoization works and how account scopes are matched. While the test file adds comprehensive unit tests validating the new behavior, E2E tests should verify the actual swap/bridge flows still work correctly end-to-end.

SmokeSwap is selected because the changed selectors directly power the bridge/swap quote request, confirmation, and submission flows.
SmokeConfirmations is selected per the SmokeSwap tag description: "When selecting SmokeSwap, also select SmokeConfirmations (transaction confirmations are part of the flow)."

The changes are a refactoring (not new functionality), with unit tests added, so risk is medium rather than high.

Performance Test Selection:
The changes are selector refactoring in bridge.ts - improving memoization and account scope matching logic. While these selectors are used in swap flows, the changes are about correctness of selector inputs/memoization rather than performance-sensitive rendering or loading operations. No performance test tags are warranted for this type of refactoring.

View GitHub Actions results

@github-actions github-actions Bot added the risk:medium AI analysis: medium risk label Jul 20, 2026
@sonarqubecloud

Copy link
Copy Markdown

@GeorgeGkas
GeorgeGkas added this pull request to the merge queue Jul 20, 2026
Merged via the queue into main with commit a6f4d69 Jul 20, 2026
268 of 348 checks passed
@GeorgeGkas
GeorgeGkas deleted the swaps-4674-selectors branch July 20, 2026 17:28
@github-actions github-actions Bot locked and limited conversation to collaborators Jul 20, 2026
@metamask-ci metamask-ci Bot added the release-8.5.0 Issue or pull request that will be included in release 8.5.0 label Jul 20, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

release-8.5.0 Issue or pull request that will be included in release 8.5.0 risk:medium AI analysis: medium risk size-M team-swaps-and-bridge Swaps and Bridge team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Remove whole-state passthrough input in bridge wallet-address selectors

2 participants