Skip to content
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

Implement Backup App Settings module #5293

Merged
merged 1 commit into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
140 changes: 140 additions & 0 deletions UnstoppableWallet/UnstoppableWallet.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "[email protected]",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "[email protected]",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -168,16 +168,29 @@ extension CloudBackupManager {
}
}

func save(fields: [AppBackupProvider.Field], passphrase: String, name: String) throws {
private func data(fields: [AppBackupProvider.Field], passphrase: String) throws -> Data {
let backup = try appBackupProvider.fullBackup(
fields: fields,
passphrase: passphrase
)
return try JSONEncoder().encode(backup)
}

func file(fields: [AppBackupProvider.Field], passphrase: String, name: String) throws -> URL {
let data = try data(fields: fields, passphrase: passphrase)

// save book to temporary file
guard let temporaryFileUrl = ContactBookManager.localUrl?.appendingPathComponent(name + ".json") else {
throw FileStorage.StorageError.cantCreateFile
}

try data.write(to: temporaryFileUrl)
return temporaryFileUrl
}

func save(fields: [AppBackupProvider.Field], passphrase: String, name: String) throws {
do {
let encoder = JSONEncoder()
let data = try encoder.encode(backup)
let encoded = try JSONEncoder().encode(backup)
let encoded = try data(fields: fields, passphrase: passphrase)
try save(encoded: encoded, name: name)
} catch {
logger?.log(level: .debug, message: "CloudAccountManager.downloadItems, can't save \(name). Because: \(error)")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,11 +189,17 @@ extension EvmSyncSourceManager {
}
}

func customSyncSources(blockchainType: BlockchainType) -> [EvmSyncSource] {
func customSyncSources(blockchainType: BlockchainType?) -> [EvmSyncSource] {
do {
let records = try evmSyncSourceStorage.records(blockchainTypeUid: blockchainType.uid)
let records: [EvmSyncSourceRecord]
if let blockchainType {
records = try evmSyncSourceStorage.records(blockchainTypeUid: blockchainType.uid)
} else {
records = try evmSyncSourceStorage.getAll()
}

return records.compactMap { record in
let blockchainType = BlockchainType(uid: record.blockchainTypeUid)
guard let url = URL(string: record.url), let scheme = url.scheme else {
return nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,11 @@ extension BackupCloudPassphraseViewModel {
} catch {
switch error {
case BackupCrypto.ValidationError.emptyPassphrase:
passphraseCaution = Caution(text: "backup.cloud.password.error.empty_passphrase".localized, type: .error)
passphraseCaution = Caution(text: error.localizedDescription, type: .error)
case BackupCrypto.ValidationError.simplePassword:
passphraseCaution = Caution(text: "backup.cloud.password.error.minimum_requirement".localized, type: .error)
passphraseCaution = Caution(text: error.localizedDescription, type: .error)
case BackupCloudPassphraseService.CreateError.invalidConfirmation:
passphraseConfirmationCaution = Caution(text: "backup.cloud.password.confirm.error.doesnt_match".localized, type: .error)
case BackupCloudPassphraseService.CreateError.urlNotAvailable:
showErrorSubject.send("backup.cloud.not_available".localized)
case BackupCloudPassphraseService.CreateError.cantSaveFile:
showErrorSubject.send("backup.cloud.cant_create_file".localized)
default:
showErrorSubject.send(error.smartDescription)
}
Expand All @@ -100,3 +96,32 @@ extension BackupCloudPassphraseViewModel {
}

}

extension BackupCrypto.ValidationError: LocalizedError {
public var errorDescription: String? {
switch self {
case .emptyPassphrase: return "backup.cloud.password.error.empty_passphrase".localized
case .simplePassword: return "backup.cloud.password.error.minimum_requirement".localized
}
}
}

extension BackupCloudPassphraseService.CreateError: LocalizedError {
public var errorDescription: String? {
switch self {
case .urlNotAvailable: return "backup.cloud.not_available".localized
case .cantSaveFile: return "backup.cloud.cant_create_file".localized
case .invalidConfirmation: return "invalid confirmation".localized
}
}
}

extension CloudBackupManager.BackupError: LocalizedError {
public var errorDescription: String? {
switch self {
case .urlNotAvailable: return "backup.cloud.not_available".localized
case .itemNotFound: return nil
}
}
}

Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import UIKit
import SwiftUI
import ThemeKit
import ComponentKit
import SectionsTableView
Expand Down Expand Up @@ -146,3 +147,20 @@ extension BottomSheetModule {
}

}

struct ViewWrapper: UIViewControllerRepresentable {
typealias UIViewControllerType = UIViewController

let viewController: UIViewController

init(_ viewController: UIViewController) {
self.viewController = viewController
}

func makeUIViewController(context _: Context) -> UIViewController {
viewController
}

func updateUIViewController(_: UIViewController, context _: Context) {}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import SwiftUI

struct BackupAppModule {
static func view(backupPresented: Binding<Bool>) -> some View {
let viewModel = BackupAppViewModel(
accountManager: App.shared.accountManager,
contactManager: App.shared.contactManager,
cloudBackupManager: App.shared.cloudBackupManager,
favoritesManager: App.shared.favoritesManager,
evmSyncSourceManager: App.shared.evmSyncSourceManager
)

return BackupTypeView(viewModel: viewModel, backupPresented: backupPresented)
}
}

extension BackupAppModule {
enum Destination: String, CaseIterable, Identifiable {
case cloud
case local

var id: Self {
self
}

var backupDisclaimer: BackupDestinationDisclaimer {
switch self {
case .cloud:
return BackupDestinationDisclaimer(
title: "backup.disclaimer.cloud.title".localized,
highlightedDescription: "backup.disclaimer.cloud.description".localized,
selectedCheckboxText: "backup.disclaimer.cloud.checkbox_label".localized,
buttonTitle: "button.next".localized
)
case .local:
return BackupDestinationDisclaimer(
title: "backup.disclaimer.file.title".localized,
highlightedDescription: "backup.disclaimer.file.description".localized,
selectedCheckboxText: "backup.disclaimer.file.checkbox_label".localized,
buttonTitle: "button.next".localized
)
}
}
}

struct BackupDestinationDisclaimer {
let title: String
let highlightedDescription: String
let selectedCheckboxText: String
let buttonTitle: String
}
}
Loading