Commit 961c01b
authored
refactor: hw provider and hooks for cleaner architecture and readability (#26676)
<!--
Please submit this PR as a draft initially.
Do not mark it as "Ready for review" until the template has been
completely filled out, and PR status checks have passed at least once.
-->
## **Description**
Part "4.5" of the hardware wallet connection & error management
overhaul. This does not introduce user facing changes.
Will close:
- https://consensyssoftware.atlassian.net/browse/MUL-1495
Final implementation will look like this ([Figma
designs](https://www.figma.com/design/1F3yNWYLOVPFpTPeJugH20/SWAP?node-id=11110-19571&t=tPMZNNiwCgbDfegd-0)):
<img width="1404" height="631" alt="image"
src="https://github.com/user-attachments/assets/68850711-f53b-4060-8b47-6faceb67f82f"
/>
Reference feature branch:
#25519
## **Changelog**
<!--
If this PR is not End-User-Facing and should not show up in the
CHANGELOG, you can choose to either:
1. Write `CHANGELOG entry: null`
2. Label with `no-changelog`
If this PR is End-User-Facing, please write a short User-Facing
description in the past tense like:
`CHANGELOG entry: Added a new tab for users to see their NFTs`
`CHANGELOG entry: Fixed a bug that was causing some NFTs to flicker`
(This helps the Release Engineer do their job more quickly and
accurately)
-->
CHANGELOG entry: null
## **Related issues**
Fixes:
## **Manual testing steps**
no manual testing steps
## **Screenshots/Recordings**
<!-- If applicable, add screenshots and/or recordings to visualize the
before and after of your change. -->
### **Before**
<!-- [screenshots/recordings] -->
### **After**
<!-- [screenshots/recordings] -->
## **Pre-merge author checklist**
- [x] I've followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Mobile
Coding
Standards](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/CODING_GUIDELINES.md).
- [x] I've completed the PR template to the best of my ability
- [x] I've included tests if applicable
- [x] I've documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [x] I've applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.
## **Pre-merge reviewer checklist**
- [x] I've manually tested the PR (e.g. pull and build branch, run the
app, test code being changed).
- [x] 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.
<!-- CURSOR_SUMMARY -->
---
> [!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.
>
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
b84edf3. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->1 parent cdf56ce commit 961c01b
19 files changed
Lines changed: 862 additions & 680 deletions
File tree
- app/core/HardwareWallet
- adapters
- components/HardwareWalletBottomSheet
- contents
- hooks
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
47 | | - | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | | - | |
55 | 47 | | |
56 | 48 | | |
57 | 49 | | |
| |||
0 commit comments