Skip to content

feat: add hw context, state manager and event handlers#26262

Merged
mathieuartu merged 39 commits into
mainfrom
feat/hw-overhaul-3
Feb 24, 2026
Merged

feat: add hw context, state manager and event handlers#26262
mathieuartu merged 39 commits into
mainfrom
feat/hw-overhaul-3

Conversation

@mathieuartu

@mathieuartu mathieuartu commented Feb 19, 2026

Copy link
Copy Markdown
Contributor

Description

Part 3 of the hardware wallet connection & error management overhaul. This does not introduce user facing changes.
Cursor summary mentions the PR being medium risk, but nothing is wired yet, so this is largely low risk.

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

Low Risk
Mostly additive, internal hooks/context plus unit tests; no wiring into user flows yet, with limited risk aside from future integration correctness of the new state transitions.

Overview
Adds new hardware-wallet scaffolding: a HardwareWalletContext (with useHardwareWallet) to expose connection state, device selection, and HW actions via a single provider.

Introduces useHardwareWalletStateManager to own HW connection state, device id, derived walletType from the selected account, and mutable refs (adapter/isConnecting/abort), plus a resetState helper.

Adds useDeviceEventHandlers to translate DeviceEvent payloads into connection state transitions and normalized error states (including app-not-open, device-locked, connection-failed, and timeouts), and extends HW types with DeviceSelectionState. Comprehensive unit tests cover these new hooks and context behavior.

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

Comment thread app/core/HardwareWallet/HardwareWalletEventHandlers.tsx
Comment thread app/core/HardwareWallet/HardwareWalletEventHandlers.test.tsx Outdated
Comment thread app/core/HardwareWallet/HardwareWalletEventHandlers.tsx
Comment thread app/core/HardwareWallet/HardwareWalletEventHandlers.test.tsx Outdated
Comment thread app/core/HardwareWallet/HardwareWalletEventHandlers.tsx Outdated
Comment thread app/core/HardwareWallet/HardwareWalletEventHandlers.tsx
Comment thread app/core/HardwareWallet/HardwareWalletEventHandlers.tsx
Comment thread app/core/HardwareWallet/contexts/HardwareWalletContext.test.tsx Outdated
Comment thread app/core/HardwareWallet/HardwareWalletEventHandlers.test.tsx Outdated
Comment thread app/core/HardwareWallet/HardwareWalletEventHandlers.tsx
Comment thread app/core/HardwareWallet/HardwareWalletEventHandlers.tsx Outdated
Comment thread app/core/HardwareWallet/HardwareWalletStateManager.test.tsx Outdated
Comment thread app/core/HardwareWallet/HardwareWalletEventHandlers.tsx
Comment thread app/core/HardwareWallet/HardwareWalletStateManager.tsx
Comment thread app/core/HardwareWallet/HardwareWalletStateManager.tsx
Comment thread app/core/HardwareWallet/HardwareWalletEventHandlers.tsx

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

Comment thread app/core/HardwareWallet/contexts/index.ts
@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: 80%
click to see 🤖 AI reasoning details

E2E Test Selection:
This PR introduces new foundational infrastructure for hardware wallet state management in app/core/HardwareWallet/:

  1. New files added:

    • HardwareWalletEventHandlers.tsx: Hook for handling device events (Connected, Disconnected, AppOpened, DeviceLocked, etc.)
    • HardwareWalletStateManager.tsx: Hook for managing hardware wallet state (connection status, device ID, wallet type detection)
    • contexts/HardwareWalletContext.tsx: React context for hardware wallet functionality
    • contexts/index.ts: Export file
    • Comprehensive unit tests for all new hooks
  2. Modified file:

    • types.ts: Added DeviceSelectionState interface for device discovery

Risk Assessment: Medium

  • These are new files that aren't yet integrated into existing UI components (the useHardwareWallet hook is only imported by its test file and index.ts)
  • The changes are in the critical app/core/ path
  • The types.ts modification adds a new interface without modifying existing ones, so it's additive

Tag Selection Rationale:

  • SmokeAccounts is selected because it covers QR-based hardware wallet account flows. The test fixtures include withImportedHdKeyringAndTwoDefaultAccountsOneImportedHdAccountOneQrAccountOneSimpleKeyPairAccount which tests QR account functionality.
  • While the new hooks aren't directly used in the app yet, running SmokeAccounts ensures the hardware wallet infrastructure and account management flows remain functional.
  • Other tags are not needed as the changes don't affect confirmations, network management, trading, identity sync, or other features.

Performance Test Selection:
These changes introduce new React hooks and context for hardware wallet state management. The hooks use standard React patterns (useState, useCallback, useMemo, useRef) and don't introduce any heavy computations, list rendering, or data loading that would impact app performance. The changes are infrastructure/foundation code that isn't yet integrated into the UI, so there's no performance impact to measure.

View GitHub Actions results

@sonarqubecloud

Copy link
Copy Markdown

@mathieuartu mathieuartu added this pull request to the merge queue Feb 24, 2026
Merged via the queue into main with commit cbdc306 Feb 24, 2026
93 of 94 checks passed
@mathieuartu mathieuartu deleted the feat/hw-overhaul-3 branch February 24, 2026 08:14
@github-actions github-actions Bot locked and limited conversation to collaborators Feb 24, 2026
@metamaskbot metamaskbot added the release-7.68.0 Issue or pull request that will be included in release 7.68.0 label Feb 24, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

release-7.68.0 Issue or pull request that will be included in release 7.68.0 size-XL team-accounts-framework Accounts team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants