mirror of
https://github.com/Such-Software/hash-wallet.git
synced 2026-10-17 05:41:29 +02:00
Remove SecretStore class for Backup viewmodels (fix for backup password not restoring) (#2723)
* backup page viewmodels without secretstore class * minor reaction optimization * minor reaction optimization
This commit is contained in:
+6
-8
@@ -224,7 +224,6 @@ import 'package:cake_wallet/store/dashboard/trade_filter_store.dart';
|
||||
import 'package:cake_wallet/store/dashboard/trades_store.dart';
|
||||
import 'package:cake_wallet/store/dashboard/transaction_filter_store.dart';
|
||||
import 'package:cake_wallet/store/node_list_store.dart';
|
||||
import 'package:cake_wallet/store/secret_store.dart';
|
||||
import 'package:cake_wallet/store/seed_settings_store.dart';
|
||||
import 'package:cake_wallet/store/settings_store.dart';
|
||||
import 'package:cake_wallet/store/templates/exchange_template_store.dart';
|
||||
@@ -417,9 +416,6 @@ Future<void> setup({
|
||||
appName: "Cake Wallet"));
|
||||
getIt.registerLazySingleton(() => TrezorViewModel(getIt<TrezorConnect>()));
|
||||
|
||||
final secretStore = await SecretStoreBase.load(getIt.get<SecureStorage>());
|
||||
|
||||
getIt.registerSingleton<SecretStore>(secretStore);
|
||||
|
||||
getIt.registerFactory<KeyService>(() => KeyService(getIt.get<SecureStorage>()));
|
||||
|
||||
@@ -1354,13 +1350,15 @@ Future<void> setup({
|
||||
_transactionDescriptionBox,
|
||||
getIt.get<KeyService>(), getIt.get<SharedPreferences>()));
|
||||
|
||||
getIt.registerFactory(() => BackupViewModel(
|
||||
getIt.get<SecureStorage>(), getIt.get<SecretStore>(), getIt.get<BackupServiceV3>()));
|
||||
|
||||
getIt.registerFactory(() => BackupPage(getIt.get<BackupViewModel>()));
|
||||
|
||||
getIt.registerFactory(
|
||||
() => EditBackupPasswordViewModel(getIt.get<SecureStorage>(), getIt.get<SecretStore>()));
|
||||
getIt.registerSingleton<EditBackupPasswordViewModel>(
|
||||
EditBackupPasswordViewModel(getIt.get<SecureStorage>()),
|
||||
);
|
||||
|
||||
getIt.registerFactory(() => BackupViewModel(
|
||||
getIt.get<SecureStorage>(),getIt.get<BackupServiceV3>(), getIt.get<EditBackupPasswordViewModel>()));
|
||||
|
||||
getIt.registerFactory(() => EditBackupPasswordPage(getIt.get<EditBackupPasswordViewModel>()));
|
||||
|
||||
|
||||
@@ -105,6 +105,7 @@ class BackupPage extends BasePage {
|
||||
}
|
||||
|
||||
void onExportBackup(BuildContext context) {
|
||||
if(backupViewModelBase.backupPassword.isEmpty) return;
|
||||
showPopUp<void>(
|
||||
context: context,
|
||||
builder: (dialogContext) {
|
||||
|
||||
@@ -7,6 +7,7 @@ import 'package:cake_wallet/src/screens/base_page.dart';
|
||||
import 'package:cake_wallet/src/widgets/alert_with_two_actions.dart';
|
||||
import 'package:cake_wallet/src/widgets/primary_button.dart';
|
||||
import 'package:cake_wallet/view_model/edit_backup_password_view_model.dart';
|
||||
import 'package:mobx/mobx.dart';
|
||||
|
||||
class EditBackupPasswordPage extends BasePage {
|
||||
EditBackupPasswordPage(this.editBackupPasswordViewModel)
|
||||
@@ -14,6 +15,12 @@ class EditBackupPasswordPage extends BasePage {
|
||||
textEditingController.text = editBackupPasswordViewModel.backupPassword;
|
||||
textEditingController
|
||||
.addListener(() => editBackupPasswordViewModel.backupPassword = textEditingController.text);
|
||||
|
||||
reaction((_) => editBackupPasswordViewModel.backupPassword, (_) {
|
||||
if (textEditingController.text != editBackupPasswordViewModel.backupPassword) {
|
||||
textEditingController.text = editBackupPasswordViewModel.backupPassword;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
final EditBackupPasswordViewModel editBackupPasswordViewModel;
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
import 'package:cake_wallet/core/secure_storage.dart';
|
||||
import 'package:cake_wallet/entities/secret_store_key.dart';
|
||||
import 'package:mobx/mobx.dart';
|
||||
|
||||
part 'secret_store.g.dart';
|
||||
|
||||
class SecretStore = SecretStoreBase with _$SecretStore;
|
||||
|
||||
abstract class SecretStoreBase with Store {
|
||||
static Future<SecretStore> load(SecureStorage storage) async {
|
||||
final secretStore = SecretStore();
|
||||
final backupPasswordKey = generateStoreKeyFor(key: SecretStoreKey.backupPassword);
|
||||
final backupPassword = await storage.read(key: backupPasswordKey);
|
||||
// FIX-ME: backupPassword ?? '' ???
|
||||
secretStore.write(key: backupPasswordKey, value: backupPassword ?? '');
|
||||
|
||||
return secretStore;
|
||||
}
|
||||
|
||||
SecretStoreBase() : values = ObservableMap<String, String>();
|
||||
|
||||
ObservableMap values;
|
||||
|
||||
String read(String key) => values[key] as String;
|
||||
|
||||
String write({required String key, required String value}) =>
|
||||
values[key] = value;
|
||||
}
|
||||
@@ -4,7 +4,7 @@ import 'package:cake_wallet/core/backup_service_v3.dart';
|
||||
import 'package:cake_wallet/core/execution_state.dart';
|
||||
import 'package:cake_wallet/core/secure_storage.dart';
|
||||
import 'package:cake_wallet/entities/secret_store_key.dart';
|
||||
import 'package:cake_wallet/store/secret_store.dart';
|
||||
import 'package:cake_wallet/view_model/edit_backup_password_view_model.dart';
|
||||
import 'package:cw_core/root_dir.dart';
|
||||
import 'package:cw_core/utils/print_verbose.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
@@ -25,21 +25,28 @@ class BackupExportFile {
|
||||
class BackupViewModel = BackupViewModelBase with _$BackupViewModel;
|
||||
|
||||
abstract class BackupViewModelBase with Store {
|
||||
BackupViewModelBase(this.secureStorage, this.secretStore, this.backupService)
|
||||
BackupViewModelBase(this.secureStorage, this.backupService, this.editBackupPasswordViewModel)
|
||||
: isBackupPasswordVisible = false,
|
||||
backupPassword = '',
|
||||
state = InitialExecutionState() {
|
||||
final key = generateStoreKeyFor(key: SecretStoreKey.backupPassword);
|
||||
secretStore.values.observe((change) {
|
||||
if (change.key == key) {
|
||||
backupPassword = secretStore.read(key);
|
||||
init();
|
||||
|
||||
reaction((_) => editBackupPasswordViewModel.backupPassword, (value) {
|
||||
if(value != backupPassword) {
|
||||
backupPassword = value;
|
||||
}
|
||||
}, fireImmediately: true);
|
||||
});
|
||||
|
||||
reaction((_)=>backupPassword, (value){
|
||||
if(value != editBackupPasswordViewModel.backupPassword) {
|
||||
editBackupPasswordViewModel.backupPassword = value;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
final SecureStorage secureStorage;
|
||||
final SecretStore secretStore;
|
||||
final BackupServiceV3 backupService;
|
||||
final EditBackupPasswordViewModel editBackupPasswordViewModel;
|
||||
|
||||
@observable
|
||||
ExecutionState state;
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import 'package:cake_wallet/core/secure_storage.dart';
|
||||
import 'package:mobx/mobx.dart';
|
||||
import 'package:cake_wallet/entities/secret_store_key.dart';
|
||||
import 'package:cake_wallet/store/secret_store.dart';
|
||||
|
||||
part 'edit_backup_password_view_model.g.dart';
|
||||
|
||||
@@ -9,12 +8,11 @@ class EditBackupPasswordViewModel = EditBackupPasswordViewModelBase
|
||||
with _$EditBackupPasswordViewModel;
|
||||
|
||||
abstract class EditBackupPasswordViewModelBase with Store {
|
||||
EditBackupPasswordViewModelBase(this.secureStorage, this.secretStore)
|
||||
: backupPassword = secretStore.read(generateStoreKeyFor(key: SecretStoreKey.backupPassword)),
|
||||
_originalPassword = '';
|
||||
EditBackupPasswordViewModelBase(this.secureStorage,)
|
||||
: backupPassword = "",
|
||||
_originalPassword = ''{init();}
|
||||
|
||||
final SecureStorage secureStorage;
|
||||
final SecretStore secretStore;
|
||||
|
||||
@observable
|
||||
String backupPassword;
|
||||
@@ -38,6 +36,5 @@ abstract class EditBackupPasswordViewModelBase with Store {
|
||||
Future<void> save() async {
|
||||
final key = generateStoreKeyFor(key: SecretStoreKey.backupPassword);
|
||||
await secureStorage.write(key: key, value: backupPassword);
|
||||
secretStore.write(key: key, value: backupPassword);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user