mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2025-01-22 18:44:31 +00:00
added conditional for desktop manual and restore backup
This commit is contained in:
parent
9231c3a2a5
commit
a6c380592e
2 changed files with 695 additions and 663 deletions
|
@ -15,6 +15,7 @@ import 'package:stackwallet/utilities/logger.dart';
|
||||||
import 'package:stackwallet/utilities/text_styles.dart';
|
import 'package:stackwallet/utilities/text_styles.dart';
|
||||||
import 'package:stackwallet/utilities/theme/stack_colors.dart';
|
import 'package:stackwallet/utilities/theme/stack_colors.dart';
|
||||||
import 'package:stackwallet/utilities/util.dart';
|
import 'package:stackwallet/utilities/util.dart';
|
||||||
|
import 'package:stackwallet/widgets/conditional_parent.dart';
|
||||||
import 'package:stackwallet/widgets/custom_buttons/app_bar_icon_button.dart';
|
import 'package:stackwallet/widgets/custom_buttons/app_bar_icon_button.dart';
|
||||||
import 'package:stackwallet/widgets/progress_bar.dart';
|
import 'package:stackwallet/widgets/progress_bar.dart';
|
||||||
import 'package:stackwallet/widgets/stack_dialog.dart';
|
import 'package:stackwallet/widgets/stack_dialog.dart';
|
||||||
|
@ -93,8 +94,14 @@ class _RestoreFromFileViewState extends State<CreateBackupView> {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
final isDesktop = Util.isDesktop;
|
||||||
|
|
||||||
|
return ConditionalParent(
|
||||||
|
condition: !isDesktop,
|
||||||
|
builder: (child) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
backgroundColor: Theme.of(context).extension<StackColors>()!.background,
|
backgroundColor:
|
||||||
|
Theme.of(context).extension<StackColors>()!.background,
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
leading: AppBarBackButton(
|
leading: AppBarBackButton(
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
|
@ -122,6 +129,30 @@ class _RestoreFromFileViewState extends State<CreateBackupView> {
|
||||||
minHeight: constraints.maxHeight,
|
minHeight: constraints.maxHeight,
|
||||||
),
|
),
|
||||||
child: IntrinsicHeight(
|
child: IntrinsicHeight(
|
||||||
|
child: child,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
child: ConditionalParent(
|
||||||
|
condition: isDesktop,
|
||||||
|
builder: (child) {
|
||||||
|
return Column(
|
||||||
|
children: [
|
||||||
|
Text(
|
||||||
|
"Choose file location",
|
||||||
|
style: STextStyles.desktopTextExtraSmall(context).copyWith(
|
||||||
|
color:
|
||||||
|
Theme.of(context).extension<StackColors>()!.textDark3),
|
||||||
|
),
|
||||||
|
// child,
|
||||||
|
],
|
||||||
|
);
|
||||||
|
},
|
||||||
child: Column(
|
child: Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||||
children: [
|
children: [
|
||||||
|
@ -139,8 +170,7 @@ class _RestoreFromFileViewState extends State<CreateBackupView> {
|
||||||
await stackFileSystem.prepareStorage();
|
await stackFileSystem.prepareStorage();
|
||||||
|
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
await stackFileSystem
|
await stackFileSystem.pickDir(context);
|
||||||
.pickDir(context);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
|
@ -150,8 +180,8 @@ class _RestoreFromFileViewState extends State<CreateBackupView> {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} catch (e, s) {
|
} catch (e, s) {
|
||||||
Logging.instance.log("$e\n$s",
|
Logging.instance
|
||||||
level: LogLevel.Error);
|
.log("$e\n$s", level: LogLevel.Error);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
controller: fileLocationController,
|
controller: fileLocationController,
|
||||||
|
@ -180,8 +210,8 @@ class _RestoreFromFileViewState extends State<CreateBackupView> {
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
key: const Key(
|
key:
|
||||||
"createBackupSaveToFileLocationTextFieldKey"),
|
const Key("createBackupSaveToFileLocationTextFieldKey"),
|
||||||
readOnly: true,
|
readOnly: true,
|
||||||
toolbarOptions: const ToolbarOptions(
|
toolbarOptions: const ToolbarOptions(
|
||||||
copy: true,
|
copy: true,
|
||||||
|
@ -231,9 +261,7 @@ class _RestoreFromFileViewState extends State<CreateBackupView> {
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
child: SvgPicture.asset(
|
child: SvgPicture.asset(
|
||||||
hidePassword
|
hidePassword ? Assets.svg.eye : Assets.svg.eyeSlash,
|
||||||
? Assets.svg.eye
|
|
||||||
: Assets.svg.eyeSlash,
|
|
||||||
color: Theme.of(context)
|
color: Theme.of(context)
|
||||||
.extension<StackColors>()!
|
.extension<StackColors>()!
|
||||||
.textDark3,
|
.textDark3,
|
||||||
|
@ -257,8 +285,7 @@ class _RestoreFromFileViewState extends State<CreateBackupView> {
|
||||||
}
|
}
|
||||||
final result = zxcvbn.evaluate(newValue);
|
final result = zxcvbn.evaluate(newValue);
|
||||||
String suggestionsAndTips = "";
|
String suggestionsAndTips = "";
|
||||||
for (var sug
|
for (var sug in result.feedback.suggestions!.toSet()) {
|
||||||
in result.feedback.suggestions!.toSet()) {
|
|
||||||
suggestionsAndTips += "$sug\n";
|
suggestionsAndTips += "$sug\n";
|
||||||
}
|
}
|
||||||
suggestionsAndTips += result.feedback.warning!;
|
suggestionsAndTips += result.feedback.warning!;
|
||||||
|
@ -275,8 +302,7 @@ class _RestoreFromFileViewState extends State<CreateBackupView> {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (feedback.endsWith("\n")) {
|
if (feedback.endsWith("\n")) {
|
||||||
feedback =
|
feedback = feedback.substring(0, feedback.length - 2);
|
||||||
feedback.substring(0, feedback.length - 2);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
setState(() {
|
setState(() {
|
||||||
|
@ -328,9 +354,7 @@ class _RestoreFromFileViewState extends State<CreateBackupView> {
|
||||||
backgroundColor: Theme.of(context)
|
backgroundColor: Theme.of(context)
|
||||||
.extension<StackColors>()!
|
.extension<StackColors>()!
|
||||||
.buttonBackSecondary,
|
.buttonBackSecondary,
|
||||||
percent: passwordStrength < 0.25
|
percent: passwordStrength < 0.25 ? 0.03 : passwordStrength,
|
||||||
? 0.03
|
|
||||||
: passwordStrength,
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
const SizedBox(
|
const SizedBox(
|
||||||
|
@ -368,9 +392,7 @@ class _RestoreFromFileViewState extends State<CreateBackupView> {
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
child: SvgPicture.asset(
|
child: SvgPicture.asset(
|
||||||
hidePassword
|
hidePassword ? Assets.svg.eye : Assets.svg.eyeSlash,
|
||||||
? Assets.svg.eye
|
|
||||||
: Assets.svg.eyeSlash,
|
|
||||||
color: Theme.of(context)
|
color: Theme.of(context)
|
||||||
.extension<StackColors>()!
|
.extension<StackColors>()!
|
||||||
.textDark3,
|
.textDark3,
|
||||||
|
@ -406,10 +428,8 @@ class _RestoreFromFileViewState extends State<CreateBackupView> {
|
||||||
onPressed: !shouldEnableCreate
|
onPressed: !shouldEnableCreate
|
||||||
? null
|
? null
|
||||||
: () async {
|
: () async {
|
||||||
final String pathToSave =
|
final String pathToSave = fileLocationController.text;
|
||||||
fileLocationController.text;
|
final String passphrase = passwordController.text;
|
||||||
final String passphrase =
|
|
||||||
passwordController.text;
|
|
||||||
final String repeatPassphrase =
|
final String repeatPassphrase =
|
||||||
passwordRepeatController.text;
|
passwordRepeatController.text;
|
||||||
|
|
||||||
|
@ -455,18 +475,15 @@ class _RestoreFromFileViewState extends State<CreateBackupView> {
|
||||||
),
|
),
|
||||||
));
|
));
|
||||||
// make sure the dialog is able to be displayed for at least 1 second
|
// make sure the dialog is able to be displayed for at least 1 second
|
||||||
await Future<void>.delayed(
|
await Future<void>.delayed(const Duration(seconds: 1));
|
||||||
const Duration(seconds: 1));
|
|
||||||
|
|
||||||
final DateTime now = DateTime.now();
|
final DateTime now = DateTime.now();
|
||||||
final String fileToSave =
|
final String fileToSave =
|
||||||
"$pathToSave/stackbackup_${now.year}_${now.month}_${now.day}_${now.hour}_${now.minute}_${now.second}.swb";
|
"$pathToSave/stackbackup_${now.year}_${now.month}_${now.day}_${now.hour}_${now.minute}_${now.second}.swb";
|
||||||
|
|
||||||
final backup =
|
final backup = await SWB.createStackWalletJSON();
|
||||||
await SWB.createStackWalletJSON();
|
|
||||||
|
|
||||||
bool result =
|
bool result = await SWB.encryptStackWalletWithPassphrase(
|
||||||
await SWB.encryptStackWalletWithPassphrase(
|
|
||||||
fileToSave,
|
fileToSave,
|
||||||
passphrase,
|
passphrase,
|
||||||
jsonEncode(backup),
|
jsonEncode(backup),
|
||||||
|
@ -486,8 +503,7 @@ class _RestoreFromFileViewState extends State<CreateBackupView> {
|
||||||
message: fileToSave,
|
message: fileToSave,
|
||||||
)
|
)
|
||||||
: const StackOkDialog(
|
: const StackOkDialog(
|
||||||
title:
|
title: "Backup creation succeeded"),
|
||||||
"Backup creation succeeded"),
|
|
||||||
);
|
);
|
||||||
passwordController.text = "";
|
passwordController.text = "";
|
||||||
passwordRepeatController.text = "";
|
passwordRepeatController.text = "";
|
||||||
|
@ -510,11 +526,6 @@ class _RestoreFromFileViewState extends State<CreateBackupView> {
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,13 +15,13 @@ import 'package:stackwallet/utilities/enums/flush_bar_type.dart';
|
||||||
import 'package:stackwallet/utilities/logger.dart';
|
import 'package:stackwallet/utilities/logger.dart';
|
||||||
import 'package:stackwallet/utilities/text_styles.dart';
|
import 'package:stackwallet/utilities/text_styles.dart';
|
||||||
import 'package:stackwallet/utilities/theme/stack_colors.dart';
|
import 'package:stackwallet/utilities/theme/stack_colors.dart';
|
||||||
|
import 'package:stackwallet/utilities/util.dart';
|
||||||
|
import 'package:stackwallet/widgets/conditional_parent.dart';
|
||||||
import 'package:stackwallet/widgets/custom_buttons/app_bar_icon_button.dart';
|
import 'package:stackwallet/widgets/custom_buttons/app_bar_icon_button.dart';
|
||||||
import 'package:stackwallet/widgets/loading_indicator.dart';
|
import 'package:stackwallet/widgets/loading_indicator.dart';
|
||||||
import 'package:stackwallet/widgets/stack_text_field.dart';
|
import 'package:stackwallet/widgets/stack_text_field.dart';
|
||||||
import 'package:tuple/tuple.dart';
|
import 'package:tuple/tuple.dart';
|
||||||
|
|
||||||
import 'package:stackwallet/utilities/util.dart';
|
|
||||||
|
|
||||||
class RestoreFromFileView extends ConsumerStatefulWidget {
|
class RestoreFromFileView extends ConsumerStatefulWidget {
|
||||||
const RestoreFromFileView({Key? key}) : super(key: key);
|
const RestoreFromFileView({Key? key}) : super(key: key);
|
||||||
|
|
||||||
|
@ -65,14 +65,21 @@ class _RestoreFromFileViewState extends ConsumerState<RestoreFromFileView> {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
final isDesktop = Util.isDesktop;
|
||||||
|
|
||||||
|
return ConditionalParent(
|
||||||
|
condition: !isDesktop,
|
||||||
|
builder: (child) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
backgroundColor: Theme.of(context).extension<StackColors>()!.background,
|
backgroundColor:
|
||||||
|
Theme.of(context).extension<StackColors>()!.background,
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
leading: AppBarBackButton(
|
leading: AppBarBackButton(
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
if (FocusScope.of(context).hasFocus) {
|
if (FocusScope.of(context).hasFocus) {
|
||||||
FocusScope.of(context).unfocus();
|
FocusScope.of(context).unfocus();
|
||||||
await Future<void>.delayed(const Duration(milliseconds: 75));
|
await Future<void>.delayed(
|
||||||
|
const Duration(milliseconds: 75));
|
||||||
}
|
}
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
Navigator.of(context).pop();
|
Navigator.of(context).pop();
|
||||||
|
@ -94,6 +101,31 @@ class _RestoreFromFileViewState extends ConsumerState<RestoreFromFileView> {
|
||||||
minHeight: constraints.maxHeight,
|
minHeight: constraints.maxHeight,
|
||||||
),
|
),
|
||||||
child: IntrinsicHeight(
|
child: IntrinsicHeight(
|
||||||
|
child: child,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
child: ConditionalParent(
|
||||||
|
condition: isDesktop,
|
||||||
|
builder: (child) {
|
||||||
|
return Column(
|
||||||
|
children: [
|
||||||
|
Text(
|
||||||
|
"Choose file location",
|
||||||
|
style: STextStyles.desktopTextExtraSmall(context).copyWith(
|
||||||
|
color: Theme.of(context)
|
||||||
|
.extension<StackColors>()!
|
||||||
|
.textDark3),
|
||||||
|
),
|
||||||
|
// child,
|
||||||
|
],
|
||||||
|
);
|
||||||
|
},
|
||||||
child: Column(
|
child: Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||||
children: [
|
children: [
|
||||||
|
@ -114,8 +146,7 @@ class _RestoreFromFileViewState extends ConsumerState<RestoreFromFileView> {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} catch (e, s) {
|
} catch (e, s) {
|
||||||
Logging.instance
|
Logging.instance.log("$e\n$s", level: LogLevel.Error);
|
||||||
.log("$e\n$s", level: LogLevel.Error);
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
controller: fileLocationController,
|
controller: fileLocationController,
|
||||||
|
@ -230,8 +261,7 @@ class _RestoreFromFileViewState extends ConsumerState<RestoreFromFileView> {
|
||||||
: () async {
|
: () async {
|
||||||
final String fileToRestore =
|
final String fileToRestore =
|
||||||
fileLocationController.text;
|
fileLocationController.text;
|
||||||
final String passphrase =
|
final String passphrase = passwordController.text;
|
||||||
passwordController.text;
|
|
||||||
|
|
||||||
if (FocusScope.of(context).hasFocus) {
|
if (FocusScope.of(context).hasFocus) {
|
||||||
FocusScope.of(context).unfocus();
|
FocusScope.of(context).unfocus();
|
||||||
|
@ -257,18 +287,15 @@ class _RestoreFromFileViewState extends ConsumerState<RestoreFromFileView> {
|
||||||
return shouldPop;
|
return shouldPop;
|
||||||
},
|
},
|
||||||
child: Column(
|
child: Column(
|
||||||
crossAxisAlignment:
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||||
CrossAxisAlignment.stretch,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
mainAxisAlignment:
|
|
||||||
MainAxisAlignment.center,
|
|
||||||
children: [
|
children: [
|
||||||
Material(
|
Material(
|
||||||
color: Colors.transparent,
|
color: Colors.transparent,
|
||||||
child: Center(
|
child: Center(
|
||||||
child: Text(
|
child: Text(
|
||||||
"Decrypting Stack backup file",
|
"Decrypting Stack backup file",
|
||||||
style: STextStyles.pageTitleH2(
|
style: STextStyles.pageTitleH2(context)
|
||||||
context)
|
|
||||||
.copyWith(
|
.copyWith(
|
||||||
color: Theme.of(context)
|
color: Theme.of(context)
|
||||||
.extension<StackColors>()!
|
.extension<StackColors>()!
|
||||||
|
@ -328,12 +355,6 @@ class _RestoreFromFileViewState extends ConsumerState<RestoreFromFileView> {
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
));
|
||||||
),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue