mirror of
https://github.com/Such-Software/hash-wallet.git
synced 2026-10-17 05:41:29 +02:00
CW-949 backup error messages (#2059)
* [skip-ci] minor * dont initialize with restore button enabled + error handling updates
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -67,7 +67,6 @@ abstract class WalletRestoreViewModelBase extends WalletCreationVM with Store {
|
||||
availableModes = [WalletRestoreMode.seed];
|
||||
break;
|
||||
}
|
||||
isButtonEnabled = !hasSeedLanguageSelector && !hasBlockchainHeightLanguageSelector;
|
||||
walletCreationService.changeWalletType(type: type);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user