CW-949 backup error messages (#2059)

* [skip-ci] minor * dont initialize with restore button enabled + error handling updates

Matthew Fosse committed Mar 6, 2025 at 10:00 UTC 6cc9f4f757d41cee9deb48de9aea9dcb11f788ca
2 files changed +26 -8
lib/view_model/restore_from_backup_view_model.dart
+26 -7
@@ -13,13 +13,12 @@ import 'package:cake_wallet/store/authentication_store.dart';
13
14 part 'restore_from_backup_view_model.g.dart';
15
16 -class RestoreFromBackupViewModel = RestoreFromBackupViewModelBase
17 - with _$RestoreFromBackupViewModel;
16 +class RestoreFromBackupViewModel = RestoreFromBackupViewModelBase with _$RestoreFromBackupViewModel;
17
18 abstract class RestoreFromBackupViewModelBase with Store {
19 RestoreFromBackupViewModelBase(this.backupService)
21 - : state = InitialExecutionState(),
22 - filePath = '';
20 + : state = InitialExecutionState(),
21 + filePath = '';
22
23 final BackupService backupService;
24
@@ -45,8 +44,14 @@ abstract class RestoreFromBackupViewModelBase with Store {
44 final file = File(filePath);
45 final data = await file.readAsBytes();
46
47 +
48 await backupService.importBackup(data, password);
49 - await initializeAppAtRoot(reInitializing: true);
49 +
50 + try {
51 + await initializeAppAtRoot(reInitializing: true);
52 + } catch (e, s) {
53 + throw Exception('failed_app_initialization: $e $s');
54 + }
55
56 final store = getIt.get<AppStore>();
57 ReactionDisposer? reaction;
@@ -63,11 +68,25 @@ abstract class RestoreFromBackupViewModelBase with Store {
68
69 state = ExecutedSuccessfullyState();
70 } catch (e, s) {
66 - var msg = e.toString();
71 + var msg = e.toString().toLowerCase();
72
68 - if (msg.toLowerCase().contains("message authentication code (mac)")) {
73 + // can't use a switch here because of .contains() / not an exact match
74 + bool shouldBeMadeAware = false;
75 + if (msg.contains("message authentication code (mac)")) {
76 msg = 'Incorrect backup password';
77 + } else if (msg.contains("faileddecryption")) {
78 + msg = 'Failed to decrypt backup file, please check you entered the right password';
79 + } else if (msg.contains("failed_to_decode")) {
80 + msg = 'Failed to decode backup file, please try again';
81 + shouldBeMadeAware = true;
82 + } else if (msg.contains("failed_app_initialization")) {
83 + msg = 'Failed to initialize app, please try again';
84 + shouldBeMadeAware = true;
85 } else {
86 + shouldBeMadeAware = true;
87 + }
88 +
89 + if (shouldBeMadeAware) {
90 await ExceptionHandler.onError(FlutterErrorDetails(
91 exception: e,
92 stack: s,
lib/view_model/wallet_restore_view_model.dart
-1
@@ -67,7 +67,6 @@ abstract class WalletRestoreViewModelBase extends WalletCreationVM with Store {
67 availableModes = [WalletRestoreMode.seed];
68 break;
69 }
70 - isButtonEnabled = !hasSeedLanguageSelector && !hasBlockchainHeightLanguageSelector;
70 walletCreationService.changeWalletType(type: type);
71 }
72