From 5bf523b81904a9a15dbdf4ea8e9d22f986d7fc76 Mon Sep 17 00:00:00 2001 From: ant013 Date: Fri, 13 Oct 2023 14:33:38 +0600 Subject: [PATCH] Make ui-fixes for app backup feature --- .../RestoreCloudViewController.swift | 7 ++-- .../RestoreFileConfigurationModule.swift | 1 + ...storeFileConfigurationViewController.swift | 13 ++++++- .../RestoreFileConfigurationViewModel.swift | 17 ++++++++- .../BackupDisclaimerView.swift | 2 +- .../Backup/BackupList/BackupListView.swift | 38 ++++++++++--------- .../en.lproj/Localizable.strings | 2 +- 7 files changed, 54 insertions(+), 26 deletions(-) diff --git a/UnstoppableWallet/UnstoppableWallet/Modules/RestoreAccount/RestoreCloud/RestoreCloudViewController.swift b/UnstoppableWallet/UnstoppableWallet/Modules/RestoreAccount/RestoreCloud/RestoreCloudViewController.swift index e119ec7eb6..2d2fbf8531 100644 --- a/UnstoppableWallet/UnstoppableWallet/Modules/RestoreAccount/RestoreCloud/RestoreCloudViewController.swift +++ b/UnstoppableWallet/UnstoppableWallet/Modules/RestoreAccount/RestoreCloud/RestoreCloudViewController.swift @@ -174,13 +174,12 @@ class RestoreCloudViewController: ThemeViewController { extension RestoreCloudViewController: SectionsDataSource { func buildSections() -> [SectionProtocol] { - guard !walletViewItem.isEmpty else { + guard !walletViewItem.isEmpty || !fullBackupViewItem.isEmpty else { return [] } - var sections = [ - descriptionSection, - ] + var sections = [ descriptionSection ] + if !walletViewItem.notImported.isEmpty { sections.append( section(id: "not_imported", headerTitle: "restore.cloud.wallets".localized, viewItems: viewModel.walletViewItem.notImported) diff --git a/UnstoppableWallet/UnstoppableWallet/Modules/RestoreAccount/RestoreFile/RestoreFileConfiguration/RestoreFileConfigurationModule.swift b/UnstoppableWallet/UnstoppableWallet/Modules/RestoreAccount/RestoreFile/RestoreFileConfiguration/RestoreFileConfigurationModule.swift index 2f0430fd91..0c74369fb6 100644 --- a/UnstoppableWallet/UnstoppableWallet/Modules/RestoreAccount/RestoreFile/RestoreFileConfiguration/RestoreFileConfigurationModule.swift +++ b/UnstoppableWallet/UnstoppableWallet/Modules/RestoreAccount/RestoreFile/RestoreFileConfiguration/RestoreFileConfigurationModule.swift @@ -5,6 +5,7 @@ class RestoreFileConfigurationModule { let viewModel = RestoreFileConfigurationViewModel( cloudBackupManager: App.shared.cloudBackupManager, appBackupProvider: App.shared.appBackupProvider, + contactBookManager: App.shared.contactManager, rawBackup: rawBackup ) diff --git a/UnstoppableWallet/UnstoppableWallet/Modules/RestoreAccount/RestoreFile/RestoreFileConfiguration/RestoreFileConfigurationViewController.swift b/UnstoppableWallet/UnstoppableWallet/Modules/RestoreAccount/RestoreFile/RestoreFileConfiguration/RestoreFileConfigurationViewController.swift index c99e24a21e..1143d7943c 100644 --- a/UnstoppableWallet/UnstoppableWallet/Modules/RestoreAccount/RestoreFile/RestoreFileConfiguration/RestoreFileConfigurationViewController.swift +++ b/UnstoppableWallet/UnstoppableWallet/Modules/RestoreAccount/RestoreFile/RestoreFileConfiguration/RestoreFileConfigurationViewController.swift @@ -52,6 +52,13 @@ class RestoreFileConfigurationViewController: KeyboardAwareViewController { restoreButton.addTarget(self, action: #selector(onTapRestore), for: .touchUpInside) restoreButton.set(style: .yellow) + viewModel.showMergeAlertPublisher + .receive(on: DispatchQueue.main) + .sink { [weak self] in + self?.showMergeAlert() + } + .store(in: &cancellables) + viewModel.finishedPublisher .receive(on: DispatchQueue.main) .sink { [weak self] success in @@ -75,6 +82,10 @@ class RestoreFileConfigurationViewController: KeyboardAwareViewController { } @objc private func onTapRestore() { + viewModel.onTapRestore() + } + + private func showMergeAlert() { let viewController = BottomSheetModule.viewController( image: .local(image: UIImage(named: "warning_2_24")?.withTintColor(.themeJacob)), title: "alert.notice".localized, @@ -83,7 +94,7 @@ class RestoreFileConfigurationViewController: KeyboardAwareViewController { ], buttons: [ .init(style: .red, title: "backup_app.restore.notice.merge".localized, actionType: .afterClose) { [weak self] in - self?.viewModel.onTapRestore() + self?.viewModel.restore() }, .init(style: .transparent, title: "button.cancel".localized, actionType: .afterClose), ] diff --git a/UnstoppableWallet/UnstoppableWallet/Modules/RestoreAccount/RestoreFile/RestoreFileConfiguration/RestoreFileConfigurationViewModel.swift b/UnstoppableWallet/UnstoppableWallet/Modules/RestoreAccount/RestoreFile/RestoreFileConfiguration/RestoreFileConfigurationViewModel.swift index 10a56c7e9a..e7e96509a5 100644 --- a/UnstoppableWallet/UnstoppableWallet/Modules/RestoreAccount/RestoreFile/RestoreFileConfiguration/RestoreFileConfigurationViewModel.swift +++ b/UnstoppableWallet/UnstoppableWallet/Modules/RestoreAccount/RestoreFile/RestoreFileConfiguration/RestoreFileConfigurationViewModel.swift @@ -4,13 +4,16 @@ import Combine class RestoreFileConfigurationViewModel { private let cloudBackupManager: CloudBackupManager private let appBackupProvider: AppBackupProvider + private let contactBookManager: ContactBookManager private let rawBackup: RawFullBackup + private let showMergeAlertSubject = PassthroughSubject() private let finishedSubject = PassthroughSubject() - init(cloudBackupManager: CloudBackupManager, appBackupProvider: AppBackupProvider, rawBackup: RawFullBackup) { + init(cloudBackupManager: CloudBackupManager, appBackupProvider: AppBackupProvider, contactBookManager: ContactBookManager, rawBackup: RawFullBackup) { self.cloudBackupManager = cloudBackupManager self.appBackupProvider = appBackupProvider + self.contactBookManager = contactBookManager self.rawBackup = rawBackup } @@ -61,10 +64,22 @@ extension RestoreFileConfigurationViewModel { } func onTapRestore() { + if contactBookManager.state.data?.contacts.isEmpty ?? true { + restore() + } else { + showMergeAlertSubject.send() + } + } + + func restore() { appBackupProvider.restore(raw: rawBackup) finishedSubject.send(true) } + var showMergeAlertPublisher: AnyPublisher { + showMergeAlertSubject.eraseToAnyPublisher() + } + var finishedPublisher: AnyPublisher { finishedSubject.eraseToAnyPublisher() } diff --git a/UnstoppableWallet/UnstoppableWallet/Modules/Settings/BackupApp/Backup/BackupDisclaimer/BackupDisclaimerView.swift b/UnstoppableWallet/UnstoppableWallet/Modules/Settings/BackupApp/Backup/BackupDisclaimer/BackupDisclaimerView.swift index 2193670173..840c33584a 100644 --- a/UnstoppableWallet/UnstoppableWallet/Modules/Settings/BackupApp/Backup/BackupDisclaimer/BackupDisclaimerView.swift +++ b/UnstoppableWallet/UnstoppableWallet/Modules/Settings/BackupApp/Backup/BackupDisclaimer/BackupDisclaimerView.swift @@ -6,7 +6,7 @@ struct BackupDisclaimerView: View { @ObservedObject var viewModel: BackupAppViewModel var onDismiss: (() -> Void)? - @State var isOn: Bool = true + @State var isOn: Bool = false var body: some View { let backupDisclaimer = (viewModel.destination ?? .local).backupDisclaimer diff --git a/UnstoppableWallet/UnstoppableWallet/Modules/Settings/BackupApp/Backup/BackupList/BackupListView.swift b/UnstoppableWallet/UnstoppableWallet/Modules/Settings/BackupApp/Backup/BackupList/BackupListView.swift index f4e194cbb7..5bd429518a 100644 --- a/UnstoppableWallet/UnstoppableWallet/Modules/Settings/BackupApp/Backup/BackupList/BackupListView.swift +++ b/UnstoppableWallet/UnstoppableWallet/Modules/Settings/BackupApp/Backup/BackupList/BackupListView.swift @@ -10,28 +10,30 @@ struct BackupListView: View { ThemeView { BottomGradientWrapper { VStack(spacing: .margin24) { - VStack(spacing: 0) { - ListSectionHeader(text: "backup_app.backup_list.header.wallets".localized) + if !viewModel.accountItems.isEmpty { + VStack(spacing: 0) { + ListSectionHeader(text: "backup_app.backup_list.header.wallets".localized) - ListSection { - ForEach(viewModel.accountItems, id: \.accountId) { (item: BackupAppModule.AccountItem) in - if viewModel.selected[item.id] != nil { - let selected = binding(for: item.accountId) + ListSection { + ForEach(viewModel.accountItems, id: \.accountId) { (item: BackupAppModule.AccountItem) in + if viewModel.selected[item.id] != nil { + let selected = binding(for: item.accountId) - ClickableRow(action: { - viewModel.toggle(item: item) - }) { - HStack { - AccountView(item: item) + ClickableRow(action: { + viewModel.toggle(item: item) + }) { + HStack { + AccountView(item: item) - Toggle(isOn: selected) {} - .labelsHidden() - .toggleStyle(CheckboxStyle()) + Toggle(isOn: selected) {} + .labelsHidden() + .toggleStyle(CheckboxStyle()) + } + } + } else { + ListRow { + AccountView(item: item) } - } - } else { - ListRow { - AccountView(item: item) } } } diff --git a/UnstoppableWallet/UnstoppableWallet/en.lproj/Localizable.strings b/UnstoppableWallet/UnstoppableWallet/en.lproj/Localizable.strings index b9242c198c..9188baae28 100644 --- a/UnstoppableWallet/UnstoppableWallet/en.lproj/Localizable.strings +++ b/UnstoppableWallet/UnstoppableWallet/en.lproj/Localizable.strings @@ -271,7 +271,7 @@ Go to Settings - > %@ and allow access to the camera."; "backup.cloud.password.confirm.placeholder" = "Confirm"; "backup.cloud.password.save" = "Save and Backup"; -"backup.cloud.password.error.empty_passphrase" = "Passphrase cannot be empty"; +"backup.cloud.password.error.empty_passphrase" = "Password cannot be empty"; "backup.cloud.password.error.forbidden_symbols" = "Please use only supported symbols: A-Z a-z 0-9 ' \" ` & / ? ! : ; . , ~ * $ = + - [ ] ( ) { } < > \\ _ # @ | %"; "backup.cloud.password.error.minimum_requirement" = "At least 8 characters, including one uppercase letter, one lowercase letter, one number, and one symbol"; "backup.cloud.password.error.invalid_password" = "Incorrect Password";