Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CW-949 backup error messages #2059

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 26 additions & 7 deletions lib/view_model/restore_from_backup_view_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
Expand All @@ -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,
Expand Down
1 change: 0 additions & 1 deletion lib/view_model/wallet_restore_view_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ abstract class WalletRestoreViewModelBase extends WalletCreationVM with Store {
availableModes = [WalletRestoreMode.seed];
break;
}
isButtonEnabled = !hasSeedLanguageSelector && !hasBlockchainHeightLanguageSelector;
walletCreationService.changeWalletType(type: type);
}

Expand Down
Loading