WIP consolidate xpub view

This commit is contained in:
julian 2023-04-07 20:04:48 -06:00
parent 72d6e636f0
commit 6b88a1a4f1
4 changed files with 162 additions and 231 deletions

View file

@ -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<XPubView> {
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<XPubView> {
}
Future<void> _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<StackColors>()!.background,
appBar: AppBar(
return ConditionalParent(
condition: !isDesktop,
builder: (child) => Background(
child: Scaffold(
backgroundColor:
Theme.of(context).extension<StackColors>()!.background,
appBar: AppBar(
leading: AppBarBackButton(
onPressed: () async {
Navigator.of(context).pop();
@ -92,32 +115,131 @@ class _XPubViewState extends ConsumerState<XPubView> {
),
),
),
]),
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<String> 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<StackColors>()!
.accentColorDark,
),
),
const SizedBox(height: 25),
RoundedWhiteContainer(
padding: const EdgeInsets.all(16),
borderColor: xpub == null
? null
: Theme.of(context)
.extension<StackColors>()!
.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,
),
),
],
),
],
);
},
),
],
),
),
);

View file

@ -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<DesktopShowXpubDialog> createState() =>
_DesktopShowXpubDialog();
}
class _DesktopShowXpubDialog extends ConsumerState<DesktopShowXpubDialog> {
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<void> _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<String> 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<StackColors>()!
.accentColorDark,
),
const SizedBox(height: 25),
RoundedWhiteContainer(
padding: const EdgeInsets.all(16),
borderColor: xpub == null
? null
: Theme.of(context)
.extension<StackColors>()!
.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,
),
),
],
),
],
);
},
),
],
),
),
),
],
),
);
}
}

View file

@ -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,
),
),

View file

@ -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(