- Fix reloading settings store - Revert changes to backup_service.dart

- Fix reloading settings store - Revert changes to backup_service.dart

OmarHatem committed Dec 7, 2022 at 16:41 UTC c235df89353ba0cdc8f1222ebb64f8c73bee6b85
4 files changed +35 -57
lib/core/backup_service.dart
+1 -5
@@ -1,7 +1,6 @@
1 import 'dart:convert';
2 import 'dart:io';
3 import 'dart:typed_data';
4 -import 'package:cake_wallet/store/settings_store.dart';
4 import 'package:cw_core/wallet_type.dart';
5 import 'package:flutter/foundation.dart';
6 import 'package:hive/hive.dart';
@@ -21,7 +20,7 @@ import 'package:cake_backup/backup.dart' as cake_backup;
20
21 class BackupService {
22 BackupService(this._flutterSecureStorage, this._walletInfoSource,
24 - this._keyService, this._sharedPreferences, this._settingsStore)
23 + this._keyService, this._sharedPreferences)
24 : _cipher = Cryptography.instance.chacha20Poly1305Aead(),
25 _correctWallets = <WalletInfo>[];
26
@@ -34,7 +33,6 @@ class BackupService {
33 final FlutterSecureStorage _flutterSecureStorage;
34 final SharedPreferences _sharedPreferences;
35 final Box<WalletInfo> _walletInfoSource;
37 - final SettingsStore _settingsStore;
36 final KeyService _keyService;
37 List<WalletInfo> _correctWallets;
38
@@ -303,7 +301,6 @@ class BackupService {
301 as Map<String, dynamic>;
302 final keychainWalletsInfo = keychainJSON['wallets'] as List;
303 final decodedPin = keychainJSON['pin'] as String;
306 - _settingsStore.pinCodeLength = decodedPin.length;
304 final pinCodeKey = generateStoreKeyFor(key: SecretStoreKey.pinCodePassword);
305 final backupPasswordKey =
306 generateStoreKeyFor(key: SecretStoreKey.backupPassword);
@@ -334,7 +331,6 @@ class BackupService {
331 final keychainWalletsInfo = keychainJSON['wallets'] as List;
332 final decodedPin = keychainJSON['pin'] as String;
333 final pinCodeKey = generateStoreKeyFor(key: SecretStoreKey.pinCodePassword);
337 - _settingsStore.pinCodeLength = decodedPin.length;
334 final backupPasswordKey =
335 generateStoreKeyFor(key: SecretStoreKey.backupPassword);
336 final backupPassword = keychainJSON[backupPasswordKey] as String;
lib/di.dart
+1 -3
@@ -606,9 +606,7 @@ Future setup(
606 getIt.get<FlutterSecureStorage>(),
607 _walletInfoSource,
608 getIt.get<KeyService>(),
609 - getIt.get<SharedPreferences>(),
610 - getIt.get<SettingsStore>(),
611 - ));
609 + getIt.get<SharedPreferences>()));
610
611 getIt.registerFactory(() => BackupViewModel(getIt.get<FlutterSecureStorage>(),
612 getIt.get<SecretStore>(), getIt.get<BackupService>()));
lib/store/settings_store.dart
+31 -46
@@ -3,7 +3,6 @@ import 'package:cake_wallet/entities/preferences_key.dart';
3 import 'package:cw_core/transaction_priority.dart';
4 import 'package:cake_wallet/themes/theme_base.dart';
5 import 'package:cake_wallet/themes/theme_list.dart';
6 -import 'package:flutter/foundation.dart';
6 import 'package:flutter/material.dart';
7 import 'package:hive/hive.dart';
8 import 'package:mobx/mobx.dart';
@@ -234,8 +233,7 @@ abstract class SettingsStoreBase with Store {
233 : ThemeType.bright.index;
234 final savedTheme = ThemeList.deserialize(
235 raw: sharedPreferences.getInt(PreferencesKey.currentTheme) ??
237 - legacyTheme ??
238 - 0);
236 + legacyTheme);
237 final actionListDisplayMode = ObservableList<ActionListDisplayMode>();
238 actionListDisplayMode.addAll(deserializeActionlistDisplayModes(
239 sharedPreferences.getInt(PreferencesKey.displayActionListModeKey) ??
@@ -281,7 +279,7 @@ abstract class SettingsStoreBase with Store {
279 if (havenNode != null) {
280 nodes[WalletType.haven] = havenNode;
281 }
284 -
282 +
283 return SettingsStore(
284 sharedPreferences: sharedPreferences,
285 nodes: nodes,
@@ -301,48 +299,35 @@ abstract class SettingsStoreBase with Store {
299 shouldShowYatPopup: shouldShowYatPopup);
300 }
301
304 - // FIX-ME: Dead code
305 -
306 - //Future<void> reload(
307 - // {required Box<Node> nodeSource,
308 - // FiatCurrency initialFiatCurrency = FiatCurrency.usd,
309 - // TransactionPriority? initialMoneroTransactionPriority,
310 - // TransactionPriority? initialBitcoinTransactionPriority,
311 - // BalanceDisplayMode initialBalanceDisplayMode =
312 - // BalanceDisplayMode.availableBalance}) async {
313 -
314 - // if (initialBitcoinTransactionPriority == null) {
315 - // initialBitcoinTransactionPriority = bitcoin?.getMediumTransactionPriority();
316 - // }
317 -
318 - // if (initialMoneroTransactionPriority == null) {
319 - // initialMoneroTransactionPriority = monero?.getDefaultTransactionPriority();
320 - // }
321 -
322 - // final isBitcoinBuyEnabled = (secrets.wyreSecretKey?.isNotEmpty ?? false) &&
323 - // (secrets.wyreApiKey?.isNotEmpty ?? false) &&
324 - // (secrets.wyreAccountId?.isNotEmpty ?? false);
325 -
326 - // final settings = await SettingsStoreBase.load(
327 - // nodeSource: nodeSource,
328 - // isBitcoinBuyEnabled: isBitcoinBuyEnabled,
329 - // initialBalanceDisplayMode: initialBalanceDisplayMode,
330 - // initialFiatCurrency: initialFiatCurrency,
331 - // initialMoneroTransactionPriority: initialMoneroTransactionPriority,
332 - // initialBitcoinTransactionPriority: initialBitcoinTransactionPriority);
333 - // fiatCurrency = settings.fiatCurrency;
334 - // actionlistDisplayMode = settings.actionlistDisplayMode;
335 - // priority[WalletType.monero] = initialMoneroTransactionPriority;
336 - // priority[WalletType.bitcoin] = initialBitcoinTransactionPriority;
337 - // balanceDisplayMode = settings.balanceDisplayMode;
338 - // shouldSaveRecipientAddress = settings.shouldSaveRecipientAddress;
339 - // allowBiometricalAuthentication = settings.allowBiometricalAuthentication;
340 - // currentTheme = settings.currentTheme;
341 - // pinCodeLength = settings.pinCodeLength;
342 - // languageCode = settings.languageCode;
343 - // appVersion = settings.appVersion;
344 - // shouldShowYatPopup = settings.shouldShowYatPopup;
345 - //}
302 + Future<void> reload(
303 + {required Box<Node> nodeSource,
304 + FiatCurrency initialFiatCurrency = FiatCurrency.usd,
305 + TransactionPriority? initialMoneroTransactionPriority,
306 + TransactionPriority? initialBitcoinTransactionPriority,
307 + BalanceDisplayMode initialBalanceDisplayMode = BalanceDisplayMode.availableBalance}) async {
308 + if (initialBitcoinTransactionPriority == null) {
309 + initialBitcoinTransactionPriority = bitcoin?.getMediumTransactionPriority();
310 + }
311 +
312 + if (initialMoneroTransactionPriority == null) {
313 + initialMoneroTransactionPriority = monero?.getDefaultTransactionPriority();
314 + }
315 +
316 + final isBitcoinBuyEnabled = (secrets.wyreSecretKey.isNotEmpty) &&
317 + (secrets.wyreApiKey.isNotEmpty) &&
318 + (secrets.wyreAccountId.isNotEmpty);
319 +
320 + final settings = await SettingsStoreBase.load(
321 + nodeSource: nodeSource,
322 + isBitcoinBuyEnabled: isBitcoinBuyEnabled,
323 + initialBalanceDisplayMode: initialBalanceDisplayMode,
324 + initialFiatCurrency: initialFiatCurrency,
325 + initialMoneroTransactionPriority: initialMoneroTransactionPriority,
326 + initialBitcoinTransactionPriority: initialBitcoinTransactionPriority);
327 +
328 + getIt.unregister<SettingsStore>();
329 + getIt.registerSingleton<SettingsStore>(settings);
330 + }
331
332 Future<void> _saveCurrentNode(Node node, WalletType walletType) async {
333 switch (walletType) {
lib/view_model/restore_from_backup_view_model.dart
+2 -3
@@ -35,7 +35,7 @@ abstract class RestoreFromBackupViewModelBase with Store {
35 try {
36 state = IsExecutingState();
37
38 - if (filePath?.isEmpty ?? true) {
38 + if (filePath.isEmpty) {
39 state = FailureState('Backup file is not selected.');
40 return;
41 }
@@ -48,8 +48,7 @@ abstract class RestoreFromBackupViewModelBase with Store {
48
49 final store = getIt.get<AppStore>();
50 ReactionDisposer? reaction;
51 - // FIX-ME: SettingsStore reload
52 - // await store.settingsStore.reload(nodeSource: getIt.get<Box<Node>>());
51 + await store.settingsStore.reload(nodeSource: getIt.get<Box<Node>>());
52
53 reaction = autorun((_) {
54 final wallet = store.wallet;