Skip to content

perf(earn): use memoized selectPendingApprovalIds instead of isEqual …#33181

Merged
shane-t merged 5 commits into
mainfrom
fix/musd-conversion-pending-approval-ids-selector
Jul 16, 2026
Merged

perf(earn): use memoized selectPendingApprovalIds instead of isEqual …#33181
shane-t merged 5 commits into
mainfrom
fix/musd-conversion-pending-approval-ids-selector

Conversation

@shane-t

@shane-t shane-t commented Jul 13, 2026

Copy link
Copy Markdown
Member

Replaces the deep-equality-guarded selectPendingApprovals subscription in useMusdConversion with a new createSelector-based selectPendingApprovalIds projection selector. This avoids running lodash isEqual over the entire pending approvals map on every Redux dispatch when the hook only consumes the set of approval IDs.

Description

useMusdConversion subscribed to selectPendingApprovals (the raw pending-approvals map) with a lodash.isEqual comparator, then derived Object.keys(pendingApprovals ?? {}) via useMemo. Since the hook only ever consumes the approval IDs, the deep comparison of the entire approvals map on every Redux dispatch was unnecessary overhead — a band-aid for a missing memoized projection selector.

Changelog

CHANGELOG entry: null

Related issues

Fixes: #31337

Manual testing steps

Feature: my feature name

  Scenario: user [verb for user action]
    Given [describe expected initial app state]

    When user [verb for user action]
    Then [describe expected outcome]

Screenshots/Recordings

Before

N/A

After

N/A

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

Low Risk
Behavior-preserving selector refactor in a feature-flagged Earn hook with no auth, payment, or shared controller API changes.

Overview
useMusdConversion no longer subscribes to the full pending-approvals map with lodash.isEqual. It now uses a local createSelector projection, selectPendingApprovalIds, that derives Object.keys from selectPendingApprovals so useSelector can use default reference equality and skip deep compares on every Redux dispatch when only approval IDs matter.

Unit tests cover key extraction, empty state, and stable vs. new array references when the underlying map is unchanged or updated. The selector stays in the hook file rather than approvalController selectors to keep the change scoped to Earn/mUSD.

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

shane-t added 2 commits July 7, 2026 16:07
…in useMusdConversion

Replaces the deep-equality-guarded selectPendingApprovals subscription in
useMusdConversion with a local createSelector-based selectPendingApprovalIds
projection selector. This avoids running lodash isEqual over the entire
pending approvals map on every Redux dispatch when the hook only consumes
the set of approval IDs.

Kept the new selector local to useMusdConversion.ts (rather than adding it
to approvalController.ts) to minimize surface area, since this feature is
currently flagged off and approvalController.ts is owned by another team.

Fixes #31337
…usd-conversion-pending-approval-ids-selector
@metamask-ci metamask-ci Bot added the team-mobile-ux Mobile UX team label Jul 13, 2026
@shane-t shane-t added team-earn and removed team-mobile-ux Mobile UX team labels Jul 13, 2026
@metamask-ci

metamask-ci Bot commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

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

Warnings — informational, address before merging:

  • Manual testing steps still contain template content (the Gherkin example title or a [...] placeholder). Replace with real steps, or write N/A — <reason>.
  • Pre-merge author checklist has unchecked items (e.g. "I've followed MetaMask Contributor Docs and MetaMask Mobile Coding Standards."). 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.

@shane-t shane-t marked this pull request as ready for review July 13, 2026 08:45
@shane-t shane-t requested review from a team as code owners July 13, 2026 08:45
@shane-t shane-t force-pushed the fix/musd-conversion-pending-approval-ids-selector branch from 119e918 to 40dd16f Compare July 13, 2026 08:47
@github-actions github-actions Bot added the risk:low AI analysis: low risk label Jul 13, 2026
Jwhiles
Jwhiles previously approved these changes Jul 13, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🔍 Smart E2E Test Selection

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

E2E Test Selection:
The PR contains two files, both within the Earn/hooks directory:

  1. useMusdConversion.ts: A pure internal optimization refactor. The change replaces useSelector(selectPendingApprovals, isEqual) + useMemo(() => Object.keys(...)) with a createSelector-based memoized selector selectPendingApprovalIds. This is functionally equivalent — the same data (pending approval IDs) is derived, just using reselect's structural memoization instead of lodash deep equality + useMemo. The code comment explicitly states "the mUSD conversion feature is flagged off," meaning this code path is not active in production. No UI changes, no API changes, no behavioral changes.

  2. useMusdConversion.test.ts: Adds unit tests for the new selectPendingApprovalIds selector — tests reference stability and correctness of the selector. No E2E test infrastructure changes.

Since:

  • The mUSD conversion feature is feature-flagged off
  • The change is a pure selector memoization optimization with no functional difference
  • No user-facing flows are affected
  • No shared components (navigation, modals, confirmations) are touched
  • No E2E smoke tests cover this specific internal hook

No E2E smoke tags are warranted. No performance tags are warranted either — this is a micro-optimization to selector memoization that would not measurably affect any of the performance test scenarios.

Performance Test Selection:
The change is a selector memoization optimization (reselect createSelector replacing lodash isEqual + useMemo) in a feature-flagged-off mUSD conversion hook. While it's a performance improvement, it's scoped to a disabled feature and would not measurably affect any of the available performance test scenarios (AccountList, Onboarding, Login, Swaps, Launch, AssetLoading, Predict, Perps).

View GitHub Actions results

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 84.39%. Comparing base (c4cb337) to head (f044975).
⚠️ Report is 16 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #33181      +/-   ##
==========================================
+ Coverage   84.37%   84.39%   +0.01%     
==========================================
  Files        6127     6132       +5     
  Lines      163530   163730     +200     
  Branches    39887    39925      +38     
==========================================
+ Hits       137974   138175     +201     
+ Misses      16050    16044       -6     
- Partials     9506     9511       +5     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@sonarqubecloud

Copy link
Copy Markdown

@shane-t shane-t added this pull request to the merge queue Jul 16, 2026
Merged via the queue into main with commit 8e5f3a3 Jul 16, 2026
129 checks passed
@shane-t shane-t deleted the fix/musd-conversion-pending-approval-ids-selector branch July 16, 2026 16:03
@github-actions github-actions Bot locked and limited conversation to collaborators Jul 16, 2026
@metamask-ci metamask-ci Bot added the release-8.4.0 Issue or pull request that will be included in release 8.4.0 label Jul 16, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

release-8.4.0 Issue or pull request that will be included in release 8.4.0 risk:low AI analysis: low risk size-S team-earn

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Remove isEqual on selectPendingApprovals in useMusdConversion

3 participants