-
Notifications
You must be signed in to change notification settings - Fork 3
feat: hardware wallet detail screen #611
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
c12d814
feat: hardware wallet activities screen
jvsena42 0fb4e8d
fix: replace cropped trezor image
jvsena42 758a1db
fix: trezor image dimensions and rotation
jvsena42 8dae92f
Merge branch 'master' into feat/hw-wallet-activity
jvsena42 bf01e66
fix: disconnect session when forgetDevice is called
jvsena42 50435ae
Merge branch 'feat/hw-wallet-activity' of github.com:synonymdev/bitki…
jvsena42 080608a
fix: reduce wallet computation and assert loadActivities run in MainA…
jvsena42 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
8 changes: 8 additions & 0 deletions
8
Bitkit/Assets.xcassets/Illustrations/trezor-device.imageset/Contents.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| { | ||
| "images" : [ | ||
| { "filename" : "trezor-device.png", "idiom" : "universal", "scale" : "1x" }, | ||
| { "filename" : "trezor-device@2x.png", "idiom" : "universal", "scale" : "2x" }, | ||
| { "filename" : "trezor-device@3x.png", "idiom" : "universal", "scale" : "3x" } | ||
| ], | ||
| "info" : { "author" : "xcode", "version" : 1 } | ||
| } |
Binary file added
BIN
+79.7 KB
Bitkit/Assets.xcassets/Illustrations/trezor-device.imageset/trezor-device.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+329 KB
Bitkit/Assets.xcassets/Illustrations/trezor-device.imageset/trezor-device@2x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+799 KB
Bitkit/Assets.xcassets/Illustrations/trezor-device.imageset/trezor-device@3x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,207 @@ | ||
| import BitkitCore | ||
| import SwiftUI | ||
|
|
||
| /// Detail overview of a paired hardware wallet, tracked as a watch-only balance. Mirrors the | ||
| /// Savings/Spending screens: device name + blue Bitcoin icon in the top bar, balance header, the | ||
| /// device's on-chain activity grouped by date (blue hardware icons), a Transfer-To-Spending | ||
| /// placeholder on funded devices, and a Remove action. Ports bitkit-android's `HardwareWalletScreen`. | ||
| struct HardwareWalletScreen: View { | ||
| let deviceId: String | ||
|
|
||
| @EnvironmentObject var activity: ActivityListViewModel | ||
| @EnvironmentObject var app: AppViewModel | ||
| @EnvironmentObject var navigation: NavigationViewModel | ||
| @Environment(HwWalletManager.self) private var hwWalletManager | ||
| @Environment(TrezorManager.self) private var trezorManager | ||
|
|
||
| @State private var activities: [Activity] = [] | ||
| @State private var showRemoveDialog = false | ||
|
|
||
| private var wallet: HwWallet? { | ||
| hwWalletManager.wallets.first { $0.deviceIds.contains(deviceId) } | ||
| } | ||
|
|
||
| var body: some View { | ||
| let wallet = wallet | ||
|
|
||
| return ZStack(alignment: .top) { | ||
| if let wallet { | ||
| NavigationBar(title: wallet.name, icon: "btc-circle-blue") | ||
| .padding(.horizontal, 16) | ||
|
|
||
| content(for: wallet) | ||
|
|
||
| bottomGradient | ||
| } | ||
| } | ||
| .navigationBarHidden(true) | ||
| .task(id: wallet?.walletId) { | ||
| await loadActivities() | ||
| } | ||
| .onReceive(activity.activitiesChangedPublisher) { _ in | ||
| Task { await loadActivities() } | ||
|
jvsena42 marked this conversation as resolved.
|
||
| } | ||
| // Leave the screen once the device is gone, whether removed here or forgotten elsewhere. | ||
| .onChange(of: wallet != nil) { _, stillPaired in | ||
| if hwWalletManager.walletsLoaded, !stillPaired { | ||
| navigation.navigateBack() | ||
| } | ||
| } | ||
| .alert( | ||
| t("hardware__remove_dialog_title", variables: ["name": wallet?.name ?? ""]), | ||
| isPresented: $showRemoveDialog | ||
| ) { | ||
| Button(t("common__remove"), role: .destructive) { | ||
| Task { await removeWallet() } | ||
| } | ||
| Button(t("common__dialog_cancel"), role: .cancel) {} | ||
| } message: { | ||
| Text(t("hardware__remove_dialog_text")) | ||
| } | ||
| } | ||
|
|
||
| private func content(for wallet: HwWallet) -> some View { | ||
| let hasFunds = wallet.balanceSats > 0 | ||
| let hasActivity = !activities.isEmpty | ||
|
|
||
| return VStack(spacing: 0) { | ||
| ScrollView(showsIndicators: false) { | ||
| MoneyStack( | ||
| sats: Int(clamping: wallet.balanceSats), | ||
| showSymbol: true, | ||
| enableSwipeGesture: true, | ||
| enableHide: true, | ||
| testIdPrefix: "TotalBalance" | ||
| ) | ||
|
|
||
| if hasFunds { | ||
| transferButton | ||
| .padding(.top, 28) | ||
| } | ||
|
|
||
| if hasActivity { | ||
| HardwareWalletActivityList(activities: activities) | ||
| .padding(.top, 32) | ||
| } | ||
|
|
||
| removeButton(for: wallet) | ||
| .padding(.top, 16) | ||
| } | ||
| .contentMargins(.top, ScreenLayout.topPaddingWithoutSafeArea) | ||
| .contentMargins(.bottom, ScreenLayout.bottomPaddingWithSafeArea) | ||
| .frame(maxWidth: .infinity, minHeight: 400) | ||
| } | ||
| .padding(.horizontal) | ||
| .background(alignment: .topTrailing) { | ||
| trezorIllustration | ||
| // Align the device's top with the balance header and bleed off the trailing edge. | ||
| .offset(x: 118, y: ScreenLayout.topPaddingWithoutSafeArea) | ||
| } | ||
| } | ||
|
|
||
| /// The shared upright Trezor device, transformed to match the Figma "Wallet Overview" visual: | ||
| /// cover-filled into a square, rotated -15°, and clipped to a 256pt box that bleeds off the | ||
| /// screen's trailing edge. Reuses the generic `trezor-device` asset — no screen-specific crop is | ||
| /// baked in, so the same image can be adapted elsewhere with SwiftUI. | ||
| private var trezorIllustration: some View { | ||
| Image("trezor-device") | ||
| .resizable() | ||
| .aspectRatio(contentMode: .fill) | ||
| .frame(width: 268, height: 268) | ||
|
jvsena42 marked this conversation as resolved.
|
||
| .clipped() | ||
| .rotationEffect(.degrees(-15)) | ||
| .offset(x: 9, y: 13) | ||
| .frame(width: 256, height: 256) | ||
| .clipped() | ||
| } | ||
|
|
||
| private var transferButton: some View { | ||
| CustomButton( | ||
| title: t("lightning__transfer_to_spending_button"), | ||
| variant: .secondary, | ||
|
jvsena42 marked this conversation as resolved.
|
||
| icon: Image("arrow-up-down") | ||
| .resizable() | ||
| .scaledToFit() | ||
| .frame(width: 16, height: 16) | ||
| .foregroundColor(.white80) | ||
| ) { | ||
| app.toast(type: .warning, title: t("hardware__transfer_not_implemented")) | ||
| } | ||
| .accessibilityIdentifier("HwTransferToSpending") | ||
| } | ||
|
|
||
|
jvsena42 marked this conversation as resolved.
|
||
| private func removeButton(for wallet: HwWallet) -> some View { | ||
| CustomButton( | ||
| title: t("hardware__remove_button", variables: ["name": wallet.name]), | ||
| variant: .tertiary | ||
| ) { | ||
| showRemoveDialog = true | ||
| } | ||
| .accessibilityIdentifier("RemoveHardwareWallet") | ||
| } | ||
|
|
||
| private var bottomGradient: some View { | ||
| VStack { | ||
| Spacer() | ||
| LinearGradient( | ||
| colors: [.black.opacity(0), .black], | ||
| startPoint: .top, | ||
| endPoint: .bottom | ||
| ) | ||
| .frame(height: ScreenLayout.bottomPaddingWithSafeArea) | ||
| } | ||
| .ignoresSafeArea(edges: .bottom) | ||
| .allowsHitTesting(false) | ||
| } | ||
|
|
||
| @MainActor | ||
| private func loadActivities() async { | ||
| guard let walletId = wallet?.walletId else { return } | ||
| do { | ||
| activities = try await CoreService.shared.activity.get(filter: .all, walletId: walletId) | ||
| } catch { | ||
| Logger.error(error, context: "HardwareWalletScreen failed to load activities") | ||
| } | ||
| } | ||
|
|
||
| /// Stop watching and forget every entry for this wallet (the same device may be paired over | ||
| /// multiple transports). `removeDevice` stops the watchers and deletes the persisted activities; | ||
| /// `forgetDevice` clears credentials and drops the known-device entry, which re-pushes the device | ||
| /// snapshot and removes the tile. The reactive auto-pop above then leaves the screen. | ||
| private func removeWallet() async { | ||
| guard let wallet else { return } | ||
| hwWalletManager.removeDevice(id: wallet.id) | ||
| for id in wallet.deviceIds { | ||
| await trezorManager.forgetDevice(id: id) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /// The hardware wallet's on-chain activity, grouped by date and rendered with the shared activity | ||
| /// row. Hardware activities draw the blue icon automatically (derived from their `walletId`). | ||
| private struct HardwareWalletActivityList: View { | ||
| @EnvironmentObject var activity: ActivityListViewModel | ||
| @EnvironmentObject var feeEstimatesManager: FeeEstimatesManager | ||
|
|
||
| let activities: [Activity] | ||
|
|
||
| var body: some View { | ||
| let groupedItems = activity.groupActivities(activities) | ||
|
|
||
| LazyVStack(alignment: .leading, spacing: 16) { | ||
| ForEach(Array(zip(groupedItems.indices, groupedItems)), id: \.1) { index, groupItem in | ||
| switch groupItem { | ||
| case let .header(title): | ||
| CaptionMText(title) | ||
| .frame(height: 34, alignment: .bottom) | ||
|
|
||
| case let .activity(item): | ||
| NavigationLink(value: Route.activityDetail(item)) { | ||
| ActivityRow(item: item, feeEstimates: feeEstimatesManager.estimates) | ||
| } | ||
| .accessibilityIdentifier("Activity-\(index)") | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.