Added displaying of errors on restore from backup screen.

This commit is contained in:
M 2021-01-15 20:07:05 +02:00
parent ab5077e5f5
commit 5999744fc7
2 changed files with 45 additions and 8 deletions

View file

@ -1,3 +1,4 @@
import 'package:cake_wallet/core/execution_state.dart';
import 'package:cake_wallet/generated/i18n.dart'; import 'package:cake_wallet/generated/i18n.dart';
import 'package:cake_wallet/src/widgets/alert_with_one_action.dart'; import 'package:cake_wallet/src/widgets/alert_with_one_action.dart';
import 'package:cake_wallet/utils/show_pop_up.dart'; import 'package:cake_wallet/utils/show_pop_up.dart';
@ -7,6 +8,8 @@ import 'package:cake_wallet/src/widgets/primary_button.dart';
import 'package:cake_wallet/view_model/restore_from_backup_view_model.dart'; import 'package:cake_wallet/view_model/restore_from_backup_view_model.dart';
import 'package:cake_wallet/src/screens/base_page.dart'; import 'package:cake_wallet/src/screens/base_page.dart';
import 'package:file_picker/file_picker.dart'; import 'package:file_picker/file_picker.dart';
import 'package:flutter_mobx/flutter_mobx.dart';
import 'package:mobx/mobx.dart';
class RestoreFromBackupPage extends BasePage { class RestoreFromBackupPage extends BasePage {
RestoreFromBackupPage(this.restoreFromBackupViewModel) RestoreFromBackupPage(this.restoreFromBackupViewModel)
@ -20,6 +23,22 @@ class RestoreFromBackupPage extends BasePage {
@override @override
Widget body(BuildContext context) { Widget body(BuildContext context) {
reaction((_) => restoreFromBackupViewModel.state, (ExecutionState state) {
if (state is FailureState) {
WidgetsBinding.instance.addPostFrameCallback((_) {
showPopUp<void>(
context: context,
builder: (BuildContext context) {
return AlertWithOneAction(
alertTitle: S.of(context).error,
alertContent: state.error,
buttonText: S.of(context).ok,
buttonAction: () => Navigator.of(context).pop());
});
});
}
});
return Container( return Container(
padding: EdgeInsets.only(bottom: 30, left: 25, right: 25), padding: EdgeInsets.only(bottom: 30, left: 25, right: 25),
child: Column(children: [ child: Column(children: [
@ -46,12 +65,15 @@ class RestoreFromBackupPage extends BasePage {
color: Colors.grey, color: Colors.grey,
textColor: Colors.white)), textColor: Colors.white)),
SizedBox(width: 20), SizedBox(width: 20),
Expanded( Expanded(child: Observer(builder: (_) {
child: PrimaryButton( return LoadingPrimaryButton(
isLoading:
restoreFromBackupViewModel.state is IsExecutingState,
onPressed: () => onImportHandler(context), onPressed: () => onImportHandler(context),
text: 'Import', text: 'Import',
color: Theme.of(context).accentTextTheme.body2.color, color: Theme.of(context).accentTextTheme.body2.color,
textColor: Colors.white)) textColor: Colors.white);
}))
])), ])),
])); ]));
} }

View file

@ -1,4 +1,5 @@
import 'dart:io'; import 'dart:io';
import 'package:cake_wallet/core/execution_state.dart';
import 'package:hive/hive.dart'; import 'package:hive/hive.dart';
import 'package:mobx/mobx.dart'; import 'package:mobx/mobx.dart';
import 'package:cake_wallet/main.dart'; import 'package:cake_wallet/main.dart';
@ -19,15 +20,21 @@ abstract class RestoreFromBackupViewModelBase with Store {
@observable @observable
String filePath; String filePath;
@observable
ExecutionState state;
final BackupService backupService; final BackupService backupService;
@action @action
void reset() => filePath = ''; void reset() => filePath = '';
@action
Future<void> import(String password) async { Future<void> import(String password) async {
try { try {
state = IsExecutingState();
if (filePath?.isEmpty ?? true) { if (filePath?.isEmpty ?? true) {
// FIXME: throw exception; state = FailureState('Backup file is not selected.');
return; return;
} }
@ -49,8 +56,16 @@ abstract class RestoreFromBackupViewModelBase with Store {
reaction?.reaction?.dispose(); reaction?.reaction?.dispose();
} }
}); });
state = ExecutedSuccessfullyState();
} catch (e) { } catch (e) {
print(e.toString()); var msg = e.toString();
if (msg == 'Message authentication code (MAC) is invalid') {
msg = 'Incorrect backup password';
}
state = FailureState(msg);
} }
} }
} }