Skip to content

Commit

Permalink
Add new fields for fullWallet backup
Browse files Browse the repository at this point in the history
  • Loading branch information
ant013 committed May 31, 2024
1 parent 2efa768 commit b741c5f
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 26 deletions.
4 changes: 3 additions & 1 deletion UnstoppableWallet/UnstoppableWallet/Core/App.swift
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,9 @@ class App {
balancePrimaryValueManager: balancePrimaryValueManager,
balanceConversionManager: balanceConversionManager,
balanceHiddenManager: balanceHiddenManager,
contactManager: contactManager
contactManager: contactManager,
priceChangeModeManager: priceChangeModeManager,
walletButtonHiddenManager: walletButtonHiddenManager
)
cloudBackupManager = CloudBackupManager(
ubiquityContainerIdentifier: AppConfig.sharedCloudContainer,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Chart
import Foundation
import ThemeKit

struct SettingsBackup: Codable {
class SettingsBackup: Codable {
var evmSyncSources: EvmSyncSourceManager.SyncSourceBackup
let btcModes: [BtcBlockchainManager.BtcRestoreModeBackup]

Expand All @@ -15,8 +15,10 @@ struct SettingsBackup: Codable {

let mode: ThemeMode
let showMarketTab: Bool
let priceChangeMode: PriceChangeMode
let launchScreen: LaunchScreen
let conversionTokenQueryId: String?
let balanceHideButtons: Bool
let balancePrimaryValue: BalancePrimaryValue
let balanceAutoHide: Bool
let appIcon: String
Expand All @@ -32,12 +34,73 @@ struct SettingsBackup: Codable {
case baseCurrency = "currency"
case mode = "theme_mode"
case showMarketTab = "show_market"
case priceChangeMode = "price_change_mode"
case launchScreen = "launch_screen"
case conversionTokenQueryId = "conversion_token_query_id"
case balanceHideButtons = "balance_hide_buttons"
case balancePrimaryValue = "balance_primary_value"
case balanceAutoHide = "balance_auto_hide"
case appIcon = "app_icon"
}

init(
evmSyncSources: EvmSyncSourceManager.SyncSourceBackup,
btcModes: [BtcBlockchainManager.BtcRestoreModeBackup],
remoteContactsSync: Bool?,
swapProviders: [DefaultProvider],
chartIndicators: ChartIndicatorsRepository.BackupIndicators,
indicatorsShown: Bool,
currentLanguage: String,
baseCurrency: String,
mode: ThemeMode,
showMarketTab: Bool,
priceChangeMode: PriceChangeMode,
launchScreen: LaunchScreen,
conversionTokenQueryId: String?,
balanceHideButtons: Bool,
balancePrimaryValue: BalancePrimaryValue,
balanceAutoHide: Bool,
appIcon: String) {
self.evmSyncSources = evmSyncSources
self.btcModes = btcModes
self.remoteContactsSync = remoteContactsSync
self.swapProviders = swapProviders
self.chartIndicators = chartIndicators
self.indicatorsShown = indicatorsShown
self.currentLanguage = currentLanguage
self.baseCurrency = baseCurrency
self.mode = mode
self.showMarketTab = showMarketTab
self.priceChangeMode = priceChangeMode
self.launchScreen = launchScreen
self.conversionTokenQueryId = conversionTokenQueryId
self.balanceHideButtons = balanceHideButtons
self.balancePrimaryValue = balancePrimaryValue
self.balanceAutoHide = balanceAutoHide
self.appIcon = appIcon
}

required init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
evmSyncSources = try container.decode(EvmSyncSourceManager.SyncSourceBackup.self, forKey: .evmSyncSources)
btcModes = try container.decode([BtcBlockchainManager.BtcRestoreModeBackup].self, forKey: .btcModes)
remoteContactsSync = try? container.decode(Bool.self, forKey: .remoteContactsSync)
swapProviders = try container.decode([DefaultProvider].self, forKey: .swapProviders)
chartIndicators = try container.decode(ChartIndicatorsRepository.BackupIndicators.self, forKey: .chartIndicators)
indicatorsShown = try container.decode(Bool.self, forKey: .indicatorsShown)
currentLanguage = try container.decode(String.self, forKey: .currentLanguage)
baseCurrency = try container.decode(String.self, forKey: .baseCurrency)
mode = try container.decode(ThemeMode.self, forKey: .mode)
showMarketTab = try container.decode(Bool.self, forKey: .showMarketTab)
priceChangeMode = (try? container.decode(PriceChangeMode.self, forKey: .priceChangeMode)) ?? .hour24
launchScreen = try container.decode(LaunchScreen.self, forKey: .launchScreen)
conversionTokenQueryId = try container.decode(String?.self, forKey: .conversionTokenQueryId)
balanceHideButtons = (try? container.decode(Bool.self, forKey: .balanceHideButtons)) ?? false
balancePrimaryValue = try container.decode(BalancePrimaryValue.self, forKey: .balancePrimaryValue)
balanceAutoHide = try container.decode(Bool.self, forKey: .balanceAutoHide)
appIcon = try container.decode(String.self, forKey: .appIcon)
}

}

extension SettingsBackup {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
enum PriceChangeMode: String, CaseIterable, Codable {
case hour24
case midnightUtc
case hour24 = "hour_24"
case midnightUtc = "midnight_utc"
}

extension PriceChangeMode {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ class AppBackupProvider {
private let balanceConversionManager: BalanceConversionManager
private let balanceHiddenManager: BalanceHiddenManager
private let contactManager: ContactBookManager
private let priceChangeModeManager: PriceChangeModeManager
private let walletButtonHiddenManager: WalletButtonHiddenManager

init(accountManager: AccountManager,
accountFactory: AccountFactory,
Expand All @@ -41,7 +43,9 @@ class AppBackupProvider {
balancePrimaryValueManager: BalancePrimaryValueManager,
balanceConversionManager: BalanceConversionManager,
balanceHiddenManager: BalanceHiddenManager,
contactManager: ContactBookManager)
contactManager: ContactBookManager,
priceChangeModeManager: PriceChangeModeManager,
walletButtonHiddenManager: WalletButtonHiddenManager)
{
self.accountManager = accountManager
self.accountFactory = accountFactory
Expand All @@ -61,6 +65,8 @@ class AppBackupProvider {
self.balanceConversionManager = balanceConversionManager
self.balanceHiddenManager = balanceHiddenManager
self.contactManager = contactManager
self.priceChangeModeManager = priceChangeModeManager
self.walletButtonHiddenManager = walletButtonHiddenManager
}

// Parts of backups
Expand Down Expand Up @@ -98,8 +104,10 @@ class AppBackupProvider {
baseCurrency: currencyManager.baseCurrency.code,
mode: themeManager.themeMode,
showMarketTab: launchScreenManager.showMarket,
priceChangeMode: priceChangeModeManager.priceChangeMode,
launchScreen: launchScreenManager.launchScreen,
conversionTokenQueryId: balanceConversionManager.conversionToken?.tokenQuery.id,
balanceHideButtons: walletButtonHiddenManager.buttonHidden,
balancePrimaryValue: balancePrimaryValueManager.balancePrimaryValue,
balanceAutoHide: balanceHiddenManager.balanceAutoHide,
appIcon: appIconManager.appIcon.title
Expand Down Expand Up @@ -204,8 +212,10 @@ extension AppBackupProvider {
themeManager.themeMode = raw.settings.mode
launchScreenManager.showMarket = raw.settings.showMarketTab
launchScreenManager.launchScreen = raw.settings.launchScreen
priceChangeModeManager.priceChangeMode = raw.settings.priceChangeMode
balancePrimaryValueManager.balancePrimaryValue = raw.settings.balancePrimaryValue

walletButtonHiddenManager.buttonHidden = raw.settings.balanceHideButtons
balanceConversionManager.set(tokenQueryId: raw.settings.conversionTokenQueryId)
balanceHiddenManager.set(balanceAutoHide: raw.settings.balanceAutoHide)
let appIcon = AppIconManager.allAppIcons.first { $0.title == raw.settings.appIcon } ?? .main
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class MainSettingsViewController: ThemeViewController {
manageAccountsCell.set(backgroundStyle: .lawrence, isFirst: true)
syncManageAccountCell()

walletConnectCell.set(backgroundStyle: .lawrence, isLast: true)
walletConnectCell.set(backgroundStyle: .lawrence)
syncWalletConnectCell()

securityCell.set(backgroundStyle: .lawrence, isFirst: true)
Expand Down Expand Up @@ -244,6 +244,20 @@ class MainSettingsViewController: ThemeViewController {
self?.viewModel.onTapWalletConnect()
}
),
tableView.universalRow48(
id: "backup-manager",
image: .local(UIImage(named: "icloud_24")),
title: .body("settings.backup_manager".localized),
accessoryType: .disclosure,
isFirst: false,
isLast: true,
action: { [weak self] in
let viewController = BackupManagerModule.viewController()
self?.navigationController?.pushViewController(viewController, animated: true)

stat(page: .settings, event: .open(page: .backupManager))
}
)
]
}

Expand Down Expand Up @@ -337,25 +351,6 @@ class MainSettingsViewController: ThemeViewController {
]
}

private var backupRows: [RowProtocol] {
[
tableView.universalRow48(
id: "backup-manager",
image: .local(UIImage(named: "icloud_24")),
title: .body("settings.backup_manager".localized),
accessoryType: .disclosure,
isFirst: true,
isLast: true,
action: { [weak self] in
let viewController = BackupManagerModule.viewController()
self?.navigationController?.pushViewController(viewController, animated: true)

stat(page: .settings, event: .open(page: .backupManager))
}
),
]
}

private var socialRows: [RowProtocol] {
[
tableView.universalRow48(
Expand Down Expand Up @@ -542,7 +537,6 @@ extension MainSettingsViewController: SectionsDataSource {
rows: socialRows
),
Section(id: "knowledge", headerState: .margin(height: .margin32), rows: knowledgeRows),
Section(id: "backup", headerState: .margin(height: .margin32), rows: backupRows),
Section(id: "about", headerState: .margin(height: .margin32), rows: aboutRows),
Section(id: "footer", headerState: .margin(height: .margin32), footerState: .margin(height: .margin32), rows: footerRows),
]
Expand Down

0 comments on commit b741c5f

Please sign in to comment.