-
Notifications
You must be signed in to change notification settings - Fork 4
feat: back up hardware wallet names #681
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 10 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
04cad36
feat: store methods
jvsena42 ae34b3e
feat: backup wiring
jvsena42 b165d3a
feat: create and consume pending names
jvsena42 5ee1cf5
feat: wallet removal flow
jvsena42 289d2e1
feat: UI handling
jvsena42 a1e0347
test: HW name persistense tests
jvsena42 4ec04f9
chore: rename changelog
jvsena42 bf3684b
fix: prefill device name with stored data
jvsena42 e8fd0d7
fix: get stored name on reconnect flow
jvsena42 46944f6
fix: shoten switch label
jvsena42 68c0eda
fix: toggle state update
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
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,111 @@ | ||
| import SwiftUI | ||
|
|
||
| /// Confirms removing a paired hardware wallet, offering to carry its name and tags in the backup so | ||
| /// re-pairing the device restores them. Shared by the wallet screen and the hardware wallet settings. | ||
| /// | ||
| /// A card rather than a native `.alert`, which cannot hold the switch. Ports bitkit-android's | ||
| /// `RemoveHwWalletDialog`. | ||
| struct RemoveHwWalletDialog: View { | ||
| let walletName: String | ||
| @Binding var keepBackupData: Bool | ||
| let onConfirm: () -> Void | ||
| let onDismiss: () -> Void | ||
|
|
||
| var body: some View { | ||
| ZStack { | ||
| Color.black.opacity(0.6) | ||
| .ignoresSafeArea() | ||
| .onTapGesture(perform: onDismiss) | ||
| .accessibilityHidden(true) | ||
|
|
||
| VStack(alignment: .leading, spacing: 0) { | ||
| SubtitleText(t("hardware__remove_dialog_title", variables: ["name": walletName])) | ||
| .padding(.bottom, 8) | ||
|
|
||
| BodyMText(t("hardware__remove_dialog_text")) | ||
| .padding(.bottom, 16) | ||
|
|
||
| keepBackupDataRow | ||
| .padding(.bottom, 24) | ||
|
|
||
| HStack(spacing: 16) { | ||
| CustomButton(title: t("common__dialog_cancel"), variant: .secondary, shouldExpand: true) { | ||
| onDismiss() | ||
| } | ||
| .accessibilityIdentifier("DialogCancel") | ||
|
|
||
| CustomButton(title: t("common__remove"), shouldExpand: true) { | ||
| onConfirm() | ||
| } | ||
| .accessibilityIdentifier("DialogConfirm") | ||
| } | ||
| } | ||
| .padding(24) | ||
| .background(Color.gray6) | ||
| .clipShape(RoundedRectangle(cornerRadius: 16)) | ||
| .padding(.horizontal, 32) | ||
| .frame(maxWidth: 400) | ||
| } | ||
| .accessibilityElement(children: .contain) | ||
| .accessibilityIdentifier("RemoveHwWalletDialog") | ||
| } | ||
|
|
||
| private var keepBackupDataRow: some View { | ||
| HStack(spacing: 16) { | ||
| BodyMSBText(t("hardware__remove_dialog_keep")) | ||
| .frame(maxWidth: .infinity, alignment: .leading) | ||
|
|
||
| Toggle("", isOn: $keepBackupData) | ||
| .toggleStyle(SwitchToggleStyle(tint: .brandAccent)) | ||
| .labelsHidden() | ||
| .accessibilityLabel(t("hardware__remove_dialog_keep")) | ||
| .accessibilityIdentifier("HwRemoveKeepBackupToggle") | ||
| } | ||
| .contentShape(Rectangle()) | ||
| .onTapGesture { keepBackupData.toggle() } | ||
| } | ||
| } | ||
|
|
||
| extension RemoveHwWalletDialog { | ||
| /// Message for a failed removal. An unreadable tag read leaves the wallet untouched, so it names | ||
| /// the way through instead of asking for a retry that would repeat the same failure. | ||
| static func errorDescription(for error: Error) -> String { | ||
| if let removalError = error as? HwWalletRemovalError, removalError == .backupDataUnreadable { | ||
| return t("hardware__remove_keep_error") | ||
| } | ||
| return t("hardware__remove_error") | ||
| } | ||
| } | ||
|
|
||
| extension View { | ||
| /// Overlays `RemoveHwWalletDialog` while `walletName` is non-nil. Nil dismisses it, so the caller | ||
| /// keeps the wallet being removed in one piece of state rather than two that can disagree. | ||
| func removeHwWalletDialog( | ||
| walletName: String?, | ||
| keepBackupData: Binding<Bool>, | ||
| onConfirm: @escaping () -> Void, | ||
| onDismiss: @escaping () -> Void | ||
| ) -> some View { | ||
| overlay { | ||
| if let walletName { | ||
| RemoveHwWalletDialog( | ||
| walletName: walletName, | ||
| keepBackupData: keepBackupData, | ||
| onConfirm: onConfirm, | ||
| onDismiss: onDismiss | ||
| ) | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| #Preview { | ||
| Color.black | ||
| .removeHwWalletDialog( | ||
| walletName: "Trezor Safe 3", | ||
| keepBackupData: .constant(true), | ||
| onConfirm: {}, | ||
| onDismiss: {} | ||
| ) | ||
| .preferredColorScheme(.dark) | ||
| } | ||
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
Oops, something went wrong.
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.