Skip to content

feat(hw): add executeHardwareWalletOperation utility#29085

Merged
montelaidev merged 8 commits into
mainfrom
feat/mul-1507-split-3-hw-operation
Apr 24, 2026
Merged

feat(hw): add executeHardwareWalletOperation utility#29085
montelaidev merged 8 commits into
mainfrom
feat/mul-1507-split-3-hw-operation

Conversation

@montelaidev

@montelaidev montelaidev commented Apr 21, 2026

Copy link
Copy Markdown
Contributor

Description

Add shared utility that runs hardware wallet operations behind the standard readiness + awaiting-confirmation flow. Includes foundation helpers (getDeviceIdForAddress, normalizeReplacementGasFeeParams) as prerequisites.

Changelog

CHANGELOG entry: null

Related issues

Related to: https://consensyssoftware.atlassian.net/browse/MUL-1741

Manual testing steps

This can only be tested via #29087

Screenshots/Recordings

Not applicable

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
Touches the hardware wallet provider’s wallet-type resolution and introduces a new shared signing wrapper; mistakes could lead to incorrect adapter selection or confirmation/error UI behavior during signing.

Overview
Adds a shared executeHardwareWalletOperation helper to standardize hardware-wallet operations: it resolves device id from address, gates on ensureDeviceReady, shows/hides the awaiting-confirmation UI, and centralizes rejection + error handling (including user-cancel suppression), with unit coverage.

Updates HardwareWalletProvider/context to support a new setPendingOperationAddress hook and to auto-derive the effective wallet type from the in-flight operation address (via getHardwareWalletTypeForAddress) when no explicit targetWalletType is set. Also tightens the setTargetWalletType context type and updates affected tests/mocks.

Separately introduces a ReplacementGasFeeValues type alias and reuses it in replacement gas normalization/repricing helpers (no functional behavior change).

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

Add shared utility that runs hardware wallet operations behind the
standard readiness + awaiting-confirmation flow. Includes foundation
helpers (getDeviceIdForAddress, normalizeReplacementGasFeeParams) as
prerequisites.
@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.

@metamaskbotv2 metamaskbotv2 Bot added the team-accounts-framework Accounts team label Apr 21, 2026
@github-actions github-actions Bot added size-M risk-medium Moderate testing recommended · Possible bug introduction risk labels Apr 21, 2026
Comment thread app/core/HardwareWallet/executeHardwareWalletOperation.test.ts Outdated
@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 Apr 21, 2026
Comment thread app/util/confirmation/gas.ts Outdated
Comment thread app/core/HardwareWallet/executeHardwareWalletOperation.ts Outdated

@gantunesr gantunesr left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a few minor comments

…ress

The provider now auto-derives the wallet type from the pending operation
address, so callers only need to supply the address — not the wallet type.
This removes the need for executeHardwareWalletOperation to compute and
forward the wallet type explicitly.
@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 Apr 22, 2026
…ationAddress

LedgerSelectAccount uses setTargetWalletType for the Add Hardware Wallet
flow, so it must remain in the context interface unchanged.
@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 Apr 22, 2026
@github-actions github-actions Bot added the risk:medium AI analysis: medium risk label Apr 22, 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.

Reviewed by Cursor Bugbot for commit b608509. Configure here.

Comment thread app/core/HardwareWallet/executeHardwareWalletOperation.ts Outdated
@github-actions github-actions Bot added risk:high AI analysis: high risk and removed risk:medium AI analysis: medium risk labels Apr 22, 2026
Comment thread app/core/HardwareWallet/executeHardwareWalletOperation.ts
@github-actions github-actions Bot added size-L and removed size-M risk:high AI analysis: high risk labels Apr 22, 2026
@github-actions github-actions Bot added the risk:medium AI analysis: medium risk label Apr 22, 2026
@github-actions github-actions Bot added size-M and removed size-L labels Apr 23, 2026
@github-actions

Copy link
Copy Markdown
Contributor

AI PR Analysis

🚫 Merge safe: false | 🟠 Risk: high

Merge decision: AI analysis did not complete — manual review required before merging.

AI analysis did not complete. Manual review recommended.

View run

@github-actions github-actions Bot added risk:high AI analysis: high risk and removed risk:medium AI analysis: medium risk labels Apr 23, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🔍 Smart E2E Test Selection

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

E2E Test Selection:
The changes are focused on the Hardware Wallet subsystem (app/core/HardwareWallet/):

  1. New executeHardwareWalletOperation.ts: A new utility function that orchestrates hardware wallet signing operations. It handles device readiness checks, shows/hides confirmation UI, and manages error flows. Currently exported but not yet consumed by any .tsx component files (only test files reference it directly), so it's a preparatory addition.

  2. HardwareWalletProvider.tsx: Added pendingOperationAddress state and setPendingOperationAddress to the context. This allows the provider to auto-derive wallet type from an address during signing, fixing a potential issue where wallet type wasn't correctly determined during signing flows.

  3. HardwareWalletContext.tsx: Added setPendingOperationAddress to the context interface; minor type tightening on setTargetWalletType.

  4. gas.ts: Pure type refactor - extracted ReplacementGasFeeValues type alias. No behavioral change.

  5. Test files: Updated mocks to include the new setPendingOperationAddress.

Why SmokeAccounts: This tag covers QR-based hardware wallet account adding flows, which use the HardwareWalletProvider and useHardwareWallet hook. The context changes (new setPendingOperationAddress) could affect the hardware wallet connection and account selection flows tested here.

Why SmokeConfirmations: The LedgerConfirmationModal and LedgerTransactionModal both use useHardwareWallet hook. The QR hardware context (used in confirmation components like footer, info-root, qr-info) also uses useHardwareWallet. The gas.ts changes (type refactor) are used in confirmation gas fee flows. These are the primary areas where hardware wallet signing is exercised in E2E tests.

The changes are additive (new function, new context property) with no breaking behavioral changes to existing flows, keeping risk at medium level.

Performance Test Selection:
The changes are focused on hardware wallet operation orchestration logic and a minor type refactor in gas utilities. These are not performance-sensitive areas - they involve user-interactive flows (hardware device connection, confirmation UI) that are inherently latency-bound by external hardware. No UI rendering, list components, data loading, or app startup code was modified.

View GitHub Actions results

@github-actions

Copy link
Copy Markdown
Contributor

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

@sonarqubecloud

Copy link
Copy Markdown

@montelaidev montelaidev added this pull request to the merge queue Apr 24, 2026
Merged via the queue into main with commit cc1992b Apr 24, 2026
101 of 102 checks passed
@montelaidev montelaidev deleted the feat/mul-1507-split-3-hw-operation branch April 24, 2026 01:42
@github-actions github-actions Bot locked and limited conversation to collaborators Apr 24, 2026
@metamaskbotv2 metamaskbotv2 Bot added the release-7.76.0 Issue or pull request that will be included in release 7.76.0 label Apr 24, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

release-7.76.0 Issue or pull request that will be included in release 7.76.0 risk:high AI analysis: high risk risk-medium Moderate testing recommended · Possible bug introduction risk size-M team-accounts-framework Accounts team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants