This commit is contained in:
M
2021-01-13 18:43:34 +02:00
parent c20d57e9a9
commit c09a41b090
18 changed files with 826 additions and 24 deletions
+93
View File
@@ -0,0 +1,93 @@
import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter_mobx/flutter_mobx.dart';
import 'package:esys_flutter_share/esys_flutter_share.dart';
import 'package:cake_wallet/routes.dart';
import 'package:cake_wallet/generated/i18n.dart';
import 'package:cake_wallet/src/widgets/alert_with_two_actions.dart';
import 'package:cake_wallet/src/widgets/primary_button.dart';
import 'package:cake_wallet/src/widgets/trail_button.dart';
import 'package:cake_wallet/utils/show_pop_up.dart';
import 'package:cake_wallet/view_model/backup_view_model.dart';
import 'package:cake_wallet/core/execution_state.dart';
import 'package:cake_wallet/src/screens/base_page.dart';
class BackupPage extends BasePage {
BackupPage(this.backupViewModelBase);
final BackupViewModelBase backupViewModelBase;
@override
String get title => 'Backup';
@override
Widget trailing(BuildContext context) => TrailButton(
caption: S.of(context).edit,
onPressed: () =>
Navigator.of(context).pushNamed(Routes.editBackupPassword));
@override
Widget body(BuildContext context) {
return Stack(
fit: StackFit.expand,
children: [
Center(
child: Container(
padding: EdgeInsets.only(left: 20, right: 20),
height: 225,
child: Column(children: [
Text(
'Backup password:',
style: TextStyle(fontSize: 30),
),
Padding(
padding: EdgeInsets.only(top: 20, bottom: 10),
child: Observer(
builder: (_) => Text(
backupViewModelBase.backupPassword,
style: TextStyle(fontSize: 26),
))),
Padding(
padding: EdgeInsets.all(20),
child: Text(
'Please write down your Backup Password. Backup Password uses for import of backup files.',
style: TextStyle(fontSize: 14, color: Colors.grey),
textAlign: TextAlign.center,
))
]))),
Positioned(
child: Observer(
builder: (_) => LoadingPrimaryButton(
isLoading: backupViewModelBase.state is IsExecutingState,
onPressed: () => onExportBackup(context),
text: 'Export backup',
color: Theme.of(context).accentTextTheme.body2.color,
textColor: Colors.white)),
bottom: 30,
left: 20,
right: 20,
)
],
);
}
void onExportBackup(BuildContext context) {
showPopUp<void>(
context: context,
builder: (dialogContext) {
return AlertWithTwoActions(
alertTitle: 'Export backup',
alertContent:
'Please be sure that you have saved your Backup Password.You will be no available to import backup files without Backup Password.\n\nHave you written it down?',
rightButtonText: S.of(context).seed_alert_yes,
leftButtonText: S.of(context).seed_alert_back,
actionRightButton: () async {
Navigator.of(dialogContext).pop();
final backup = await backupViewModelBase.exportBackup();
await Share.file(
'Backup file', backup.name, backup.content, 'text');
},
actionLeftButton: () => Navigator.of(dialogContext).pop());
});
}
}
@@ -0,0 +1,73 @@
import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter_mobx/flutter_mobx.dart';
import 'package:cake_wallet/generated/i18n.dart';
import 'package:cake_wallet/utils/show_pop_up.dart';
import 'package:cake_wallet/src/screens/base_page.dart';
import 'package:cake_wallet/src/widgets/alert_with_two_actions.dart';
import 'package:cake_wallet/src/widgets/primary_button.dart';
import 'package:cake_wallet/view_model/edit_backup_password_view_model.dart';
class EditBackupPasswordPage extends BasePage {
EditBackupPasswordPage(this.editBackupPasswordViewModel)
: textEditingController = TextEditingController() {
textEditingController.text = editBackupPasswordViewModel.backupPassword;
textEditingController.addListener(() => editBackupPasswordViewModel
.backupPassword = textEditingController.text);
}
final EditBackupPasswordViewModel editBackupPasswordViewModel;
final TextEditingController textEditingController;
@override
String get title => 'Edit Backup Password';
@override
Widget body(BuildContext context) {
return Padding(
padding: EdgeInsets.only(left: 20, right: 20),
child: Stack(
fit: StackFit.expand,
children: [
Center(
child: Observer(
builder: (_) => TextFormField(
autofocus: true,
enableSuggestions: false,
autocorrect: false,
keyboardType: TextInputType.visiblePassword,
controller: textEditingController,
style: TextStyle(fontSize: 26, color: Colors.black)))),
Positioned(
child: Observer(
builder: (_) => PrimaryButton(
onPressed: () => onSave(context),
text: 'Save',
color: Theme.of(context).accentTextTheme.body2.color,
textColor: Colors.white,
isDisabled: !editBackupPasswordViewModel.canSave)),
bottom: 30,
left: 0,
right: 0)
],
));
}
void onSave(BuildContext context) {
showPopUp<void>(
context: context,
builder: (dialogContext) {
return AlertWithTwoActions(
alertTitle: 'Save backup password',
alertContent:
'Your previous backup files will be not available to import with new backup password. New backup password will be used only for new backup files. Are you sure that you want to change backup password ?',
rightButtonText: S.of(context).ok,
leftButtonText: S.of(context).cancel,
actionRightButton: () async {
await editBackupPasswordViewModel.save();
Navigator.of(dialogContext)..pop()..pop();
},
actionLeftButton: () => Navigator.of(dialogContext).pop());
});
}
}
@@ -0,0 +1,88 @@
import 'package:cake_wallet/generated/i18n.dart';
import 'package:cake_wallet/src/widgets/alert_with_one_action.dart';
import 'package:cake_wallet/utils/show_pop_up.dart';
import 'package:flutter/material.dart';
import 'package:flutter/src/widgets/framework.dart';
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/src/screens/base_page.dart';
import 'package:file_picker/file_picker.dart';
class RestoreFromBackupPage extends BasePage {
RestoreFromBackupPage(this.restoreFromBackupViewModel)
: textEditingController = TextEditingController();
final RestoreFromBackupViewModel restoreFromBackupViewModel;
final TextEditingController textEditingController;
@override
String get title => 'Restore from backup';
@override
Widget body(BuildContext context) {
return Container(
padding: EdgeInsets.only(bottom: 30, left: 25, right: 25),
child: Column(children: [
Expanded(
child: Container(
child: Center(
child: TextFormField(
obscureText: true,
enableSuggestions: false,
autocorrect: false,
decoration: InputDecoration(
hintText: 'Enter backup password here'),
keyboardType: TextInputType.visiblePassword,
controller: textEditingController,
style: TextStyle(fontSize: 26, color: Colors.black))),
),
),
Container(
child: Row(children: [
Expanded(
child: PrimaryButton(
onPressed: () => presentFilePicker(),
text: 'Select backup file',
color: Colors.grey,
textColor: Colors.white)),
SizedBox(width: 20),
Expanded(
child: PrimaryButton(
onPressed: () => onImportHandler(context),
text: 'Import',
color: Theme.of(context).accentTextTheme.body2.color,
textColor: Colors.white))
])),
]));
}
Future<void> presentFilePicker() async {
final result = await FilePicker.platform.pickFiles();
if (result?.files?.isEmpty ?? true) {
return;
}
restoreFromBackupViewModel.filePath = result.files.first.path;
}
Future<void> onImportHandler(BuildContext context) async {
if (textEditingController.text.isEmpty ||
(restoreFromBackupViewModel.filePath.isEmpty ?? true)) {
await showPopUp<void>(
context: context,
builder: (_) {
return AlertWithOneAction(
alertTitle: S.current.error,
alertContent:
'Please select backup file and enter backup password.',
buttonText: S.of(context).ok,
buttonAction: () => Navigator.of(context).pop());
});
return;
}
await restoreFromBackupViewModel.import(textEditingController.text);
}
}
@@ -1,6 +1,5 @@
import 'package:cake_wallet/entities/wallet_type.dart';
import 'package:flutter/material.dart';
import 'package:cake_wallet/palette.dart';
import 'package:cake_wallet/routes.dart';
import 'package:flutter/cupertino.dart';
import 'package:cake_wallet/src/screens/restore/widgets/restore_button.dart';
@@ -39,7 +38,8 @@ class RestoreOptionsPage extends BasePage {
Padding(
padding: EdgeInsets.only(top: 24),
child: RestoreButton(
onPressed: () {},
onPressed: () => Navigator.pushNamed(
context, Routes.restoreFromBackup),
image: imageBackup,
title: S.of(context).restore_title_from_backup,
description: S.of(context).restore_description_from_backup
+1 -1
View File
@@ -21,7 +21,7 @@ class TrailButton extends StatelessWidget {
child: Text(
caption,
style: TextStyle(
color: Theme.of(context).textTheme.subhead.decorationColor,
color: Theme.of(context).textTheme.display1.color,
fontWeight: FontWeight.w500,
fontSize: 14),
),