feat: home screen hardware wallet ui#999
Conversation
0a23adb to
b56896b
Compare
490121b to
a4dbd43
Compare
|
@greptile review |
Greptile SummaryThis PR introduces the first slice of the Trezor hardware wallet epic: a watch-only balance/activity layer backed by per-(device, address-type) xpub watchers, a new hardware-wallet row beneath the Savings/Spending tiles, headline-total inclusion, merged recent-activity, and a stub connect sheet opened from a new
Confidence Score: 3/5The data layer and UI wiring are solid, but the stub connect sheet ships production-visible hardcoded English strings (including a 'not yet implemented' message) to users who tap the Hardware suggestion card, and a watcher-stop failure path in HwWalletRepo can cause stale balance data to persistently re-appear. The core watch-only balance and activity plumbing is well-structured and backed by unit tests. The main concern before shipping is HardwareWalletConnectSheet.kt: three user-facing strings are hardcoded in English and bypass localisation, and the copy tells users the feature is 'not yet implemented' — which is confusing in a production release. Additionally, HwWalletRepo.syncWatchers silently discards the stopWatcher result, so a failed stop leaves the watcher active; observeWatcherEvents will continue writing its balance updates back into _watcherData, making the entry impossible to evict until the next settings change triggers a new sync cycle. HardwareWalletConnectSheet.kt needs production-ready copy and string resources before shipping; HwWalletRepo.kt syncWatchers needs the stopWatcher result checked; HomeViewModel.kt emptyWalletSuggestions is missing the HARDWARE card.
|
| Filename | Overview |
|---|---|
| app/src/main/java/to/bitkit/repositories/HwWalletRepo.kt | New singleton that aggregates watch-only balances and activity per device; core logic is sound but stopWatcher result is silently discarded, leaving a window where stale watchers can re-populate _watcherData. |
| app/src/main/java/to/bitkit/ui/sheets/HardwareWalletConnectSheet.kt | Stub connect sheet with three hardcoded English user-visible strings that should be in strings.xml per AGENTS.md; one string explicitly says 'not yet implemented' and will be shown to production users. |
| app/src/main/java/to/bitkit/ui/screens/wallets/HomeViewModel.kt | Wires hardware wallets into the suggestion flow correctly for spending/savings-only states, but emptyWalletSuggestions is not updated and never includes the HARDWARE card. |
| app/src/main/java/to/bitkit/repositories/TrezorRepo.kt | Adds fetchAccountXpubs on connect and persists xpubs in KnownDevice; failures are swallowed per-type with a warning, fallback to previous xpubs is handled correctly. |
| app/src/main/java/to/bitkit/services/TrezorTransport.kt | Adds a BroadcastReceiver for BT state-change and USB detach events to surface link loss that GATT misses; registration uses RECEIVER_NOT_EXPORTED correctly. |
| app/src/main/java/to/bitkit/repositories/WalletRepo.kt | Wires hwWalletRepo.totalHardwareSats into _balanceState and preserves live hardware total on syncBalances; the syncBalances path correctly uses .value to avoid dropping updates. |
| app/src/main/java/to/bitkit/ui/screens/wallets/HomeScreen.kt | Adds hardware wallet grid rows beneath Savings/Spending tiles and wires totalWithHardwareSats to the headline total; UI refactoring is clean and the grid layout handles 1, 2, and 3+ devices. |
| app/src/main/java/to/bitkit/viewmodels/ActivityListViewModel.kt | Merges hardware wallet activity into the home activity list, sorted by timestamp and capped at the same limit; the null-initial-state handling is correct. |
| app/src/main/java/to/bitkit/models/BalanceState.kt | Adds totalHardwareSats field and totalWithHardwareSats computed property using safe() arithmetic to prevent overflow; covered by new unit tests. |
| app/src/test/java/to/bitkit/repositories/HwWalletRepoTest.kt | Good coverage of the aggregation logic (zero-balance init, multi-watcher sum, address-type filtering, and activity mapping); uses test dispatcher correctly. |
Sequence Diagram
sequenceDiagram
participant TT as TrezorTransport
participant TR as TrezorRepo
participant HW as HwWalletRepo
participant WR as WalletRepo
participant HVM as HomeViewModel
participant ALV as ActivityListViewModel
TT->>TR: externalDisconnect (BT off / USB unplug)
TR-->>HW: state (connectedDeviceId cleared)
HW-->>HVM: "hardwareWallets (isConnected=false)"
TR->>TR: addOrUpdateKnownDevice (on connect)
TR->>TR: fetchAccountXpubs()
TR-->>HW: trezorStore.data (KnownDevice with xpubs)
HW->>TR: startWatcher(watcherId, xpub, accountType)
TR-->>HW: watcherEvents (TransactionsChanged)
HW->>HW: _watcherData.update (balance + activities)
HW-->>WR: totalHardwareSats
WR->>WR: _balanceState.update(copy(totalHardwareSats))
HW-->>HVM: hardwareWallets
HVM->>HVM: _uiState.update(copy(hardwareWallets))
HW-->>ALV: hardwareActivities
ALV->>ALV: combine(localActivities, hardwareActivities) → latestActivities
Comments Outside Diff (1)
-
app/src/main/java/to/bitkit/ui/screens/wallets/HomeViewModel.kt, line 372-386 (link)HARDWAREsuggestion absent for empty-wallet usersemptyWalletSuggestionsis the only suggestion builder that does not receivehasHardwareWalletand does not includeSuggestion.HARDWARE.takeIf { !hasHardwareWallet }. A user who has no savings and no spending balance — the "empty wallet" state — will therefore never see the Hardware / Connect device card, even though they could still own a Trezor they want to track. The two other builders (spendingSuggestions,savingsOnlySuggestions) both include the card, making the omission asymmetric and likely unintentional.
Reviews (1): Last reviewed commit: "docs: reference test files by name in pr..." | Re-trigger Greptile
Part of #998
This PR brings the first slice of the Trezor hardware wallet epic to the wallet home screen. A paired Trezor now shows up as a watch-only balance: a device row under the Savings/Spending tiles, its sats folded into the headline total, and its on-chain transactions merged into the recent activity list. A new Hardware suggestion card prompts users with no paired device to start connecting.
Description
Preview
trezorBle2x.mp4
trezorUsb2x.mp4
receive2x.mp4
Edge Cases
trezorViaBle.Usb2x.mp4
QA Notes
Manual Tests
regression:open Receive and other large sheets: sheet top sits below the home toolbar, toolbar fully visible.Automated Checks
HwWalletRepoTest.kt.BalanceStateTest.kt.WalletRepoTest.ktandDeriveBalanceStateUseCaseTest.kt.ActivityDetailViewModelTest.kt.HwWalletRepoTest.kt.HwWalletRepoTest.kt.TrezorRepoTest.kt.TrezorRepoTest.kt.ActivityListViewModelTest.kt.just compile,just test(full suite),just lint.