From 8af1350b95acc35ffb0e83e3ea67a32453b53a2f Mon Sep 17 00:00:00 2001 From: ryleedavis <rylee@cypherstack.com> Date: Tue, 8 Nov 2022 10:50:12 -0700 Subject: [PATCH] button correction for desktop restore backup and other ui fixes --- .../create_backup_view.dart | 37 +- .../restore_from_file_view.dart | 354 ++++++++++++------ 2 files changed, 251 insertions(+), 140 deletions(-) diff --git a/lib/pages/settings_views/global_settings_view/stack_backup_views/create_backup_view.dart b/lib/pages/settings_views/global_settings_view/stack_backup_views/create_backup_view.dart index 51a1d7218..eacdda66a 100644 --- a/lib/pages/settings_views/global_settings_view/stack_backup_views/create_backup_view.dart +++ b/lib/pages/settings_views/global_settings_view/stack_backup_views/create_backup_view.dart @@ -147,7 +147,7 @@ class _RestoreFromFileViewState extends State<CreateBackupView> { crossAxisAlignment: CrossAxisAlignment.start, children: [ Padding( - padding: const EdgeInsets.all(10.0), + padding: const EdgeInsets.only(bottom: 10), child: Text( "Choose file location", style: STextStyles.desktopTextExtraExtraSmall(context) @@ -158,24 +158,6 @@ class _RestoreFromFileViewState extends State<CreateBackupView> { ), ), child, - // const SizedBox(height: 20), - // Row( - // children: [ - // PrimaryButton( - // desktopMed: true, - // width: 200, - // label: "Create backup", - // onPressed: () {}, - // ), - // const SizedBox(width: 16), - // SecondaryButton( - // desktopMed: true, - // width: 200, - // label: "Cancel", - // onPressed: () {}, - // ), - // ], - // ), ], ); }, @@ -252,8 +234,21 @@ class _RestoreFromFileViewState extends State<CreateBackupView> { ); }), if (!Platform.isAndroid) - const SizedBox( - height: 8, + SizedBox( + height: !isDesktop ? 8 : 24, + ), + if (isDesktop) + Padding( + padding: const EdgeInsets.only(bottom: 10.0), + child: Text( + "Create a passphrase", + style: STextStyles.desktopTextExtraExtraSmall(context) + .copyWith( + color: Theme.of(context) + .extension<StackColors>()! + .textDark3), + textAlign: TextAlign.left, + ), ), ClipRRect( borderRadius: BorderRadius.circular( diff --git a/lib/pages/settings_views/global_settings_view/stack_backup_views/restore_from_file_view.dart b/lib/pages/settings_views/global_settings_view/stack_backup_views/restore_from_file_view.dart index c73d596f0..f7a9883de 100644 --- a/lib/pages/settings_views/global_settings_view/stack_backup_views/restore_from_file_view.dart +++ b/lib/pages/settings_views/global_settings_view/stack_backup_views/restore_from_file_view.dart @@ -131,7 +131,7 @@ class _RestoreFromFileViewState extends ConsumerState<RestoreFromFileView> { crossAxisAlignment: CrossAxisAlignment.start, children: [ Padding( - padding: const EdgeInsets.all(10.0), + padding: const EdgeInsets.only(bottom: 10.0), child: Text( "Choose file location", style: STextStyles.desktopTextExtraExtraSmall(context) @@ -143,26 +143,6 @@ class _RestoreFromFileViewState extends ConsumerState<RestoreFromFileView> { ), ), child, - const SizedBox(height: 20), - Row( - children: [ - PrimaryButton( - desktopMed: true, - width: 200, - label: "Restore", - onPressed: () { - restoreBackupPopup(context); - }, - ), - const SizedBox(width: 16), - SecondaryButton( - desktopMed: true, - width: 200, - label: "Cancel", - onPressed: () {}, - ), - ], - ), ], ); }, @@ -225,9 +205,22 @@ class _RestoreFromFileViewState extends ConsumerState<RestoreFromFileView> { ), onChanged: (newValue) {}, ), - const SizedBox( - height: 8, + SizedBox( + height: !isDesktop ? 8 : 24, ), + if (isDesktop) + Padding( + padding: const EdgeInsets.only(bottom: 10.0), + child: Text( + "Enter passphrase", + style: STextStyles.desktopTextExtraExtraSmall(context) + .copyWith( + color: Theme.of(context) + .extension<StackColors>()! + .textDark3), + textAlign: TextAlign.left, + ), + ), ClipRRect( borderRadius: BorderRadius.circular( Constants.size.circularBorderRadius, @@ -288,113 +281,236 @@ class _RestoreFromFileViewState extends ConsumerState<RestoreFromFileView> { height: 16, ), if (!isDesktop) const Spacer(), - TextButton( - style: passwordController.text.isEmpty || - fileLocationController.text.isEmpty - ? Theme.of(context) - .extension<StackColors>()! - .getPrimaryDisabledButtonColor(context) - : Theme.of(context) - .extension<StackColors>()! - .getPrimaryEnabledButtonColor(context), - onPressed: passwordController.text.isEmpty || - fileLocationController.text.isEmpty - ? null - : () async { - final String fileToRestore = - fileLocationController.text; - final String passphrase = passwordController.text; + !isDesktop + ? TextButton( + style: passwordController.text.isEmpty || + fileLocationController.text.isEmpty + ? Theme.of(context) + .extension<StackColors>()! + .getPrimaryDisabledButtonColor(context) + : Theme.of(context) + .extension<StackColors>()! + .getPrimaryEnabledButtonColor(context), + onPressed: passwordController.text.isEmpty || + fileLocationController.text.isEmpty + ? null + : () async { + final String fileToRestore = + fileLocationController.text; + final String passphrase = passwordController.text; - if (FocusScope.of(context).hasFocus) { - FocusScope.of(context).unfocus(); - await Future<void>.delayed( - const Duration(milliseconds: 75)); - } + if (FocusScope.of(context).hasFocus) { + FocusScope.of(context).unfocus(); + await Future<void>.delayed( + const Duration(milliseconds: 75)); + } - if (!(await File(fileToRestore).exists())) { - showFloatingFlushBar( - type: FlushBarType.warning, - message: "Backup file does not exist", - context: context, - ); - return; - } + if (!(await File(fileToRestore).exists())) { + await showFloatingFlushBar( + type: FlushBarType.warning, + message: "Backup file does not exist", + context: context, + ); + return; + } - bool shouldPop = false; - showDialog<dynamic>( - barrierDismissible: false, - context: context, - builder: (_) => WillPopScope( - onWillPop: () async { - return shouldPop; - }, - child: Column( - crossAxisAlignment: CrossAxisAlignment.stretch, - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Material( - color: Colors.transparent, - child: Center( - child: Text( - "Decrypting Stack backup file", - style: STextStyles.pageTitleH2(context) - .copyWith( - color: Theme.of(context) - .extension<StackColors>()! - .textWhite, + bool shouldPop = false; + await showDialog<dynamic>( + barrierDismissible: false, + context: context, + builder: (_) => WillPopScope( + onWillPop: () async { + return shouldPop; + }, + child: Column( + crossAxisAlignment: + CrossAxisAlignment.stretch, + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Material( + color: Colors.transparent, + child: Center( + child: Text( + "Decrypting Stack backup file", + style: + STextStyles.pageTitleH2(context) + .copyWith( + color: Theme.of(context) + .extension<StackColors>()! + .textWhite, + ), + ), + ), ), + const SizedBox( + height: 64, + ), + const Center( + child: LoadingIndicator( + width: 100, + ), + ), + ], + ), + ), + ); + + final String? jsonString = await compute( + SWB.decryptStackWalletWithPassphrase, + Tuple2(fileToRestore, passphrase), + debugLabel: "stack wallet decryption compute", + ); + + if (mounted) { + // pop LoadingIndicator + shouldPop = true; + Navigator.of(context).pop(); + + passwordController.text = ""; + + if (jsonString == null) { + await showFloatingFlushBar( + type: FlushBarType.warning, + message: "Failed to decrypt backup file", + context: context, + ); + return; + } + + await Navigator.of(context).push( + RouteGenerator.getRoute( + builder: (_) => StackRestoreProgressView( + jsonString: jsonString, ), ), - ), - const SizedBox( - height: 64, - ), - const Center( - child: LoadingIndicator( - width: 100, - ), - ), - ], - ), - ), - ); + ); + } + }, + child: Text( + "Restore", + style: STextStyles.button(context), + ), + ) + : Row( + children: [ + PrimaryButton( + width: 183, + desktopMed: true, + label: "Restore", + enabled: !(passwordController.text.isEmpty || + fileLocationController.text.isEmpty), + onPressed: passwordController.text.isEmpty || + fileLocationController.text.isEmpty + ? null + : () async { + final String fileToRestore = + fileLocationController.text; + final String passphrase = + passwordController.text; - final String? jsonString = await compute( - SWB.decryptStackWalletWithPassphrase, - Tuple2(fileToRestore, passphrase), - debugLabel: "stack wallet decryption compute", - ); + if (FocusScope.of(context).hasFocus) { + FocusScope.of(context).unfocus(); + await Future<void>.delayed( + const Duration(milliseconds: 75)); + } - if (mounted) { - // pop LoadingIndicator - shouldPop = true; - Navigator.of(context).pop(); + if (!(await File(fileToRestore).exists())) { + await showFloatingFlushBar( + type: FlushBarType.warning, + message: "Backup file does not exist", + context: context, + ); + return; + } - passwordController.text = ""; + bool shouldPop = false; + await showDialog<dynamic>( + barrierDismissible: false, + context: context, + builder: (_) => WillPopScope( + onWillPop: () async { + return shouldPop; + }, + child: Column( + crossAxisAlignment: + CrossAxisAlignment.stretch, + mainAxisAlignment: + MainAxisAlignment.center, + children: [ + Material( + color: Colors.transparent, + child: Center( + child: Text( + "Decrypting Stack backup file", + style: STextStyles.pageTitleH2( + context) + .copyWith( + color: Theme.of(context) + .extension<StackColors>()! + .textWhite, + ), + ), + ), + ), + const SizedBox( + height: 64, + ), + const Center( + child: LoadingIndicator( + width: 100, + ), + ), + ], + ), + ), + ); - if (jsonString == null) { - showFloatingFlushBar( - type: FlushBarType.warning, - message: "Failed to decrypt backup file", - context: context, - ); - return; - } + final String? jsonString = await compute( + SWB.decryptStackWalletWithPassphrase, + Tuple2(fileToRestore, passphrase), + debugLabel: + "stack wallet decryption compute", + ); - Navigator.of(context).push( - RouteGenerator.getRoute( - builder: (_) => StackRestoreProgressView( - jsonString: jsonString, - ), - ), - ); - } - }, - child: Text( - "Restore", - style: STextStyles.button(context), - ), - ), + if (mounted) { + // pop LoadingIndicator + shouldPop = true; + Navigator.of(context).pop(); + + passwordController.text = ""; + + if (jsonString == null) { + await showFloatingFlushBar( + type: FlushBarType.warning, + message: + "Failed to decrypt backup file", + context: context, + ); + return; + } + + await Navigator.of(context).push( + RouteGenerator.getRoute( + builder: (_) => + StackRestoreProgressView( + jsonString: jsonString, + ), + ), + ); + } + }, + ), + const SizedBox( + width: 16, + ), + SecondaryButton( + width: 183, + desktopMed: true, + label: "Cancel", + onPressed: () {}, + ), + ], + ), ], ), ));