From 6b88a1a4f184d4bdef9ffff775f879cd7ec385e1 Mon Sep 17 00:00:00 2001 From: julian Date: Fri, 7 Apr 2023 20:04:48 -0600 Subject: [PATCH] WIP consolidate xpub view --- .../global_settings_view/xpub_view.dart | 194 ++++++++++++++---- .../sub_widgets/desktop_show_xpub_dialog.dart | 177 ---------------- .../sub_widgets/wallet_options_button.dart | 6 +- lib/route_generator.dart | 16 +- 4 files changed, 162 insertions(+), 231 deletions(-) delete mode 100644 lib/pages_desktop_specific/my_stack_view/wallet_view/sub_widgets/desktop_show_xpub_dialog.dart diff --git a/lib/pages/settings_views/global_settings_view/xpub_view.dart b/lib/pages/settings_views/global_settings_view/xpub_view.dart index fce352037..dc3ca7e0b 100644 --- a/lib/pages/settings_views/global_settings_view/xpub_view.dart +++ b/lib/pages/settings_views/global_settings_view/xpub_view.dart @@ -6,22 +6,32 @@ import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:flutter_svg/svg.dart'; import 'package:qr_flutter/qr_flutter.dart'; import 'package:stackwallet/notifications/show_flush_bar.dart'; +import 'package:stackwallet/providers/global/wallets_provider.dart'; +import 'package:stackwallet/services/coins/manager.dart'; +import 'package:stackwallet/services/mixins/xpubable.dart'; import 'package:stackwallet/utilities/assets.dart'; import 'package:stackwallet/utilities/clipboard_interface.dart'; import 'package:stackwallet/utilities/text_styles.dart'; import 'package:stackwallet/utilities/theme/stack_colors.dart'; +import 'package:stackwallet/utilities/util.dart'; import 'package:stackwallet/widgets/background.dart'; +import 'package:stackwallet/widgets/conditional_parent.dart'; import 'package:stackwallet/widgets/custom_buttons/app_bar_icon_button.dart'; +import 'package:stackwallet/widgets/desktop/desktop_dialog.dart'; +import 'package:stackwallet/widgets/desktop/desktop_dialog_close_button.dart'; +import 'package:stackwallet/widgets/desktop/primary_button.dart'; +import 'package:stackwallet/widgets/desktop/secondary_button.dart'; +import 'package:stackwallet/widgets/loading_indicator.dart'; import 'package:stackwallet/widgets/rounded_white_container.dart'; class XPubView extends ConsumerStatefulWidget { const XPubView({ Key? key, - this.xpub, + required this.walletId, this.clipboardInterface = const ClipboardWrapper(), }) : super(key: key); - final String? xpub; + final String walletId; final ClipboardInterface clipboardInterface; static const String routeName = "/xpub"; @@ -31,11 +41,19 @@ class XPubView extends ConsumerStatefulWidget { } class _XPubViewState extends ConsumerState { + final bool isDesktop = Util.isDesktop; + late ClipboardInterface _clipboardInterface; + late final Manager manager; + + String? xpub; @override void initState() { _clipboardInterface = widget.clipboardInterface; + manager = + ref.read(walletsChangeNotifierProvider).getManager(widget.walletId); + super.initState(); } @@ -45,21 +63,26 @@ class _XPubViewState extends ConsumerState { } Future _copy() async { - await _clipboardInterface.setData(ClipboardData(text: widget.xpub)); - unawaited(showFloatingFlushBar( - type: FlushBarType.info, - message: "Copied to clipboard", - iconAsset: Assets.svg.copy, - context: context, - )); + await _clipboardInterface.setData(ClipboardData(text: xpub!)); + if (mounted) { + unawaited(showFloatingFlushBar( + type: FlushBarType.info, + message: "Copied to clipboard", + iconAsset: Assets.svg.copy, + context: context, + )); + } } @override Widget build(BuildContext context) { - return Background( - child: Scaffold( - backgroundColor: Theme.of(context).extension()!.background, - appBar: AppBar( + return ConditionalParent( + condition: !isDesktop, + builder: (child) => Background( + child: Scaffold( + backgroundColor: + Theme.of(context).extension()!.background, + appBar: AppBar( leading: AppBarBackButton( onPressed: () async { Navigator.of(context).pop(); @@ -92,32 +115,131 @@ class _XPubViewState extends ConsumerState { ), ), ), - ]), - body: Padding( - padding: const EdgeInsets.only( - top: 12, - left: 16, - right: 16, + ], ), - child: Column(children: [ - if (widget.xpub != null) - RoundedWhiteContainer( - padding: const EdgeInsets.all(12), - child: QrImage(data: widget.xpub!), - onPressed: () => _copy(), + body: Padding( + padding: const EdgeInsets.only( + top: 12, + left: 16, + right: 16, ), - if (widget.xpub != null) - const SizedBox( - height: 8, + child: child), + ), + ), + child: ConditionalParent( + condition: isDesktop, + builder: (child) => DesktopDialog( + maxWidth: 600, + maxHeight: double.infinity, + child: Column( + children: [ + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Padding( + padding: const EdgeInsets.only( + left: 32, + ), + child: Text( + "${manager.walletName} xPub", + style: STextStyles.desktopH2(context), + ), + ), + DesktopDialogCloseButton( + onPressedOverride: Navigator.of( + context, + rootNavigator: true, + ).pop, + ), + AnimatedSize( + duration: const Duration( + milliseconds: 150, + ), + child: Padding( + padding: const EdgeInsets.fromLTRB(32, 0, 32, 32), + child: child, + ), + ), + ], ), - if (widget.xpub != null) - RoundedWhiteContainer( - padding: const EdgeInsets.all(12), - child: Text(widget.xpub!, - style: STextStyles.largeMedium14(context)), - onPressed: () => _copy(), - ) - ]), + ], + ), + ), + child: Column( + children: [ + if (isDesktop) const SizedBox(height: 44), + FutureBuilder( + future: (manager.wallet as XPubAble).xpub, + builder: (context, AsyncSnapshot snapshot) { + if (snapshot.connectionState == ConnectionState.done && + snapshot.hasData) { + xpub = snapshot.data!; + } + + return Column( + children: [ + ConditionalParent( + condition: !isDesktop, + builder: (child) => RoundedWhiteContainer( + child: child, + ), + child: xpub == null + ? const SizedBox( + height: 300, + child: LoadingIndicator(), + ) + : QrImage( + data: xpub!, + size: 280, + foregroundColor: Theme.of(context) + .extension()! + .accentColorDark, + ), + ), + const SizedBox(height: 25), + RoundedWhiteContainer( + padding: const EdgeInsets.all(16), + borderColor: xpub == null + ? null + : Theme.of(context) + .extension()! + .backgroundAppBar, + child: SelectableText( + xpub ?? "", + style: STextStyles.largeMedium14(context), + ), + ), + if (isDesktop) const SizedBox(height: 32), + if (!isDesktop) const Spacer(), + Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Expanded( + child: SecondaryButton( + buttonHeight: ButtonHeight.xl, + label: "Cancel", + onPressed: Navigator.of( + context, + rootNavigator: true, + ).pop, + ), + ), + const SizedBox(width: 16), + Expanded( + child: PrimaryButton( + buttonHeight: ButtonHeight.xl, + label: "Copy", + enabled: xpub != null, + onPressed: _copy, + ), + ), + ], + ), + ], + ); + }, + ), + ], ), ), ); diff --git a/lib/pages_desktop_specific/my_stack_view/wallet_view/sub_widgets/desktop_show_xpub_dialog.dart b/lib/pages_desktop_specific/my_stack_view/wallet_view/sub_widgets/desktop_show_xpub_dialog.dart deleted file mode 100644 index 681e82cd2..000000000 --- a/lib/pages_desktop_specific/my_stack_view/wallet_view/sub_widgets/desktop_show_xpub_dialog.dart +++ /dev/null @@ -1,177 +0,0 @@ -import 'dart:async'; - -import 'package:flutter/material.dart'; -import 'package:flutter/services.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; -import 'package:qr_flutter/qr_flutter.dart'; -import 'package:stackwallet/notifications/show_flush_bar.dart'; -import 'package:stackwallet/providers/global/wallets_provider.dart'; -import 'package:stackwallet/services/coins/manager.dart'; -import 'package:stackwallet/services/mixins/xpubable.dart'; -import 'package:stackwallet/utilities/assets.dart'; -import 'package:stackwallet/utilities/clipboard_interface.dart'; -import 'package:stackwallet/utilities/text_styles.dart'; -import 'package:stackwallet/utilities/theme/stack_colors.dart'; -import 'package:stackwallet/widgets/desktop/desktop_dialog.dart'; -import 'package:stackwallet/widgets/desktop/desktop_dialog_close_button.dart'; -import 'package:stackwallet/widgets/desktop/primary_button.dart'; -import 'package:stackwallet/widgets/desktop/secondary_button.dart'; -import 'package:stackwallet/widgets/loading_indicator.dart'; -import 'package:stackwallet/widgets/rounded_white_container.dart'; - -class DesktopShowXpubDialog extends ConsumerStatefulWidget { - const DesktopShowXpubDialog({ - Key? key, - required this.walletId, - this.clipboardInterface = const ClipboardWrapper(), - }) : super(key: key); - - final String walletId; - - final ClipboardInterface clipboardInterface; - - static const String routeName = "/desktopShowXpubDialog"; - - @override - ConsumerState createState() => - _DesktopShowXpubDialog(); -} - -class _DesktopShowXpubDialog extends ConsumerState { - late ClipboardInterface _clipboardInterface; - late final Manager manager; - - String? xpub; - - @override - void initState() { - _clipboardInterface = widget.clipboardInterface; - manager = - ref.read(walletsChangeNotifierProvider).getManager(widget.walletId); - super.initState(); - } - - @override - void dispose() { - super.dispose(); - } - - Future _copy() async { - await _clipboardInterface.setData(ClipboardData(text: xpub!)); - if (mounted) { - unawaited(showFloatingFlushBar( - type: FlushBarType.info, - message: "Copied to clipboard", - iconAsset: Assets.svg.copy, - context: context, - )); - } - } - - @override - Widget build(BuildContext context) { - return DesktopDialog( - maxWidth: 600, - maxHeight: double.infinity, - child: Column( - children: [ - Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Padding( - padding: const EdgeInsets.only( - left: 32, - ), - child: Text( - "${manager.walletName} xPub", - style: STextStyles.desktopH2(context), - ), - ), - DesktopDialogCloseButton( - onPressedOverride: Navigator.of( - context, - rootNavigator: true, - ).pop, - ), - ], - ), - AnimatedSize( - duration: const Duration(milliseconds: 150), - child: Padding( - padding: const EdgeInsets.fromLTRB(32, 0, 32, 32), - child: Column( - children: [ - const SizedBox(height: 44), - FutureBuilder( - future: (manager.wallet as XPubAble).xpub, - builder: (context, AsyncSnapshot snapshot) { - if (snapshot.connectionState == ConnectionState.done && - snapshot.hasData) { - xpub = snapshot.data!; - } - - return Column( - children: [ - xpub == null - ? const SizedBox( - height: 300, - child: LoadingIndicator(), - ) - : QrImage( - data: xpub!, - size: 280, - foregroundColor: Theme.of(context) - .extension()! - .accentColorDark, - ), - const SizedBox(height: 25), - RoundedWhiteContainer( - padding: const EdgeInsets.all(16), - borderColor: xpub == null - ? null - : Theme.of(context) - .extension()! - .backgroundAppBar, - child: SelectableText( - xpub ?? "", - style: STextStyles.largeMedium14(context), - ), - ), - const SizedBox(height: 32), - Row( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Expanded( - child: SecondaryButton( - buttonHeight: ButtonHeight.xl, - label: "Cancel", - onPressed: Navigator.of( - context, - rootNavigator: true, - ).pop, - ), - ), - const SizedBox(width: 16), - Expanded( - child: PrimaryButton( - buttonHeight: ButtonHeight.xl, - label: "Copy", - enabled: xpub != null, - onPressed: _copy, - ), - ), - ], - ), - ], - ); - }, - ), - ], - ), - ), - ), - ], - ), - ); - } -} diff --git a/lib/pages_desktop_specific/my_stack_view/wallet_view/sub_widgets/wallet_options_button.dart b/lib/pages_desktop_specific/my_stack_view/wallet_view/sub_widgets/wallet_options_button.dart index 11ccd82d8..095b9c7e3 100644 --- a/lib/pages_desktop_specific/my_stack_view/wallet_view/sub_widgets/wallet_options_button.dart +++ b/lib/pages_desktop_specific/my_stack_view/wallet_view/sub_widgets/wallet_options_button.dart @@ -3,9 +3,9 @@ import 'dart:async'; import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:flutter_svg/svg.dart'; +import 'package:stackwallet/pages/settings_views/global_settings_view/xpub_view.dart'; import 'package:stackwallet/pages_desktop_specific/addresses/desktop_wallet_addresses_view.dart'; import 'package:stackwallet/pages_desktop_specific/my_stack_view/wallet_view/sub_widgets/desktop_delete_wallet_dialog.dart'; -import 'package:stackwallet/pages_desktop_specific/my_stack_view/wallet_view/sub_widgets/desktop_show_xpub_dialog.dart'; import 'package:stackwallet/providers/providers.dart'; import 'package:stackwallet/route_generator.dart'; import 'package:stackwallet/utilities/assets.dart'; @@ -109,13 +109,13 @@ class WalletOptionsButton extends StatelessWidget { context: context, barrierDismissible: false, builder: (context) => Navigator( - initialRoute: DesktopShowXpubDialog.routeName, + initialRoute: XPubView.routeName, onGenerateRoute: RouteGenerator.generateRoute, onGenerateInitialRoutes: (_, __) { return [ RouteGenerator.generateRoute( RouteSettings( - name: DesktopShowXpubDialog.routeName, + name: XPubView.routeName, arguments: walletId, ), ), diff --git a/lib/route_generator.dart b/lib/route_generator.dart index 0609c3839..db3a7450c 100644 --- a/lib/route_generator.dart +++ b/lib/route_generator.dart @@ -122,7 +122,6 @@ import 'package:stackwallet/pages_desktop_specific/my_stack_view/wallet_view/des import 'package:stackwallet/pages_desktop_specific/my_stack_view/wallet_view/sub_widgets/delete_wallet_keys_popup.dart'; import 'package:stackwallet/pages_desktop_specific/my_stack_view/wallet_view/sub_widgets/desktop_attention_delete_wallet.dart'; import 'package:stackwallet/pages_desktop_specific/my_stack_view/wallet_view/sub_widgets/desktop_delete_wallet_dialog.dart'; -import 'package:stackwallet/pages_desktop_specific/my_stack_view/wallet_view/sub_widgets/desktop_show_xpub_dialog.dart'; import 'package:stackwallet/pages_desktop_specific/my_stack_view/wallet_view/sub_widgets/qr_code_desktop_popup_content.dart'; import 'package:stackwallet/pages_desktop_specific/my_stack_view/wallet_view/sub_widgets/unlock_wallet_keys_desktop.dart'; import 'package:stackwallet/pages_desktop_specific/my_stack_view/wallet_view/sub_widgets/wallet_keys_desktop_popup.dart'; @@ -500,7 +499,7 @@ class RouteGenerator { return getRoute( shouldUseMaterialRoute: useMaterialPageRoute, builder: (_) => XPubView( - xpub: args, + walletId: args, ), settings: RouteSettings( name: settings.name, @@ -1687,19 +1686,6 @@ class RouteGenerator { } return _routeError("${settings.name} invalid args: ${args.toString()}"); - case DesktopShowXpubDialog.routeName: - if (args is String) { - return FadePageRoute( - DesktopShowXpubDialog( - walletId: args, - ), - RouteSettings( - name: settings.name, - ), - ); - } - return _routeError("${settings.name} invalid args: ${args.toString()}"); - case QRCodeDesktopPopupContent.routeName: if (args is String) { return FadePageRoute(