add change rep to desktop

This commit is contained in:
julian 2023-07-21 15:58:28 -06:00
parent a282e1607c
commit 3125a25a69
2 changed files with 125 additions and 13 deletions

View file

@ -87,6 +87,7 @@ class _XPubViewState extends ConsumerState<ChangeRepresentativeView> {
whileFuture: changeFuture(_textController.text), whileFuture: changeFuture(_textController.text),
context: context, context: context,
message: "Updating representative...", message: "Updating representative...",
isDesktop: Util.isDesktop,
onException: (ex) { onException: (ex) {
String msg = ex.toString(); String msg = ex.toString();
while (msg.isNotEmpty && msg.startsWith("Exception:")) { while (msg.isNotEmpty && msg.startsWith("Exception:")) {
@ -214,7 +215,7 @@ class _XPubViewState extends ConsumerState<ChangeRepresentativeView> {
left: 32, left: 32,
), ),
child: Text( child: Text(
"${ref.watch(walletsChangeNotifierProvider.select((value) => value.getManager(widget.walletId).walletName))} xPub", "Change representative",
style: STextStyles.desktopH2(context), style: STextStyles.desktopH2(context),
), ),
), ),
@ -240,7 +241,7 @@ class _XPubViewState extends ConsumerState<ChangeRepresentativeView> {
), ),
child: Column( child: Column(
children: [ children: [
if (isDesktop) const SizedBox(height: 44), if (isDesktop) const SizedBox(height: 24),
ConditionalParent( ConditionalParent(
condition: !isDesktop, condition: !isDesktop,
builder: (child) => Expanded( builder: (child) => Expanded(
@ -269,15 +270,48 @@ class _XPubViewState extends ConsumerState<ChangeRepresentativeView> {
} else { } else {
child = Column( child = Column(
children: [ children: [
RoundedWhiteContainer( ConditionalParent(
child: Column( condition: !isDesktop,
crossAxisAlignment: CrossAxisAlignment.start, builder: (child) => RoundedWhiteContainer(
children: [ child: Column(
Text( crossAxisAlignment: CrossAxisAlignment.start,
representative!, children: [
style: STextStyles.itemSubtitle(context), child,
), ],
], ),
),
child: ConditionalParent(
condition: isDesktop,
builder: (child) => Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
"Current representative",
style: STextStyles.desktopTextExtraExtraSmall(
context),
),
const SizedBox(
height: 4,
),
child,
],
),
child: Row(
children: [
SelectableText(
representative!,
style: isDesktop
? STextStyles.desktopTextExtraExtraSmall(
context)
.copyWith(
color: Theme.of(context)
.extension<StackColors>()!
.textDark,
)
: STextStyles.itemSubtitle12(context),
),
],
),
), ),
), ),
const SizedBox( const SizedBox(
@ -337,6 +371,7 @@ class _XPubViewState extends ConsumerState<ChangeRepresentativeView> {
), ),
), ),
), ),
if (isDesktop) const SizedBox(height: 60),
if (!isDesktop) const Spacer(), if (!isDesktop) const Spacer(),
PrimaryButton( PrimaryButton(
label: "Save", label: "Save",

View file

@ -13,6 +13,7 @@ import 'dart:async';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_svg/svg.dart'; import 'package:flutter_svg/svg.dart';
import 'package:stackwallet/pages/settings_views/wallet_settings_view/wallet_settings_wallet_settings/change_representative_view.dart';
import 'package:stackwallet/pages/settings_views/wallet_settings_view/wallet_settings_wallet_settings/xpub_view.dart'; import 'package:stackwallet/pages/settings_views/wallet_settings_view/wallet_settings_wallet_settings/xpub_view.dart';
import 'package:stackwallet/pages_desktop_specific/addresses/desktop_wallet_addresses_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_delete_wallet_dialog.dart';
@ -21,11 +22,13 @@ import 'package:stackwallet/route_generator.dart';
import 'package:stackwallet/themes/stack_colors.dart'; import 'package:stackwallet/themes/stack_colors.dart';
import 'package:stackwallet/utilities/assets.dart'; import 'package:stackwallet/utilities/assets.dart';
import 'package:stackwallet/utilities/constants.dart'; import 'package:stackwallet/utilities/constants.dart';
import 'package:stackwallet/utilities/enums/coin_enum.dart';
import 'package:stackwallet/utilities/text_styles.dart'; import 'package:stackwallet/utilities/text_styles.dart';
enum _WalletOptions { enum _WalletOptions {
addressList, addressList,
deleteWallet, deleteWallet,
changeRepresentative,
showXpub; showXpub;
String get prettyName { String get prettyName {
@ -34,6 +37,8 @@ enum _WalletOptions {
return "Address list"; return "Address list";
case _WalletOptions.deleteWallet: case _WalletOptions.deleteWallet:
return "Delete wallet"; return "Delete wallet";
case _WalletOptions.changeRepresentative:
return "Change representative";
case _WalletOptions.showXpub: case _WalletOptions.showXpub:
return "Show xPub"; return "Show xPub";
} }
@ -70,6 +75,9 @@ class WalletOptionsButton extends StatelessWidget {
onAddressListPressed: () async { onAddressListPressed: () async {
Navigator.of(context).pop(_WalletOptions.addressList); Navigator.of(context).pop(_WalletOptions.addressList);
}, },
onChangeRepPressed: () async {
Navigator.of(context).pop(_WalletOptions.changeRepresentative);
},
onShowXpubPressed: () async { onShowXpubPressed: () async {
Navigator.of(context).pop(_WalletOptions.showXpub); Navigator.of(context).pop(_WalletOptions.showXpub);
}, },
@ -134,6 +142,32 @@ class WalletOptionsButton extends StatelessWidget {
), ),
); );
if (result == true) {
if (context.mounted) {
Navigator.of(context).pop();
}
}
break;
case _WalletOptions.changeRepresentative:
final result = await showDialog<bool?>(
context: context,
barrierDismissible: false,
builder: (context) => Navigator(
initialRoute: ChangeRepresentativeView.routeName,
onGenerateRoute: RouteGenerator.generateRoute,
onGenerateInitialRoutes: (_, __) {
return [
RouteGenerator.generateRoute(
RouteSettings(
name: ChangeRepresentativeView.routeName,
arguments: walletId,
),
),
];
},
),
);
if (result == true) { if (result == true) {
if (context.mounted) { if (context.mounted) {
Navigator.of(context).pop(); Navigator.of(context).pop();
@ -171,18 +205,24 @@ class WalletOptionsPopupMenu extends ConsumerWidget {
required this.onDeletePressed, required this.onDeletePressed,
required this.onAddressListPressed, required this.onAddressListPressed,
required this.onShowXpubPressed, required this.onShowXpubPressed,
required this.onChangeRepPressed,
required this.walletId, required this.walletId,
}) : super(key: key); }) : super(key: key);
final VoidCallback onDeletePressed; final VoidCallback onDeletePressed;
final VoidCallback onAddressListPressed; final VoidCallback onAddressListPressed;
final VoidCallback onShowXpubPressed; final VoidCallback onShowXpubPressed;
final VoidCallback onChangeRepPressed;
final String walletId; final String walletId;
@override @override
Widget build(BuildContext context, WidgetRef ref) { Widget build(BuildContext context, WidgetRef ref) {
final bool xpubEnabled = ref.watch(walletsChangeNotifierProvider final manager = ref.watch(walletsChangeNotifierProvider
.select((value) => value.getManager(walletId).hasXPub)); .select((value) => value.getManager(walletId)));
final bool xpubEnabled = manager.hasXPub;
final bool canChangeRep =
manager.coin == Coin.nano || manager.coin == Coin.banano;
return Stack( return Stack(
children: [ children: [
@ -237,6 +277,43 @@ class WalletOptionsPopupMenu extends ConsumerWidget {
), ),
), ),
), ),
if (canChangeRep)
const SizedBox(
height: 8,
),
if (canChangeRep)
TransparentButton(
onPressed: onChangeRepPressed,
child: Padding(
padding: const EdgeInsets.all(8),
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
SvgPicture.asset(
Assets.svg.eye,
width: 20,
height: 20,
color: Theme.of(context)
.extension<StackColors>()!
.textFieldActiveSearchIconLeft,
),
const SizedBox(width: 14),
Expanded(
child: Text(
_WalletOptions.changeRepresentative.prettyName,
style: STextStyles.desktopTextExtraExtraSmall(
context)
.copyWith(
color: Theme.of(context)
.extension<StackColors>()!
.textDark,
),
),
),
],
),
),
),
if (xpubEnabled) if (xpubEnabled)
const SizedBox( const SizedBox(
height: 8, height: 8,