diff --git a/lib/pages/wallet_view/sub_widgets/wallet_navigation_bar.dart b/lib/pages/wallet_view/sub_widgets/wallet_navigation_bar.dart index 19a785de5..7f1c9c757 100644 --- a/lib/pages/wallet_view/sub_widgets/wallet_navigation_bar.dart +++ b/lib/pages/wallet_view/sub_widgets/wallet_navigation_bar.dart @@ -50,6 +50,11 @@ class _WalletNavigationBarState extends ConsumerState { @override Widget build(BuildContext context) { + final showMore = ref.watch(walletsChangeNotifierProvider.select( + (value) => value.getManager(widget.walletId).hasPaynymSupport)) || + ref.watch(walletsChangeNotifierProvider.select((value) => + value.getManager(widget.walletId).hasCoinControlSupport)); + return Column( mainAxisAlignment: MainAxisAlignment.end, crossAxisAlignment: CrossAxisAlignment.end, @@ -97,62 +102,20 @@ class _WalletNavigationBarState extends ConsumerState { // const SizedBox( // height: 8, // ), - AnimatedOpacity( - opacity: scale, - duration: duration, - child: Consumer(builder: (context, ref, __) { - return GestureDetector( - onTap: () async { - setState(() { - scale = 0; - }); - unawaited( - showDialog( - context: context, - builder: (context) => const LoadingIndicator( - width: 100, - ), - ), - ); - - final manager = ref - .read(walletsChangeNotifierProvider) - .getManager(widget.walletId); - - final paynymInterface = - manager.wallet as PaynymWalletInterface; - - final code = await paynymInterface.getPaymentCode( - DerivePathTypeExt.primaryFor(manager.coin)); - - final account = await ref - .read(paynymAPIProvider) - .nym(code.toString()); - - Logging.instance.log( - "my nym account: $account", - level: LogLevel.Info, - ); - + if (ref.watch(walletsChangeNotifierProvider.select((value) => + value.getManager(widget.walletId).hasCoinControlSupport))) + AnimatedOpacity( + opacity: scale, + duration: duration, + child: GestureDetector( + onTap: () { if (mounted) { Navigator.of(context).pop(); - // check if account exists and for matching code to see if claimed - if (account.value != null && - account.value!.codes.first.claimed) { - ref.read(myPaynymAccountStateProvider.state).state = - account.value!; - - await Navigator.of(context).pushNamed( - PaynymHomeView.routeName, - arguments: widget.walletId, - ); - } else { - await Navigator.of(context).pushNamed( - PaynymClaimView.routeName, - arguments: widget.walletId, - ); - } + // Navigator.of(context).pushNamed( + // PaynymHomeView.routeName, + // arguments: widget.walletId, + // ); } }, child: Container( @@ -174,14 +137,14 @@ class _WalletNavigationBarState extends ConsumerState { mainAxisAlignment: MainAxisAlignment.center, children: [ Text( - "Paynym", + "Coin control", style: STextStyles.buttonSmall(context), ), const SizedBox( width: 16, ), SvgPicture.asset( - Assets.svg.robotHead, + Assets.svg.coinControl.gamePad, height: 20, width: 20, color: Theme.of(context) @@ -191,9 +154,117 @@ class _WalletNavigationBarState extends ConsumerState { ], ), ), - ); - }), - ), + ), + ), + if (ref.watch(walletsChangeNotifierProvider.select((value) => + value + .getManager(widget.walletId) + .hasCoinControlSupport)) && + ref.watch(walletsChangeNotifierProvider.select((value) => + value.getManager(widget.walletId).hasPaynymSupport))) + const SizedBox( + height: 8, + ), + if (ref.watch(walletsChangeNotifierProvider.select((value) => + value.getManager(widget.walletId).hasPaynymSupport))) + AnimatedOpacity( + opacity: scale, + duration: duration, + child: Consumer(builder: (context, ref, __) { + return GestureDetector( + onTap: () async { + setState(() { + scale = 0; + }); + unawaited( + showDialog( + context: context, + builder: (context) => const LoadingIndicator( + width: 100, + ), + ), + ); + + final manager = ref + .read(walletsChangeNotifierProvider) + .getManager(widget.walletId); + + final paynymInterface = + manager.wallet as PaynymWalletInterface; + + final code = await paynymInterface.getPaymentCode( + DerivePathTypeExt.primaryFor(manager.coin)); + + final account = await ref + .read(paynymAPIProvider) + .nym(code.toString()); + + Logging.instance.log( + "my nym account: $account", + level: LogLevel.Info, + ); + + if (mounted) { + Navigator.of(context).pop(); + + // check if account exists and for matching code to see if claimed + if (account.value != null && + account.value!.codes.first.claimed) { + ref.read(myPaynymAccountStateProvider.state).state = + account.value!; + + await Navigator.of(context).pushNamed( + PaynymHomeView.routeName, + arguments: widget.walletId, + ); + } else { + await Navigator.of(context).pushNamed( + PaynymClaimView.routeName, + arguments: widget.walletId, + ); + } + } + }, + child: Container( + padding: const EdgeInsets.all(16), + width: 146, + decoration: BoxDecoration( + color: Theme.of(context) + .extension()! + .popupBG, + boxShadow: [ + Theme.of(context) + .extension()! + .standardBoxShadow + ], + borderRadius: BorderRadius.circular( + widget.height / 2.0, + ), + ), + child: Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Text( + "Paynym", + style: STextStyles.buttonSmall(context), + ), + const SizedBox( + width: 16, + ), + SvgPicture.asset( + Assets.svg.robotHead, + height: 20, + width: 20, + color: Theme.of(context) + .extension()! + .bottomNavIconIcon, + ), + ], + ), + ), + ); + }), + ), const SizedBox( height: 8, ), @@ -410,8 +481,7 @@ class _WalletNavigationBarState extends ConsumerState { ), ), ), - if (ref.watch(walletsChangeNotifierProvider.select((value) => - value.getManager(widget.walletId).hasPaynymSupport))) + if (showMore) RawMaterialButton( constraints: const BoxConstraints( minWidth: 66, diff --git a/lib/services/coins/bitcoin/bitcoin_wallet.dart b/lib/services/coins/bitcoin/bitcoin_wallet.dart index 25a74e7b9..b2909a53b 100644 --- a/lib/services/coins/bitcoin/bitcoin_wallet.dart +++ b/lib/services/coins/bitcoin/bitcoin_wallet.dart @@ -24,6 +24,7 @@ import 'package:stackwallet/services/event_bus/events/global/refresh_percent_cha import 'package:stackwallet/services/event_bus/events/global/updated_in_background_event.dart'; import 'package:stackwallet/services/event_bus/events/global/wallet_sync_status_changed_event.dart'; import 'package:stackwallet/services/event_bus/global_event_bus.dart'; +import 'package:stackwallet/services/mixins/coin_control_interface.dart'; import 'package:stackwallet/services/mixins/electrum_x_parsing.dart'; import 'package:stackwallet/services/mixins/paynym_wallet_interface.dart'; import 'package:stackwallet/services/mixins/wallet_cache.dart'; @@ -94,7 +95,12 @@ String constructDerivePath({ } class BitcoinWallet extends CoinServiceAPI - with WalletCache, WalletDB, ElectrumXParsing, PaynymWalletInterface { + with + WalletCache, + WalletDB, + ElectrumXParsing, + PaynymWalletInterface, + CoinControlInterface { BitcoinWallet({ required String walletId, required String walletName, diff --git a/lib/services/coins/manager.dart b/lib/services/coins/manager.dart index a15d227c6..38dc938b3 100644 --- a/lib/services/coins/manager.dart +++ b/lib/services/coins/manager.dart @@ -10,6 +10,7 @@ import 'package:stackwallet/services/coins/coin_service.dart'; import 'package:stackwallet/services/event_bus/events/global/node_connection_status_changed_event.dart'; import 'package:stackwallet/services/event_bus/events/global/updated_in_background_event.dart'; import 'package:stackwallet/services/event_bus/global_event_bus.dart'; +import 'package:stackwallet/services/mixins/coin_control_interface.dart'; import 'package:stackwallet/services/mixins/paynym_wallet_interface.dart'; import 'package:stackwallet/utilities/enums/coin_enum.dart'; import 'package:stackwallet/utilities/logger.dart'; @@ -229,6 +230,8 @@ class Manager with ChangeNotifier { bool get hasPaynymSupport => _currentWallet is PaynymWalletInterface; + bool get hasCoinControlSupport => _currentWallet is CoinControlInterface; + int get rescanOnOpenVersion => DB.instance.get( boxName: DB.boxNameDBInfo, diff --git a/lib/services/mixins/coin_control_interface.dart b/lib/services/mixins/coin_control_interface.dart new file mode 100644 index 000000000..c4a68ade9 --- /dev/null +++ b/lib/services/mixins/coin_control_interface.dart @@ -0,0 +1,3 @@ +mixin CoinControlInterface { + // +} diff --git a/lib/utilities/assets.dart b/lib/utilities/assets.dart index fdad0cd3c..90ba2557b 100644 --- a/lib/utilities/assets.dart +++ b/lib/utilities/assets.dart @@ -60,7 +60,7 @@ class _COIN_CONTROL { class _SVG { const _SVG(); - static const coinControl = _COIN_CONTROL(); + final coinControl = const _COIN_CONTROL(); String? background(BuildContext context) { switch (Theme.of(context).extension()!.themeType) { diff --git a/pubspec.yaml b/pubspec.yaml index 9e610128c..1b0de860e 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -324,6 +324,9 @@ flutter: # coin icons - assets/svg/coin_icons/ + # coin control icons + - assets/svg/coin_control/ + # lottie animations - assets/lottie/test.json - assets/lottie/test2.json