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

malik1004x committed Dec 11, 2025 at 23:23 UTC 7464ead41c52046f25b803fba8b920209be728c2
6 files changed +32 -50
lib/di.dart
+6 -8
@@ -224,7 +224,6 @@ import 'package:cake_wallet/store/dashboard/trade_filter_store.dart';
224 import 'package:cake_wallet/store/dashboard/trades_store.dart';
225 import 'package:cake_wallet/store/dashboard/transaction_filter_store.dart';
226 import 'package:cake_wallet/store/node_list_store.dart';
227 -import 'package:cake_wallet/store/secret_store.dart';
227 import 'package:cake_wallet/store/seed_settings_store.dart';
228 import 'package:cake_wallet/store/settings_store.dart';
229 import 'package:cake_wallet/store/templates/exchange_template_store.dart';
@@ -417,9 +416,6 @@ Future<void> setup({
416 appName: "Cake Wallet"));
417 getIt.registerLazySingleton(() => TrezorViewModel(getIt<TrezorConnect>()));
418
420 - final secretStore = await SecretStoreBase.load(getIt.get<SecureStorage>());
421 -
422 - getIt.registerSingleton<SecretStore>(secretStore);
419
420 getIt.registerFactory<KeyService>(() => KeyService(getIt.get<SecureStorage>()));
421
@@ -1354,13 +1350,15 @@ Future<void> setup({
1350 _transactionDescriptionBox,
1351 getIt.get<KeyService>(), getIt.get<SharedPreferences>()));
1352
1357 - getIt.registerFactory(() => BackupViewModel(
1358 - getIt.get<SecureStorage>(), getIt.get<SecretStore>(), getIt.get<BackupServiceV3>()));
1353
1354 getIt.registerFactory(() => BackupPage(getIt.get<BackupViewModel>()));
1355
1362 - getIt.registerFactory(
1363 - () => EditBackupPasswordViewModel(getIt.get<SecureStorage>(), getIt.get<SecretStore>()));
1356 + getIt.registerSingleton<EditBackupPasswordViewModel>(
1357 + EditBackupPasswordViewModel(getIt.get<SecureStorage>()),
1358 + );
1359 +
1360 + getIt.registerFactory(() => BackupViewModel(
1361 + getIt.get<SecureStorage>(),getIt.get<BackupServiceV3>(), getIt.get<EditBackupPasswordViewModel>()));
1362
1363 getIt.registerFactory(() => EditBackupPasswordPage(getIt.get<EditBackupPasswordViewModel>()));
1364
lib/src/screens/backup/backup_page.dart
+1
@@ -105,6 +105,7 @@ class BackupPage extends BasePage {
105 }
106
107 void onExportBackup(BuildContext context) {
108 + if(backupViewModelBase.backupPassword.isEmpty) return;
109 showPopUp<void>(
110 context: context,
111 builder: (dialogContext) {
lib/src/screens/backup/edit_backup_password_page.dart
+7
@@ -7,6 +7,7 @@ import 'package:cake_wallet/src/screens/base_page.dart';
7 import 'package:cake_wallet/src/widgets/alert_with_two_actions.dart';
8 import 'package:cake_wallet/src/widgets/primary_button.dart';
9 import 'package:cake_wallet/view_model/edit_backup_password_view_model.dart';
10 +import 'package:mobx/mobx.dart';
11
12 class EditBackupPasswordPage extends BasePage {
13 EditBackupPasswordPage(this.editBackupPasswordViewModel)
@@ -14,6 +15,12 @@ class EditBackupPasswordPage extends BasePage {
15 textEditingController.text = editBackupPasswordViewModel.backupPassword;
16 textEditingController
17 .addListener(() => editBackupPasswordViewModel.backupPassword = textEditingController.text);
18 +
19 + reaction((_) => editBackupPasswordViewModel.backupPassword, (_) {
20 + if (textEditingController.text != editBackupPasswordViewModel.backupPassword) {
21 + textEditingController.text = editBackupPasswordViewModel.backupPassword;
22 + }
23 + });
24 }
25
26 final EditBackupPasswordViewModel editBackupPasswordViewModel;
lib/store/secret_store.dart deleted
-28
@@ -1,28 +0,0 @@
1 -import 'package:cake_wallet/core/secure_storage.dart';
2 -import 'package:cake_wallet/entities/secret_store_key.dart';
3 -import 'package:mobx/mobx.dart';
4 -
5 -part 'secret_store.g.dart';
6 -
7 -class SecretStore = SecretStoreBase with _$SecretStore;
8 -
9 -abstract class SecretStoreBase with Store {
10 - static Future<SecretStore> load(SecureStorage storage) async {
11 - final secretStore = SecretStore();
12 - final backupPasswordKey = generateStoreKeyFor(key: SecretStoreKey.backupPassword);
13 - final backupPassword = await storage.read(key: backupPasswordKey);
14 - // FIX-ME: backupPassword ?? '' ???
15 - secretStore.write(key: backupPasswordKey, value: backupPassword ?? '');
16 -
17 - return secretStore;
18 - }
19 -
20 - SecretStoreBase() : values = ObservableMap<String, String>();
21 -
22 - ObservableMap values;
23 -
24 - String read(String key) => values[key] as String;
25 -
26 - String write({required String key, required String value}) =>
27 - values[key] = value;
28 -}
lib/view_model/backup_view_model.dart
+15 -8
@@ -4,7 +4,7 @@ import 'package:cake_wallet/core/backup_service_v3.dart';
4 import 'package:cake_wallet/core/execution_state.dart';
5 import 'package:cake_wallet/core/secure_storage.dart';
6 import 'package:cake_wallet/entities/secret_store_key.dart';
7 -import 'package:cake_wallet/store/secret_store.dart';
7 +import 'package:cake_wallet/view_model/edit_backup_password_view_model.dart';
8 import 'package:cw_core/root_dir.dart';
9 import 'package:cw_core/utils/print_verbose.dart';
10 import 'package:flutter/foundation.dart';
@@ -25,21 +25,28 @@ class BackupExportFile {
25 class BackupViewModel = BackupViewModelBase with _$BackupViewModel;
26
27 abstract class BackupViewModelBase with Store {
28 - BackupViewModelBase(this.secureStorage, this.secretStore, this.backupService)
28 + BackupViewModelBase(this.secureStorage, this.backupService, this.editBackupPasswordViewModel)
29 : isBackupPasswordVisible = false,
30 backupPassword = '',
31 state = InitialExecutionState() {
32 - final key = generateStoreKeyFor(key: SecretStoreKey.backupPassword);
33 - secretStore.values.observe((change) {
34 - if (change.key == key) {
35 - backupPassword = secretStore.read(key);
32 + init();
33 +
34 + reaction((_) => editBackupPasswordViewModel.backupPassword, (value) {
35 + if(value != backupPassword) {
36 + backupPassword = value;
37 + }
38 + });
39 +
40 + reaction((_)=>backupPassword, (value){
41 + if(value != editBackupPasswordViewModel.backupPassword) {
42 + editBackupPasswordViewModel.backupPassword = value;
43 }
37 - }, fireImmediately: true);
44 + });
45 }
46
47 final SecureStorage secureStorage;
41 - final SecretStore secretStore;
48 final BackupServiceV3 backupService;
49 + final EditBackupPasswordViewModel editBackupPasswordViewModel;
50
51 @observable
52 ExecutionState state;
lib/view_model/edit_backup_password_view_model.dart
+3 -6
@@ -1,7 +1,6 @@
1 import 'package:cake_wallet/core/secure_storage.dart';
2 import 'package:mobx/mobx.dart';
3 import 'package:cake_wallet/entities/secret_store_key.dart';
4 -import 'package:cake_wallet/store/secret_store.dart';
4
5 part 'edit_backup_password_view_model.g.dart';
6
@@ -9,12 +8,11 @@ class EditBackupPasswordViewModel = EditBackupPasswordViewModelBase
8 with _$EditBackupPasswordViewModel;
9
10 abstract class EditBackupPasswordViewModelBase with Store {
12 - EditBackupPasswordViewModelBase(this.secureStorage, this.secretStore)
13 - : backupPassword = secretStore.read(generateStoreKeyFor(key: SecretStoreKey.backupPassword)),
14 - _originalPassword = '';
11 + EditBackupPasswordViewModelBase(this.secureStorage,)
12 + : backupPassword = "",
13 + _originalPassword = ''{init();}
14
15 final SecureStorage secureStorage;
17 - final SecretStore secretStore;
16
17 @observable
18 String backupPassword;
@@ -38,6 +36,5 @@ abstract class EditBackupPasswordViewModelBase with Store {
36 Future<void> save() async {
37 final key = generateStoreKeyFor(key: SecretStoreKey.backupPassword);
38 await secureStorage.write(key: key, value: backupPassword);
41 - secretStore.write(key: key, value: backupPassword);
39 }
40 }