Skip to content

refactor: hw provider and hooks for cleaner architecture and readability#26676

Merged
mathieuartu merged 4 commits into
mainfrom
feat/hw-overhaul-4.5
Feb 27, 2026
Merged

refactor: hw provider and hooks for cleaner architecture and readability#26676
mathieuartu merged 4 commits into
mainfrom
feat/hw-overhaul-4.5

Conversation

@mathieuartu

@mathieuartu mathieuartu commented Feb 27, 2026

Copy link
Copy Markdown
Contributor

Description

Part "4.5" of the hardware wallet connection & error management overhaul. This does not introduce user facing changes.

Will close:

Final implementation will look like this (Figma designs):
image

Reference feature branch: #25519

Changelog

CHANGELOG entry: null

Related issues

Fixes:

Manual testing steps

no manual testing steps

Screenshots/Recordings

Before

After

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
Refactors core hardware-wallet connection flow and transport monitoring into new hooks, which could subtly change state transitions (scanning/connecting/error/ready) or cleanup behavior. No new security surface, but regressions could impact device connectivity and error handling.

Overview
Refactors HardwareWalletProvider by extracting adapter lifecycle, transport monitoring, device discovery, and connection/retry/close logic into new hooks (useAdapterLifecycle, useTransportMonitoring, useDeviceDiscovery, useDeviceConnectionFlow) and wiring the provider to these hook APIs.

Simplifies the connecting UI contract by removing adapter-provided connectionTips: getConnectionTips() is removed from HardwareWalletAdapter (and Ledger/NonHardware adapters), HardwareWalletBottomSheet no longer accepts connectionTips, and ConnectingContent now derives tips via getConnectionTipsForWalletType() in helpers.ts. Also makes bottom-sheet onClose required and updates tests accordingly.

Written by Cursor Bugbot for commit b84edf3. This will update automatically on new commits. Configure here.

@mathieuartu mathieuartu self-assigned this Feb 27, 2026
@mathieuartu mathieuartu added team-accounts-framework Accounts team skip-e2e skip E2E test jobs labels Feb 27, 2026
@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.

Comment thread app/core/HardwareWallet/hooks/useAdapterLifecycle.ts Outdated
Comment thread app/core/HardwareWallet/hooks/useAdapterLifecycle.ts Outdated
Comment thread app/core/HardwareWallet/hooks/useTransportMonitoring.ts Outdated
Comment thread app/core/HardwareWallet/hooks/useTransportMonitoring.ts Outdated
Comment thread app/core/HardwareWallet/hooks/useTransportMonitoring.ts Outdated
@github-actions

Copy link
Copy Markdown
Contributor

🔍 Smart E2E Test Selection

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

E2E Test Selection:
This PR is a refactoring of the Hardware Wallet Provider module in app/core/HardwareWallet/. The changes include:

  1. Code reorganization: Moving hooks from the root directory into a dedicated hooks/ subdirectory (useHardwareWalletStateManager, useDeviceEventHandlers)

  2. New hooks extracted from HardwareWalletProvider.tsx: useAdapterLifecycle, useTransportMonitoring, useDeviceDiscovery, useDeviceConnectionFlow - these break down the large provider into smaller, focused hooks

  3. API simplification: Removed getConnectionTips() method from adapters and moved the logic to a helper function getConnectionTipsForWalletType() in helpers.ts

  4. Component updates: Removed connectionTips prop from HardwareWalletBottomSheet and ConnectingContent components

The public API (HardwareWalletProvider, useHardwareWallet, isUserCancellation) remains unchanged. This is purely an internal refactoring with no functional changes to hardware wallet behavior.

Selected SmokeAccounts because:

  • It's the tag most related to hardware wallet functionality (mentions "adding QR-based hardware wallet accounts")
  • The HardwareWallet module is used by LedgerConnect and SelectHardware views which are part of account management flows
  • While there don't appear to be dedicated hardware wallet E2E tests, running SmokeAccounts provides coverage for account-related flows that might indirectly use this module

The risk is medium because:

  • Changes are in critical app/core/ path
  • Multiple files changed but all are internal refactoring
  • Unit tests have been updated to reflect the changes
  • No changes to external API or user-facing behavior

Performance Test Selection:
This PR is a pure code refactoring of the Hardware Wallet Provider module. The changes reorganize hooks into a dedicated directory and extract logic into smaller focused hooks, but do not change any rendering logic, data loading patterns, or state management in ways that would impact performance. No UI components are modified in ways that affect rendering performance, and no new data fetching or processing logic is introduced. The changes are internal architectural improvements that maintain the same functional behavior.

View GitHub Actions results

@mathieuartu mathieuartu added this pull request to the merge queue Feb 27, 2026
Merged via the queue into main with commit 961c01b Feb 27, 2026
62 of 63 checks passed
@mathieuartu mathieuartu deleted the feat/hw-overhaul-4.5 branch February 27, 2026 20:43
@github-actions github-actions Bot locked and limited conversation to collaborators Feb 27, 2026
@metamaskbot metamaskbot added the release-7.69.0 Issue or pull request that will be included in release 7.69.0 label Feb 27, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

release-7.69.0 Issue or pull request that will be included in release 7.69.0 size-XL skip-e2e skip E2E test jobs team-accounts-framework Accounts team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants