CW-949 backup error messages ()

* [skip-ci] minor

* dont initialize with restore button enabled + error handling updates
This commit is contained in:
Matthew Fosse 2025-03-06 10:00:44 -08:00 committed by GitHub
parent c2996ac303
commit 6cc9f4f757
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 26 additions and 8 deletions

View file

@ -13,13 +13,12 @@ import 'package:cake_wallet/store/authentication_store.dart';
part 'restore_from_backup_view_model.g.dart';
class RestoreFromBackupViewModel = RestoreFromBackupViewModelBase
with _$RestoreFromBackupViewModel;
class RestoreFromBackupViewModel = RestoreFromBackupViewModelBase with _$RestoreFromBackupViewModel;
abstract class RestoreFromBackupViewModelBase with Store {
RestoreFromBackupViewModelBase(this.backupService)
: state = InitialExecutionState(),
filePath = '';
: state = InitialExecutionState(),
filePath = '';
final BackupService backupService;
@ -45,8 +44,14 @@ abstract class RestoreFromBackupViewModelBase with Store {
final file = File(filePath);
final data = await file.readAsBytes();
await backupService.importBackup(data, password);
await initializeAppAtRoot(reInitializing: true);
try {
await initializeAppAtRoot(reInitializing: true);
} catch (e, s) {
throw Exception('failed_app_initialization: $e $s');
}
final store = getIt.get<AppStore>();
ReactionDisposer? reaction;
@ -63,11 +68,25 @@ abstract class RestoreFromBackupViewModelBase with Store {
state = ExecutedSuccessfullyState();
} catch (e, s) {
var msg = e.toString();
var msg = e.toString().toLowerCase();
if (msg.toLowerCase().contains("message authentication code (mac)")) {
// can't use a switch here because of .contains() / not an exact match
bool shouldBeMadeAware = false;
if (msg.contains("message authentication code (mac)")) {
msg = 'Incorrect backup password';
} else if (msg.contains("faileddecryption")) {
msg = 'Failed to decrypt backup file, please check you entered the right password';
} else if (msg.contains("failed_to_decode")) {
msg = 'Failed to decode backup file, please try again';
shouldBeMadeAware = true;
} else if (msg.contains("failed_app_initialization")) {
msg = 'Failed to initialize app, please try again';
shouldBeMadeAware = true;
} else {
shouldBeMadeAware = true;
}
if (shouldBeMadeAware) {
await ExceptionHandler.onError(FlutterErrorDetails(
exception: e,
stack: s,

View file

@ -67,7 +67,6 @@ abstract class WalletRestoreViewModelBase extends WalletCreationVM with Store {
availableModes = [WalletRestoreMode.seed];
break;
}
isButtonEnabled = !hasSeedLanguageSelector && !hasBlockchainHeightLanguageSelector;
walletCreationService.changeWalletType(type: type);
}