Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "Wallet xPub" page #20

Closed
wants to merge 25 commits into from
Closed
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
f34cc62
add Show xPub dot option on desktop
sneurlax Apr 5, 2023
15047f0
add desktop show xpub dialog
sneurlax Apr 5, 2023
68505cd
cherrypick merge conflict resolution
sneurlax Apr 6, 2023
73c5e66
add copy to clipboard functionality
sneurlax Apr 6, 2023
35aa06e
add padding like in other dialogs
sneurlax Apr 6, 2023
7350c6f
disable xpub wallet option for monero, wownero, and firo
sneurlax Apr 6, 2023
c251f5a
add xpub option to More menu in mobile wallet view
sneurlax Apr 6, 2023
c9b784e
change copy to clipboard button color
sneurlax Apr 6, 2023
f665e26
add copy to clipboard button to mobile xpub dialog
sneurlax Apr 6, 2023
22ae3dd
add qr dialog for mobile
sneurlax Apr 6, 2023
25602e3
change copy to clipboard text in desktop xpub dialog
sneurlax Apr 6, 2023
471a7a0
add xpub nav icon
sneurlax Apr 6, 2023
0e06a35
remove qr dialog and xpub nav icon
sneurlax Apr 6, 2023
082d9b0
remove show xpub item from mobile more dialog
sneurlax Apr 6, 2023
8da1dde
add stub xpub settings view
sneurlax Apr 6, 2023
9a77e7e
add working xpub settings view with click to copy to clipboard
sneurlax Apr 6, 2023
feccd50
add copy icon to top right of xpub view
sneurlax Apr 6, 2023
3dc3046
stackwallet -> stackduo
sneurlax Apr 6, 2023
06777d2
remove non-monero coin references
sneurlax Apr 6, 2023
8754c3a
remove non-monero coin references
sneurlax Apr 6, 2023
d7f2d35
remove non-monero coin references
sneurlax Apr 6, 2023
525e6cb
remove buy references from stack_wallet cherry-pick
sneurlax Apr 6, 2023
d5fb446
remove buy references from stack_wallet cherry-pick
sneurlax Apr 6, 2023
f0c27a5
remove references to non-duo coins
sneurlax Apr 6, 2023
5f9fda2
add text to desktop xpub dialog
sneurlax Apr 6, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
125 changes: 125 additions & 0 deletions lib/pages/settings_views/global_settings_view/xpub_view.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
import 'dart:async';

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_svg/svg.dart';
import 'package:qr_flutter/qr_flutter.dart';
import 'package:stackduo/notifications/show_flush_bar.dart';
import 'package:stackduo/utilities/assets.dart';
import 'package:stackduo/utilities/clipboard_interface.dart';
import 'package:stackduo/utilities/text_styles.dart';
import 'package:stackduo/utilities/theme/stack_colors.dart';
import 'package:stackduo/widgets/background.dart';
import 'package:stackduo/widgets/custom_buttons/app_bar_icon_button.dart';
import 'package:stackduo/widgets/rounded_white_container.dart';

class XPubView extends ConsumerStatefulWidget {
const XPubView({
Key? key,
this.xpub,
this.clipboardInterface = const ClipboardWrapper(),
}) : super(key: key);

final String? xpub;
final ClipboardInterface clipboardInterface;

static const String routeName = "/xpub";

@override
ConsumerState<XPubView> createState() => _XPubViewState();
}

class _XPubViewState extends ConsumerState<XPubView> {
late ClipboardInterface _clipboardInterface;

@override
void initState() {
_clipboardInterface = widget.clipboardInterface;
super.initState();
}

@override
void dispose() {
super.dispose();
}

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,
));
}

@override
Widget build(BuildContext context) {
return Background(
child: Scaffold(
backgroundColor: Theme.of(context).extension<StackColors>()!.background,
appBar: AppBar(
leading: AppBarBackButton(
onPressed: () async {
Navigator.of(context).pop();
},
),
title: Text(
"Wallet xPub",
style: STextStyles.navBarTitle(context),
),
actions: [
Padding(
padding: const EdgeInsets.all(10),
child: AspectRatio(
aspectRatio: 1,
child: AppBarIconButton(
color:
Theme.of(context).extension<StackColors>()!.background,
shadows: const [],
icon: SvgPicture.asset(
Assets.svg.copy,
width: 24,
height: 24,
color: Theme.of(context)
.extension<StackColors>()!
.topNavIconPrimary,
),
onPressed: () async {
await _copy();
},
),
),
),
]),
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(),
),
if (widget.xpub != null)
const SizedBox(
height: 8,
),
if (widget.xpub != null)
RoundedWhiteContainer(
padding: const EdgeInsets.all(12),
child: Text(widget.xpub!,
style: STextStyles.largeMedium14(context)),
onPressed: () => _copy(),
)
]),
),
),
);
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import 'dart:async';

import 'package:bip32/bip32.dart' as bip32;
import 'package:bip39/bip39.dart' as bip39;
import 'package:event_bus/event_bus.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:stackduo/notifications/show_flush_bar.dart';
import 'package:stackduo/pages/address_book_views/address_book_view.dart';
import 'package:stackduo/pages/home_view/home_view.dart';
import 'package:stackduo/pages/pinpad_views/lock_screen_view.dart';
import 'package:stackduo/pages/settings_views/global_settings_view/advanced_views/debug_view.dart';
import 'package:stackduo/pages/settings_views/global_settings_view/syncing_preferences_views/syncing_preferences_view.dart';
import 'package:stackduo/pages/settings_views/global_settings_view/xpub_view.dart';
import 'package:stackduo/pages/settings_views/sub_widgets/settings_list_button.dart';
import 'package:stackduo/pages/settings_views/wallet_settings_view/wallet_backup_views/wallet_backup_view.dart';
import 'package:stackduo/pages/settings_views/wallet_settings_view/wallet_network_settings_view/wallet_network_settings_view.dart';
Expand All @@ -23,7 +25,6 @@ import 'package:stackduo/utilities/assets.dart';
import 'package:stackduo/utilities/enums/coin_enum.dart';
import 'package:stackduo/utilities/text_styles.dart';
import 'package:stackduo/utilities/theme/stack_colors.dart';
import 'package:stackduo/utilities/util.dart';
import 'package:stackduo/widgets/background.dart';
import 'package:stackduo/widgets/custom_buttons/app_bar_icon_button.dart';
import 'package:stackduo/widgets/rounded_white_container.dart';
Expand Down Expand Up @@ -55,6 +56,8 @@ class WalletSettingsView extends StatefulWidget {
class _WalletSettingsViewState extends State<WalletSettingsView> {
late final String walletId;
late final Coin coin;
late String xpub;
late final bool xPubEnabled;

late final EventBus eventBus;

Expand All @@ -68,6 +71,8 @@ class _WalletSettingsViewState extends State<WalletSettingsView> {
void initState() {
walletId = widget.walletId;
coin = widget.coin;
xPubEnabled = coin != Coin.monero;
xpub = "";

_currentSyncStatus = widget.initialSyncStatus;
// _currentNodeStatus = widget.initialNodeStatus;
Expand Down Expand Up @@ -268,6 +273,37 @@ class _WalletSettingsViewState extends State<WalletSettingsView> {
SyncingPreferencesView.routeName);
},
),
if (xPubEnabled)
const SizedBox(
height: 8,
),
if (xPubEnabled)
Consumer(
builder: (_, ref, __) {
return SettingsListButton(
iconAssetName: Assets.svg.eye,
title: "Wallet xPub",
onPressed: () async {
final List<String> mnemonic = await ref
.read(
walletsChangeNotifierProvider)
.getManager(widget.walletId)
.mnemonic;

final seed = bip39.mnemonicToSeed(
mnemonic.join(' '));
final node =
bip32.BIP32.fromSeed(seed);
final xpub =
node.neutered().toBase58();

Navigator.of(context).pushNamed(
XPubView.routeName,
arguments: xpub);
},
);
},
),
const SizedBox(
height: 8,
),
Expand Down Expand Up @@ -328,73 +364,3 @@ class _WalletSettingsViewState extends State<WalletSettingsView> {
);
}
}

class EpicBoxInfoForm extends ConsumerStatefulWidget {
const EpicBoxInfoForm({
Key? key,
required this.walletId,
}) : super(key: key);

final String walletId;

@override
ConsumerState<EpicBoxInfoForm> createState() => _EpiBoxInfoFormState();
}

class _EpiBoxInfoFormState extends ConsumerState<EpicBoxInfoForm> {
final hostController = TextEditingController();
final portController = TextEditingController();

@override
void initState() {
super.initState();
}

@override
void dispose() {
hostController.dispose();
portController.dispose();
super.dispose();
}

@override
Widget build(BuildContext context) {
return RoundedWhiteContainer(
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
TextField(
autocorrect: Util.isDesktop ? false : true,
enableSuggestions: Util.isDesktop ? false : true,
controller: hostController,
decoration: const InputDecoration(hintText: "Host"),
),
const SizedBox(
height: 8,
),
TextField(
autocorrect: Util.isDesktop ? false : true,
enableSuggestions: Util.isDesktop ? false : true,
controller: portController,
decoration: const InputDecoration(hintText: "Port"),
keyboardType:
Util.isDesktop ? null : const TextInputType.numberWithOptions(),
),
const SizedBox(
height: 8,
),
TextButton(
onPressed: () async {},
child: Text(
"Save",
style: STextStyles.button(context).copyWith(
color: Theme.of(context)
.extension<StackColors>()!
.accentColorDark),
),
),
],
),
);
}
}
11 changes: 9 additions & 2 deletions lib/pages/wallet_view/wallet_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import 'package:stackduo/services/event_bus/global_event_bus.dart';
import 'package:stackduo/services/exchange/exchange_data_loading_service.dart';
import 'package:stackduo/services/mixins/paynym_wallet_interface.dart';
import 'package:stackduo/utilities/assets.dart';
import 'package:stackduo/utilities/clipboard_interface.dart';
import 'package:stackduo/utilities/constants.dart';
import 'package:stackduo/utilities/enums/backup_frequency_type.dart';
import 'package:stackduo/utilities/enums/coin_enum.dart';
Expand Down Expand Up @@ -66,6 +67,7 @@ class WalletView extends ConsumerStatefulWidget {
required this.walletId,
required this.managerProvider,
this.eventBus,
this.clipboardInterface = const ClipboardWrapper(),
}) : super(key: key);

static const String routeName = "/wallet";
Expand All @@ -75,6 +77,8 @@ class WalletView extends ConsumerStatefulWidget {
final ChangeNotifierProvider<Manager> managerProvider;
final EventBus? eventBus;

final ClipboardInterface clipboardInterface;

@override
ConsumerState<WalletView> createState() => _WalletViewState();
}
Expand All @@ -94,10 +98,13 @@ class _WalletViewState extends ConsumerState<WalletView> {

bool _rescanningOnOpen = false;

late ClipboardInterface _clipboardInterface;

@override
void initState() {
walletId = widget.walletId;
managerProvider = widget.managerProvider;
_clipboardInterface = widget.clipboardInterface;

ref.read(managerProvider).isActiveWallet = true;
if (!ref.read(managerProvider).shouldAutoSync) {
Expand Down Expand Up @@ -254,7 +261,7 @@ class _WalletViewState extends ConsumerState<WalletView> {
}

void _onExchangePressed(BuildContext context) async {
final coin = ref.read(managerProvider).coin;
final Coin coin = ref.read(managerProvider).coin;

if (coin.isTestNet) {
await showDialog<void>(
Expand Down Expand Up @@ -306,7 +313,7 @@ class _WalletViewState extends ConsumerState<WalletView> {
Widget build(BuildContext context) {
debugPrint("BUILD: $runtimeType");

final coin = ref.watch(managerProvider.select((value) => value.coin));
final Coin coin = ref.watch(managerProvider.select((value) => value.coin));

return ConditionalParent(
condition: _rescanningOnOpen,
Expand Down
Loading