From c235df89353ba0cdc8f1222ebb64f8c73bee6b85 Mon Sep 17 00:00:00 2001 From: OmarHatem Date: Wed, 7 Dec 2022 16:41:04 +0200 Subject: [PATCH] - Fix reloading settings store - Revert changes to backup_service.dart --- lib/core/backup_service.dart | 6 +- lib/di.dart | 4 +- lib/store/settings_store.dart | 77 ++++++++----------- .../restore_from_backup_view_model.dart | 5 +- 4 files changed, 35 insertions(+), 57 deletions(-) diff --git a/lib/core/backup_service.dart b/lib/core/backup_service.dart index 780185a6..999b6712 100644 --- a/lib/core/backup_service.dart +++ b/lib/core/backup_service.dart @@ -1,7 +1,6 @@ import 'dart:convert'; import 'dart:io'; import 'dart:typed_data'; -import 'package:cake_wallet/store/settings_store.dart'; import 'package:cw_core/wallet_type.dart'; import 'package:flutter/foundation.dart'; import 'package:hive/hive.dart'; @@ -21,7 +20,7 @@ import 'package:cake_backup/backup.dart' as cake_backup; class BackupService { BackupService(this._flutterSecureStorage, this._walletInfoSource, - this._keyService, this._sharedPreferences, this._settingsStore) + this._keyService, this._sharedPreferences) : _cipher = Cryptography.instance.chacha20Poly1305Aead(), _correctWallets = []; @@ -34,7 +33,6 @@ class BackupService { final FlutterSecureStorage _flutterSecureStorage; final SharedPreferences _sharedPreferences; final Box _walletInfoSource; - final SettingsStore _settingsStore; final KeyService _keyService; List _correctWallets; @@ -303,7 +301,6 @@ class BackupService { as Map; final keychainWalletsInfo = keychainJSON['wallets'] as List; final decodedPin = keychainJSON['pin'] as String; - _settingsStore.pinCodeLength = decodedPin.length; final pinCodeKey = generateStoreKeyFor(key: SecretStoreKey.pinCodePassword); final backupPasswordKey = generateStoreKeyFor(key: SecretStoreKey.backupPassword); @@ -334,7 +331,6 @@ class BackupService { final keychainWalletsInfo = keychainJSON['wallets'] as List; final decodedPin = keychainJSON['pin'] as String; final pinCodeKey = generateStoreKeyFor(key: SecretStoreKey.pinCodePassword); - _settingsStore.pinCodeLength = decodedPin.length; final backupPasswordKey = generateStoreKeyFor(key: SecretStoreKey.backupPassword); final backupPassword = keychainJSON[backupPasswordKey] as String; diff --git a/lib/di.dart b/lib/di.dart index 2a07919d..c62dc979 100644 --- a/lib/di.dart +++ b/lib/di.dart @@ -606,9 +606,7 @@ Future setup( getIt.get(), _walletInfoSource, getIt.get(), - getIt.get(), - getIt.get(), - )); + getIt.get())); getIt.registerFactory(() => BackupViewModel(getIt.get(), getIt.get(), getIt.get())); diff --git a/lib/store/settings_store.dart b/lib/store/settings_store.dart index 534ea67e..9fc082ec 100644 --- a/lib/store/settings_store.dart +++ b/lib/store/settings_store.dart @@ -3,7 +3,6 @@ import 'package:cake_wallet/entities/preferences_key.dart'; import 'package:cw_core/transaction_priority.dart'; import 'package:cake_wallet/themes/theme_base.dart'; import 'package:cake_wallet/themes/theme_list.dart'; -import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:hive/hive.dart'; import 'package:mobx/mobx.dart'; @@ -234,8 +233,7 @@ abstract class SettingsStoreBase with Store { : ThemeType.bright.index; final savedTheme = ThemeList.deserialize( raw: sharedPreferences.getInt(PreferencesKey.currentTheme) ?? - legacyTheme ?? - 0); + legacyTheme); final actionListDisplayMode = ObservableList(); actionListDisplayMode.addAll(deserializeActionlistDisplayModes( sharedPreferences.getInt(PreferencesKey.displayActionListModeKey) ?? @@ -281,7 +279,7 @@ abstract class SettingsStoreBase with Store { if (havenNode != null) { nodes[WalletType.haven] = havenNode; } - + return SettingsStore( sharedPreferences: sharedPreferences, nodes: nodes, @@ -301,48 +299,35 @@ abstract class SettingsStoreBase with Store { shouldShowYatPopup: shouldShowYatPopup); } - // FIX-ME: Dead code - - //Future reload( - // {required Box nodeSource, - // FiatCurrency initialFiatCurrency = FiatCurrency.usd, - // TransactionPriority? initialMoneroTransactionPriority, - // TransactionPriority? initialBitcoinTransactionPriority, - // BalanceDisplayMode initialBalanceDisplayMode = - // BalanceDisplayMode.availableBalance}) async { - - // if (initialBitcoinTransactionPriority == null) { - // initialBitcoinTransactionPriority = bitcoin?.getMediumTransactionPriority(); - // } - - // if (initialMoneroTransactionPriority == null) { - // initialMoneroTransactionPriority = monero?.getDefaultTransactionPriority(); - // } - - // final isBitcoinBuyEnabled = (secrets.wyreSecretKey?.isNotEmpty ?? false) && - // (secrets.wyreApiKey?.isNotEmpty ?? false) && - // (secrets.wyreAccountId?.isNotEmpty ?? false); - - // final settings = await SettingsStoreBase.load( - // nodeSource: nodeSource, - // isBitcoinBuyEnabled: isBitcoinBuyEnabled, - // initialBalanceDisplayMode: initialBalanceDisplayMode, - // initialFiatCurrency: initialFiatCurrency, - // initialMoneroTransactionPriority: initialMoneroTransactionPriority, - // initialBitcoinTransactionPriority: initialBitcoinTransactionPriority); - // fiatCurrency = settings.fiatCurrency; - // actionlistDisplayMode = settings.actionlistDisplayMode; - // priority[WalletType.monero] = initialMoneroTransactionPriority; - // priority[WalletType.bitcoin] = initialBitcoinTransactionPriority; - // balanceDisplayMode = settings.balanceDisplayMode; - // shouldSaveRecipientAddress = settings.shouldSaveRecipientAddress; - // allowBiometricalAuthentication = settings.allowBiometricalAuthentication; - // currentTheme = settings.currentTheme; - // pinCodeLength = settings.pinCodeLength; - // languageCode = settings.languageCode; - // appVersion = settings.appVersion; - // shouldShowYatPopup = settings.shouldShowYatPopup; - //} + Future reload( + {required Box nodeSource, + FiatCurrency initialFiatCurrency = FiatCurrency.usd, + TransactionPriority? initialMoneroTransactionPriority, + TransactionPriority? initialBitcoinTransactionPriority, + BalanceDisplayMode initialBalanceDisplayMode = BalanceDisplayMode.availableBalance}) async { + if (initialBitcoinTransactionPriority == null) { + initialBitcoinTransactionPriority = bitcoin?.getMediumTransactionPriority(); + } + + if (initialMoneroTransactionPriority == null) { + initialMoneroTransactionPriority = monero?.getDefaultTransactionPriority(); + } + + final isBitcoinBuyEnabled = (secrets.wyreSecretKey.isNotEmpty) && + (secrets.wyreApiKey.isNotEmpty) && + (secrets.wyreAccountId.isNotEmpty); + + final settings = await SettingsStoreBase.load( + nodeSource: nodeSource, + isBitcoinBuyEnabled: isBitcoinBuyEnabled, + initialBalanceDisplayMode: initialBalanceDisplayMode, + initialFiatCurrency: initialFiatCurrency, + initialMoneroTransactionPriority: initialMoneroTransactionPriority, + initialBitcoinTransactionPriority: initialBitcoinTransactionPriority); + + getIt.unregister(); + getIt.registerSingleton(settings); + } Future _saveCurrentNode(Node node, WalletType walletType) async { switch (walletType) { diff --git a/lib/view_model/restore_from_backup_view_model.dart b/lib/view_model/restore_from_backup_view_model.dart index d3542a66..403ae3ff 100644 --- a/lib/view_model/restore_from_backup_view_model.dart +++ b/lib/view_model/restore_from_backup_view_model.dart @@ -35,7 +35,7 @@ abstract class RestoreFromBackupViewModelBase with Store { try { state = IsExecutingState(); - if (filePath?.isEmpty ?? true) { + if (filePath.isEmpty) { state = FailureState('Backup file is not selected.'); return; } @@ -48,8 +48,7 @@ abstract class RestoreFromBackupViewModelBase with Store { final store = getIt.get(); ReactionDisposer? reaction; - // FIX-ME: SettingsStore reload - // await store.settingsStore.reload(nodeSource: getIt.get>()); + await store.settingsStore.reload(nodeSource: getIt.get>()); reaction = autorun((_) { final wallet = store.wallet;