Skip to content

fix: handle transient BLE errors during Ledger app switch and simplify HW retry logic#26798

Merged
mathieuartu merged 1 commit into
mainfrom
feat/hw-overhaul-4.5.1
Mar 2, 2026
Merged

fix: handle transient BLE errors during Ledger app switch and simplify HW retry logic#26798
mathieuartu merged 1 commit into
mainfrom
feat/hw-overhaul-4.5.1

Conversation

@mathieuartu

@mathieuartu mathieuartu commented Mar 2, 2026

Copy link
Copy Markdown
Contributor

Description

Part "4.5.1" of the hardware wallet connection & error management overhaul. This is a small follow up PR and 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
Changes core hardware-wallet connection/retry behavior (including BLE reconnection timing and which errors are retried), which could impact Ledger connection reliability and error recovery paths.

Overview
Improves Ledger BLE readiness checks by retrying ensureDeviceReady on a broader set of transient BLE errors (e.g., disconnects during app switch, pairing-related failures) and increasing the retry backoff delay.

Simplifies the hardware-wallet retry path by removing generic "retry last operation" tracking and standardizing retries around retryEnsureDeviceReady (wired through HardwareWalletProvider/HardwareWalletBottomSheet), while dropping the now-unused clearError handler from useDeviceEventHandlers.

Tightens adapter connection failure behavior/tests to ensure connect errors clear adapter connection state and propagate thrown values consistently.

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

@mathieuartu mathieuartu self-assigned this Mar 2, 2026
@mathieuartu mathieuartu added team-accounts-framework Accounts team skip-e2e skip E2E test jobs labels Mar 2, 2026
@github-actions

github-actions Bot commented Mar 2, 2026

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 size-M label Mar 2, 2026
@github-actions

github-actions Bot commented Mar 2, 2026

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:
The PR modifies the Hardware Wallet module in app/core/HardwareWallet/, which handles Ledger Bluetooth connections. Key changes include:

  1. LedgerBluetoothAdapter.ts: Expanded transient BLE error handling to include PairingFailed, PeerRemovedPairing, and BleError (not just disconnect errors), increased retry delay from 1s to 2s, and reset restart count at ensureDeviceReady start.

  2. useDeviceConnectionFlow.ts: Simplified retry logic by renaming retryLastOperation to retryEnsureDeviceReady and removing the lastOperationRef tracking - now only retries ensureDeviceReady with current deviceId.

  3. useDeviceEventHandlers.ts: Removed the clearError function entirely.

  4. HardwareWalletProvider.tsx & HardwareWalletBottomSheet.tsx: Updated to use renamed functions.

These are internal refactoring changes that improve Bluetooth connection reliability without changing user-facing behavior. The SmokeAccounts tag is selected because it covers "adding QR-based hardware wallet accounts" according to the tag description, and hardware wallet functionality is part of account management flows.

The changes are well-covered by unit tests (all updated in this PR), and the risk is medium because while the changes are internal refactoring, they affect critical hardware wallet connection flows that could impact users connecting Ledger devices. However, there are no dedicated E2E tests for Ledger connection flows in the test suite, so SmokeAccounts provides the closest coverage for hardware wallet account-related functionality.

Performance Test Selection:
These changes are internal refactoring of the Hardware Wallet Bluetooth connection flow. The changes involve error handling improvements and retry logic simplification, but do not affect UI rendering performance, data loading, or any of the critical user flows covered by performance tests (account list, onboarding, login, swaps, launch, asset loading, predict, perps). The increased retry delay (1s to 2s) is for error recovery scenarios, not normal operation performance.

View GitHub Actions results

@mathieuartu mathieuartu enabled auto-merge March 2, 2026 17:06
const CONNECTION_RESTART_LIMIT = 5;
const MAX_DISCONNECT_RETRIES = 3;
const RETRY_DELAY_MS = 1000;
const RETRY_DELAY_MS = 2000;

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.

why increase the timeout?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Just to be a bit on the safer side considering the randomness of BLE readiness times. I know this isn't a perfect solution (good catch), I might even revert it in the first implementation PR if I find it's stable enough.

@mathieuartu mathieuartu added this pull request to the merge queue Mar 2, 2026
Merged via the queue into main with commit 5a3caf1 Mar 2, 2026
95 of 129 checks passed
@mathieuartu mathieuartu deleted the feat/hw-overhaul-4.5.1 branch March 2, 2026 21:35
@github-actions github-actions Bot locked and limited conversation to collaborators Mar 2, 2026
@metamaskbot metamaskbot added the release-7.69.0 Issue or pull request that will be included in release 7.69.0 label Mar 2, 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-M 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