From 194623e11634f92e4d4580dd65f89b400f05a7d2 Mon Sep 17 00:00:00 2001 From: ant013 Date: Wed, 4 Oct 2023 17:21:08 +0400 Subject: [PATCH] Fix handling icloud oneWalletBackups for v1 and v2 - add fileBackedUp field for accounts --- .../Core/Crypto/WalletBackup.swift | 8 +- .../Core/Factories/AccountFactory.swift | 8 +- .../Core/Managers/CloudBackupManager.swift | 7 +- .../Core/Storage/AccountStorage.swift | 4 +- .../Core/Storage/StorageMigrator.swift | 3 +- .../UnstoppableWallet/Models/Account.swift | 4 +- .../Models/AccountRecord.swift | 8 +- .../Backup/ICloud/AppBackupProvider.swift | 13 +- .../RestoreBinanceService.swift | 2 +- .../CreateAccount/CreateAccountService.swift | 1 + .../RestoreCloud/RestoreCloudModule.swift | 1 + .../RestoreCloudPassphraseService.swift | 9 +- ...RestoreCloudPassphraseViewController.swift | 150 +++++++++--------- .../RestoreSelect/RestoreSelectModule.swift | 3 +- .../RestoreSelect/RestoreSelectService.swift | 28 ++-- 15 files changed, 147 insertions(+), 102 deletions(-) diff --git a/UnstoppableWallet/UnstoppableWallet/Core/Crypto/WalletBackup.swift b/UnstoppableWallet/UnstoppableWallet/Core/Crypto/WalletBackup.swift index df55844c58..78611a0aad 100644 --- a/UnstoppableWallet/UnstoppableWallet/Core/Crypto/WalletBackup.swift +++ b/UnstoppableWallet/UnstoppableWallet/Core/Crypto/WalletBackup.swift @@ -5,6 +5,7 @@ class WalletBackup: Codable { let id: String let type: AccountType.Abstract let isManualBackedUp: Bool + let isFileBackedUp: Bool let version: Int let timestamp: TimeInterval? let enabledWallets: [EnabledWallet] @@ -15,16 +16,18 @@ class WalletBackup: Codable { case id case type case isManualBackedUp = "manual_backup" + case isFileBackedUp = "file_backup" case version case timestamp } - init(crypto: BackupCrypto, enabledWallets: [EnabledWallet], id: String, type: AccountType.Abstract, isManualBackedUp: Bool, version: Int, timestamp: TimeInterval) { + init(crypto: BackupCrypto, enabledWallets: [EnabledWallet], id: String, type: AccountType.Abstract, isManualBackedUp: Bool, isFileBackedUp: Bool, version: Int, timestamp: TimeInterval) { self.crypto = crypto self.enabledWallets = enabledWallets self.id = id self.type = type self.isManualBackedUp = isManualBackedUp + self.isFileBackedUp = isFileBackedUp self.version = version self.timestamp = timestamp } @@ -37,6 +40,8 @@ class WalletBackup: Codable { type = try container.decode(AccountType.Abstract.self, forKey: .type) let isManualBackedUp = try? container.decode(Bool.self, forKey: .isManualBackedUp) self.isManualBackedUp = isManualBackedUp ?? false + let isFileBackedUp = try? container.decode(Bool.self, forKey: .isFileBackedUp) + self.isFileBackedUp = isFileBackedUp ?? false version = try container.decode(Int.self, forKey: .version) timestamp = try? container.decode(TimeInterval.self, forKey: .timestamp) } @@ -48,6 +53,7 @@ class WalletBackup: Codable { try container.encode(id, forKey: .id) try container.encode(type, forKey: .type) try container.encode(isManualBackedUp, forKey: .isManualBackedUp) + try container.encode(isFileBackedUp, forKey: .isFileBackedUp) try container.encode(version, forKey: .version) try container.encode(timestamp, forKey: .timestamp) } diff --git a/UnstoppableWallet/UnstoppableWallet/Core/Factories/AccountFactory.swift b/UnstoppableWallet/UnstoppableWallet/Core/Factories/AccountFactory.swift index 778d6af7c7..abc36cba0a 100644 --- a/UnstoppableWallet/UnstoppableWallet/Core/Factories/AccountFactory.swift +++ b/UnstoppableWallet/UnstoppableWallet/Core/Factories/AccountFactory.swift @@ -36,14 +36,15 @@ extension AccountFactory { return "Watch Wallet \(order)" } - func account(type: AccountType, origin: AccountOrigin, backedUp: Bool, name: String) -> Account { + func account(type: AccountType, origin: AccountOrigin, backedUp: Bool, fileBackedUp: Bool, name: String) -> Account { Account( id: UUID().uuidString, level: accountManager.currentLevel, name: name, type: type, origin: origin, - backedUp: backedUp + backedUp: backedUp, + fileBackedUp: fileBackedUp ) } @@ -54,7 +55,8 @@ extension AccountFactory { name: name, type: type, origin: .restored, - backedUp: true + backedUp: true, + fileBackedUp: false ) } } diff --git a/UnstoppableWallet/UnstoppableWallet/Core/Managers/CloudBackupManager.swift b/UnstoppableWallet/UnstoppableWallet/Core/Managers/CloudBackupManager.swift index 5ef7ae1bf1..d9ccac8749 100644 --- a/UnstoppableWallet/UnstoppableWallet/Core/Managers/CloudBackupManager.swift +++ b/UnstoppableWallet/UnstoppableWallet/Core/Managers/CloudBackupManager.swift @@ -71,7 +71,12 @@ class CloudBackupManager { do { forceDownloadContainerFiles(url: url) - let oneWalletItems: [String: WalletBackup] = try Self.downloadItems(url: url, fileStorage: fileStorage, logger: logger) + + var oneWalletItems: [String: WalletBackup] = try Self.downloadItems(url: url, fileStorage: fileStorage, logger: logger) + let oneWalletItemsV2: [String: RestoreCloudModule.RestoredBackup] = try Self.downloadItems(url: url, fileStorage: fileStorage, logger: logger) + let mapped = oneWalletItemsV2.reduce(into: [:]) { $0[$1.value.name] = $1.value.walletBackup } + + oneWalletItems.merge(mapped) { backup, backup2 in backup2 } let fullBackupItems: [String: FullBackup] = try Self.downloadItems(url: url, fileStorage: fileStorage, logger: logger) state = .success diff --git a/UnstoppableWallet/UnstoppableWallet/Core/Storage/AccountStorage.swift b/UnstoppableWallet/UnstoppableWallet/Core/Storage/AccountStorage.swift index a8f63fab4a..66e78e29c6 100644 --- a/UnstoppableWallet/UnstoppableWallet/Core/Storage/AccountStorage.swift +++ b/UnstoppableWallet/UnstoppableWallet/Core/Storage/AccountStorage.swift @@ -87,7 +87,8 @@ class AccountStorage { name: record.name, type: type, origin: origin, - backedUp: record.backedUp + backedUp: record.backedUp, + fileBackedUp: record.fileBackedUp ) } @@ -132,6 +133,7 @@ class AccountStorage { type: typeName.rawValue, origin: account.origin.rawValue, backedUp: account.backedUp, + fileBackedUp: account.fileBackedUp, wordsKey: wordsKey, saltKey: saltKey, dataKey: dataKey, diff --git a/UnstoppableWallet/UnstoppableWallet/Core/Storage/StorageMigrator.swift b/UnstoppableWallet/UnstoppableWallet/Core/Storage/StorageMigrator.swift index 03edb45cdd..b35bd20bdf 100644 --- a/UnstoppableWallet/UnstoppableWallet/Core/Storage/StorageMigrator.swift +++ b/UnstoppableWallet/UnstoppableWallet/Core/Storage/StorageMigrator.swift @@ -784,9 +784,10 @@ class StorageMigrator { } } - migrator.registerMigration("Add level to AccountRecord") { db in + migrator.registerMigration("Add level and fileBackedUp to AccountRecord") { db in try db.alter(table: AccountRecord.databaseTableName) { t in t.add(column: AccountRecord.Columns.level.name, .integer).defaults(to: 0) + t.add(column: AccountRecord.Columns.fileBackedUp.name, .boolean).defaults(to: false) } } diff --git a/UnstoppableWallet/UnstoppableWallet/Models/Account.swift b/UnstoppableWallet/UnstoppableWallet/Models/Account.swift index 3852a1ff9d..7c2593c3e6 100644 --- a/UnstoppableWallet/UnstoppableWallet/Models/Account.swift +++ b/UnstoppableWallet/UnstoppableWallet/Models/Account.swift @@ -7,14 +7,16 @@ class Account: Identifiable { let type: AccountType let origin: AccountOrigin var backedUp: Bool + var fileBackedUp: Bool - init(id: String, level: Int, name: String, type: AccountType, origin: AccountOrigin, backedUp: Bool) { + init(id: String, level: Int, name: String, type: AccountType, origin: AccountOrigin, backedUp: Bool, fileBackedUp: Bool) { self.id = id self.level = level self.name = name self.type = type self.origin = origin self.backedUp = backedUp + self.fileBackedUp = fileBackedUp } var watchAccount: Bool { diff --git a/UnstoppableWallet/UnstoppableWallet/Models/AccountRecord.swift b/UnstoppableWallet/UnstoppableWallet/Models/AccountRecord.swift index 87027f01b5..21420d2718 100644 --- a/UnstoppableWallet/UnstoppableWallet/Models/AccountRecord.swift +++ b/UnstoppableWallet/UnstoppableWallet/Models/AccountRecord.swift @@ -7,18 +7,20 @@ class AccountRecord: Record { let type: String let origin: String let backedUp: Bool + let fileBackedUp: Bool var wordsKey: String? var saltKey: String? var dataKey: String? var bip39Compliant: Bool? - init(id: String, level: Int, name: String, type: String, origin: String, backedUp: Bool, wordsKey: String?, saltKey: String?, dataKey: String?, bip39Compliant: Bool?) { + init(id: String, level: Int, name: String, type: String, origin: String, backedUp: Bool, fileBackedUp: Bool, wordsKey: String?, saltKey: String?, dataKey: String?, bip39Compliant: Bool?) { self.id = id self.level = level self.name = name self.type = type self.origin = origin self.backedUp = backedUp + self.fileBackedUp = fileBackedUp self.wordsKey = wordsKey self.saltKey = saltKey self.dataKey = dataKey @@ -32,7 +34,7 @@ class AccountRecord: Record { } enum Columns: String, ColumnExpression { - case id, level, name, type, origin, backedUp, wordsKey, saltKey, dataKey, bip39Compliant + case id, level, name, type, origin, backedUp, fileBackedUp, wordsKey, saltKey, dataKey, bip39Compliant } required init(row: Row) { @@ -42,6 +44,7 @@ class AccountRecord: Record { type = row[Columns.type] origin = row[Columns.origin] backedUp = row[Columns.backedUp] + fileBackedUp = row[Columns.fileBackedUp] wordsKey = row[Columns.wordsKey] saltKey = row[Columns.saltKey] dataKey = row[Columns.dataKey] @@ -57,6 +60,7 @@ class AccountRecord: Record { container[Columns.type] = type container[Columns.origin] = origin container[Columns.backedUp] = backedUp + container[Columns.fileBackedUp] = fileBackedUp container[Columns.wordsKey] = wordsKey container[Columns.saltKey] = saltKey container[Columns.dataKey] = dataKey diff --git a/UnstoppableWallet/UnstoppableWallet/Modules/Backup/ICloud/AppBackupProvider.swift b/UnstoppableWallet/UnstoppableWallet/Modules/Backup/ICloud/AppBackupProvider.swift index aecc2ef9fb..8a1d122552 100644 --- a/UnstoppableWallet/UnstoppableWallet/Modules/Backup/ICloud/AppBackupProvider.swift +++ b/UnstoppableWallet/UnstoppableWallet/Modules/Backup/ICloud/AppBackupProvider.swift @@ -89,6 +89,7 @@ extension AppBackupProvider { accountType: account.type, wallets: wallets, isManualBackedUp: account.backedUp, + isFileBackedUp: account.fileBackedUp, name: account.name, passphrase: passphrase ) @@ -171,11 +172,18 @@ extension AppBackupProvider { type: accountType, origin: .restored, backedUp: backup.walletBackup.isManualBackedUp, + fileBackedUp: backup.walletBackup.isFileBackedUp, name: backup.name ) accountManager.save(account: account) default: - let account = accountFactory.account(type: accountType, origin: .restored, backedUp: backup.walletBackup.isManualBackedUp, name: backup.name) + let account = accountFactory.account( + type: accountType, + origin: .restored, + backedUp: backup.walletBackup.isManualBackedUp, + fileBackedUp: backup.walletBackup.isFileBackedUp, + name: backup.name + ) accountManager.save(account: account) let wallets = backup.walletBackup.enabledWallets.map { @@ -262,7 +270,7 @@ extension AppBackupProvider { } extension AppBackupProvider { - static func walletBackup(accountType: AccountType, wallets: [WalletBackup.EnabledWallet], isManualBackedUp: Bool, name: String, passphrase: String) throws -> RestoreCloudModule.RestoredBackup { + static func walletBackup(accountType: AccountType, wallets: [WalletBackup.EnabledWallet], isManualBackedUp: Bool, isFileBackedUp: Bool, name: String, passphrase: String) throws -> RestoreCloudModule.RestoredBackup { let message = accountType.uniqueId(hashed: false) let crypto = try BackupCrypto.instance(data: message, passphrase: passphrase) @@ -272,6 +280,7 @@ extension AppBackupProvider { id: accountType.uniqueId().hs.hex, type: AccountType.Abstract(accountType), isManualBackedUp: isManualBackedUp, + isFileBackedUp: isFileBackedUp, version: Self.version, timestamp: Date().timeIntervalSince1970.rounded() ) diff --git a/UnstoppableWallet/UnstoppableWallet/Modules/Binance/RestoreBinance/RestoreBinanceService.swift b/UnstoppableWallet/UnstoppableWallet/Modules/Binance/RestoreBinance/RestoreBinanceService.swift index b34f8436a7..b423f55181 100644 --- a/UnstoppableWallet/UnstoppableWallet/Modules/Binance/RestoreBinance/RestoreBinanceService.swift +++ b/UnstoppableWallet/UnstoppableWallet/Modules/Binance/RestoreBinance/RestoreBinanceService.swift @@ -36,7 +36,7 @@ class RestoreBinanceService { private func createAccount() { let type: AccountType = .cex(cexAccount: .binance(apiKey: apiKey, secret: secretKey)) let name = accountFactory.nextAccountName(cex: .binance) - let account = accountFactory.account(type: type, origin: .restored, backedUp: true, name: name) + let account = accountFactory.account(type: type, origin: .restored, backedUp: true, fileBackedUp: false, name: name) accountManager.save(account: account) diff --git a/UnstoppableWallet/UnstoppableWallet/Modules/CreateAccount/CreateAccountService.swift b/UnstoppableWallet/UnstoppableWallet/Modules/CreateAccount/CreateAccountService.swift index 02a507f926..1a3e4a01ba 100644 --- a/UnstoppableWallet/UnstoppableWallet/Modules/CreateAccount/CreateAccountService.swift +++ b/UnstoppableWallet/UnstoppableWallet/Modules/CreateAccount/CreateAccountService.swift @@ -100,6 +100,7 @@ extension CreateAccountService { type: accountType, origin: .created, backedUp: false, + fileBackedUp: false, name: trimmedName.isEmpty ? defaultAccountName : trimmedName ) diff --git a/UnstoppableWallet/UnstoppableWallet/Modules/RestoreAccount/RestoreCloud/RestoreCloudModule.swift b/UnstoppableWallet/UnstoppableWallet/Modules/RestoreAccount/RestoreCloud/RestoreCloudModule.swift index c3801524d5..75217aeaa0 100644 --- a/UnstoppableWallet/UnstoppableWallet/Modules/RestoreAccount/RestoreCloud/RestoreCloudModule.swift +++ b/UnstoppableWallet/UnstoppableWallet/Modules/RestoreAccount/RestoreCloud/RestoreCloudModule.swift @@ -27,6 +27,7 @@ struct RestoreCloudModule { let name: String let accountType: AccountType let isManualBackedUp: Bool + let isFileBackedUp: Bool let showSelectCoins: Bool } diff --git a/UnstoppableWallet/UnstoppableWallet/Modules/RestoreAccount/RestoreCloud/RestoreCloudPassphrase/RestoreCloudPassphraseService.swift b/UnstoppableWallet/UnstoppableWallet/Modules/RestoreAccount/RestoreCloud/RestoreCloudPassphrase/RestoreCloudPassphraseService.swift index b29f427712..426f82e0d1 100644 --- a/UnstoppableWallet/UnstoppableWallet/Modules/RestoreAccount/RestoreCloud/RestoreCloudPassphrase/RestoreCloudPassphraseService.swift +++ b/UnstoppableWallet/UnstoppableWallet/Modules/RestoreAccount/RestoreCloud/RestoreCloudPassphrase/RestoreCloudPassphraseService.swift @@ -24,7 +24,13 @@ class RestoreCloudPassphraseService { } private func createAccount(accountType: AccountType) { - let account = accountFactory.account(type: accountType, origin: .restored, backedUp: restoredBackup.walletBackup.isManualBackedUp, name: restoredBackup.name) + let account = accountFactory.account( + type: accountType, + origin: .restored, + backedUp: restoredBackup.walletBackup.isManualBackedUp, + fileBackedUp: restoredBackup.walletBackup.isFileBackedUp, + name: restoredBackup.name + ) accountManager.save(account: account) let wallets = restoredBackup.walletBackup.enabledWallets.map { @@ -67,6 +73,7 @@ extension RestoreCloudPassphraseService { name: restoredBackup.name, accountType: accountType, isManualBackedUp: restoredBackup.walletBackup.isManualBackedUp, + isFileBackedUp: restoredBackup.walletBackup.isFileBackedUp, showSelectCoins: restoredBackup.walletBackup.enabledWallets.isEmpty )) } diff --git a/UnstoppableWallet/UnstoppableWallet/Modules/RestoreAccount/RestoreCloud/RestoreCloudPassphrase/RestoreCloudPassphraseViewController.swift b/UnstoppableWallet/UnstoppableWallet/Modules/RestoreAccount/RestoreCloud/RestoreCloudPassphrase/RestoreCloudPassphraseViewController.swift index 69c2191076..4ff179b41c 100644 --- a/UnstoppableWallet/UnstoppableWallet/Modules/RestoreAccount/RestoreCloud/RestoreCloudPassphrase/RestoreCloudPassphraseViewController.swift +++ b/UnstoppableWallet/UnstoppableWallet/Modules/RestoreAccount/RestoreCloud/RestoreCloudPassphrase/RestoreCloudPassphraseViewController.swift @@ -1,10 +1,10 @@ import Combine -import SnapKit -import ThemeKit -import UIKit import ComponentKit import SectionsTableView +import SnapKit +import ThemeKit import UIExtensions +import UIKit class RestoreCloudPassphraseViewController: KeyboardAwareViewController { private let viewModel: RestoreCloudPassphraseViewModel @@ -30,7 +30,8 @@ class RestoreCloudPassphraseViewController: KeyboardAwareViewController { super.init(scrollViews: [tableView], accessoryView: gradientWrapperView) } - required init?(coder aDecoder: NSCoder) { + @available(*, unavailable) + required init?(coder _: NSCoder) { fatalError("init(coder:) has not been implemented") } @@ -68,48 +69,53 @@ class RestoreCloudPassphraseViewController: KeyboardAwareViewController { passphraseCautionCell.onChangeHeight = { [weak self] in self?.onChangeHeight() } viewModel.$passphraseCaution - .receive(on: DispatchQueue.main) - .sink { [weak self] caution in - self?.passphraseCell.set(cautionType: caution?.type) - self?.passphraseCautionCell.set(caution: caution) - } - .store(in: &cancellables) + .receive(on: DispatchQueue.main) + .sink { [weak self] caution in + self?.passphraseCell.set(cautionType: caution?.type) + self?.passphraseCautionCell.set(caution: caution) + } + .store(in: &cancellables) viewModel.$processing - .receive(on: DispatchQueue.main) - .sink { [weak self] processing in - self?.show(processing: processing) - } - .store(in: &cancellables) + .receive(on: DispatchQueue.main) + .sink { [weak self] processing in + self?.show(processing: processing) + } + .store(in: &cancellables) viewModel.clearInputsPublisher - .receive(on: DispatchQueue.main) - .sink { [weak self] in - self?.passphraseCell.inputText = nil - } - .store(in: &cancellables) + .receive(on: DispatchQueue.main) + .sink { [weak self] in + self?.passphraseCell.inputText = nil + } + .store(in: &cancellables) viewModel.showErrorPublisher - .receive(on: DispatchQueue.main) - .sink { [weak self] in - self?.show(error: $0) - } - .store(in: &cancellables) + .receive(on: DispatchQueue.main) + .sink { [weak self] in + self?.show(error: $0) + } + .store(in: &cancellables) viewModel.openSelectCoinsPublisher - .receive(on: DispatchQueue.main) - .sink { [weak self] backupAccount in - self?.openSelectCoins(accountName: backupAccount.name, accountType: backupAccount.accountType, isManualBackedUp: backupAccount.isManualBackedUp) - } - .store(in: &cancellables) + .receive(on: DispatchQueue.main) + .sink { [weak self] backupAccount in + self?.openSelectCoins( + accountName: backupAccount.name, + accountType: backupAccount.accountType, + isManualBackedUp: backupAccount.isManualBackedUp, + isFileBackedUp: backupAccount.isFileBackedUp + ) + } + .store(in: &cancellables) viewModel.successPublisher - .receive(on: DispatchQueue.main) - .sink { [weak self] in - HudHelper.instance.show(banner: .imported) - (self?.returnViewController ?? self)?.dismiss(animated: true) - } - .store(in: &cancellables) + .receive(on: DispatchQueue.main) + .sink { [weak self] in + HudHelper.instance.show(banner: .imported) + (self?.returnViewController ?? self)?.dismiss(animated: true) + } + .store(in: &cancellables) showDefaultPassphrase() @@ -158,61 +164,58 @@ class RestoreCloudPassphraseViewController: KeyboardAwareViewController { HudHelper.instance.show(banner: .error(string: error)) } - private func openSelectCoins(accountName: String, accountType: AccountType, isManualBackedUp: Bool) { + private func openSelectCoins(accountName: String, accountType: AccountType, isManualBackedUp: Bool, isFileBackedUp: Bool) { let viewController = RestoreSelectModule.viewController( - accountName: accountName, - accountType: accountType, - isManualBackedUp: isManualBackedUp, - returnViewController: returnViewController + accountName: accountName, + accountType: accountType, + isManualBackedUp: isManualBackedUp, + isFileBackedUp: isFileBackedUp, + returnViewController: returnViewController ) navigationController?.pushViewController(viewController, animated: true) } - } extension RestoreCloudPassphraseViewController: SectionsDataSource { - func buildSections() -> [SectionProtocol] { [ Section( - id: "description-section", - headerState: .margin(height: .margin12), - footerState: .margin(height: .margin32), - rows: [ - tableView.descriptionRow( - id: "description", - text: "restore.cloud.password.description".localized, - font: .subhead2, - textColor: .gray, - ignoreBottomMargin: true - ) - ] + id: "description-section", + headerState: .margin(height: .margin12), + footerState: .margin(height: .margin32), + rows: [ + tableView.descriptionRow( + id: "description", + text: "restore.cloud.password.description".localized, + font: .subhead2, + textColor: .gray, + ignoreBottomMargin: true + ), + ] ), Section( - id: "passphrase", - footerState: .margin(height: .margin16), - rows: [ - StaticRow( - cell: passphraseCell, - id: "passphrase", - height: .heightSingleLineCell - ), - StaticRow( - cell: passphraseCautionCell, - id: "passphrase-caution", - dynamicHeight: { [weak self] width in - self?.passphraseCautionCell.height(containerWidth: width) ?? 0 - } - ) - ] + id: "passphrase", + footerState: .margin(height: .margin16), + rows: [ + StaticRow( + cell: passphraseCell, + id: "passphrase", + height: .heightSingleLineCell + ), + StaticRow( + cell: passphraseCautionCell, + id: "passphrase-caution", + dynamicHeight: { [weak self] width in + self?.passphraseCautionCell.height(containerWidth: width) ?? 0 + } + ), + ] ), ] } - } extension RestoreCloudPassphraseViewController: IDynamicHeightCellDelegate { - func onChangeHeight() { guard isLoaded else { return @@ -223,5 +226,4 @@ extension RestoreCloudPassphraseViewController: IDynamicHeightCellDelegate { self?.tableView.endUpdates() } } - } diff --git a/UnstoppableWallet/UnstoppableWallet/Modules/RestoreAccount/RestoreSelect/RestoreSelectModule.swift b/UnstoppableWallet/UnstoppableWallet/Modules/RestoreAccount/RestoreSelect/RestoreSelectModule.swift index 4152159d46..ebd220f473 100644 --- a/UnstoppableWallet/UnstoppableWallet/Modules/RestoreAccount/RestoreSelect/RestoreSelectModule.swift +++ b/UnstoppableWallet/UnstoppableWallet/Modules/RestoreAccount/RestoreSelect/RestoreSelectModule.swift @@ -4,7 +4,7 @@ import MarketKit struct RestoreSelectModule { - static func viewController(accountName: String, accountType: AccountType, isManualBackedUp: Bool = true, returnViewController: UIViewController?) -> UIViewController { + static func viewController(accountName: String, accountType: AccountType, isManualBackedUp: Bool = true, isFileBackedUp: Bool = false, returnViewController: UIViewController?) -> UIViewController { let (blockchainTokensService, blockchainTokensView) = BlockchainTokensModule.module() let (restoreSettingsService, restoreSettingsView) = RestoreSettingsModule.module() @@ -12,6 +12,7 @@ struct RestoreSelectModule { accountName: accountName, accountType: accountType, isManualBackedUp: isManualBackedUp, + isFileBackedUp: isFileBackedUp, accountFactory: App.shared.accountFactory, accountManager: App.shared.accountManager, walletManager: App.shared.walletManager, diff --git a/UnstoppableWallet/UnstoppableWallet/Modules/RestoreAccount/RestoreSelect/RestoreSelectService.swift b/UnstoppableWallet/UnstoppableWallet/Modules/RestoreAccount/RestoreSelect/RestoreSelectService.swift index df2bf20cdb..178a97e42c 100644 --- a/UnstoppableWallet/UnstoppableWallet/Modules/RestoreAccount/RestoreSelect/RestoreSelectService.swift +++ b/UnstoppableWallet/UnstoppableWallet/Modules/RestoreAccount/RestoreSelect/RestoreSelectService.swift @@ -1,12 +1,12 @@ -import RxSwift -import RxRelay import MarketKit +import RxRelay +import RxSwift class RestoreSelectService { - private let accountName: String private let accountType: AccountType private let isManualBackedUp: Bool + private let isFileBackedUp: Bool private let accountFactory: AccountFactory private let accountManager: AccountManager private let walletManager: WalletManager @@ -31,10 +31,11 @@ class RestoreSelectService { } } - init(accountName: String, accountType: AccountType, isManualBackedUp: Bool, accountFactory: AccountFactory, accountManager: AccountManager, walletManager: WalletManager, evmAccountRestoreStateManager: EvmAccountRestoreStateManager, marketKit: MarketKit.Kit, blockchainTokensService: BlockchainTokensService, restoreSettingsService: RestoreSettingsService) { + init(accountName: String, accountType: AccountType, isManualBackedUp: Bool, isFileBackedUp: Bool, accountFactory: AccountFactory, accountManager: AccountManager, walletManager: WalletManager, evmAccountRestoreStateManager: EvmAccountRestoreStateManager, marketKit: MarketKit.Kit, blockchainTokensService: BlockchainTokensService, restoreSettingsService: RestoreSettingsService) { self.accountName = accountName self.accountType = accountType self.isManualBackedUp = isManualBackedUp + self.isFileBackedUp = isFileBackedUp self.accountFactory = accountFactory self.accountManager = accountManager self.walletManager = walletManager @@ -83,9 +84,9 @@ class RestoreSelectService { let enabled = isEnabled(blockchain: blockchain) return Item( - blockchain: blockchain, - enabled: enabled, - hasSettings: enabled && hasSettings(blockchain: blockchain) + blockchain: blockchain, + enabled: enabled, + hasSettings: enabled && hasSettings(blockchain: blockchain) ) } @@ -132,11 +133,9 @@ class RestoreSelectService { cancelEnableBlockchainRelay.accept(blockchain.type) } } - } extension RestoreSelectService { - var itemsObservable: Observable<[Item]> { itemsRelay.asObservable() } @@ -192,7 +191,13 @@ extension RestoreSelectService { } func restore() { - let account = accountFactory.account(type: accountType, origin: .restored, backedUp: isManualBackedUp, name: accountName) + let account = accountFactory.account( + type: accountType, + origin: .restored, + backedUp: isManualBackedUp, + fileBackedUp: isFileBackedUp, + name: accountName + ) accountManager.save(account: account) for (token, settings) in restoreSettingsMap { @@ -210,15 +215,12 @@ extension RestoreSelectService { let wallets = enabledTokens.map { Wallet(token: $0, account: account) } walletManager.save(wallets: wallets) } - } extension RestoreSelectService { - struct Item { let blockchain: Blockchain let enabled: Bool let hasSettings: Bool } - }