From c784d2cf048308f252fcd9726b30f22584d4df88 Mon Sep 17 00:00:00 2001 From: julian Date: Fri, 23 Jun 2023 13:35:19 -0600 Subject: [PATCH] fix: disable fee selection for firo private send on desktop --- .../wallet_view/sub_widgets/desktop_send.dart | 211 ++++++++++-------- lib/widgets/desktop/desktop_fee_dialog.dart | 56 ++++- 2 files changed, 167 insertions(+), 100 deletions(-) diff --git a/lib/pages_desktop_specific/my_stack_view/wallet_view/sub_widgets/desktop_send.dart b/lib/pages_desktop_specific/my_stack_view/wallet_view/sub_widgets/desktop_send.dart index d3588325c..a6d58c667 100644 --- a/lib/pages_desktop_specific/my_stack_view/wallet_view/sub_widgets/desktop_send.dart +++ b/lib/pages_desktop_specific/my_stack_view/wallet_view/sub_widgets/desktop_send.dart @@ -1369,7 +1369,10 @@ class _DesktopSendState extends ConsumerState { ), if (!([Coin.nano, Coin.banano, Coin.epicCash].contains(coin))) ConditionalParent( - condition: coin.isElectrumXCoin, + condition: coin.isElectrumXCoin && + !(((coin == Coin.firo || coin == Coin.firoTestNet) && + ref.read(publicPrivateBalanceStateProvider.state).state == + "Private")), builder: (child) => Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ @@ -1421,72 +1424,117 @@ class _DesktopSendState extends ConsumerState { ), if (!([Coin.nano, Coin.banano, Coin.epicCash].contains(coin))) if (!isCustomFee) - (feeSelectionResult?.$2 == null) - ? FutureBuilder( - future: ref.watch( - walletsChangeNotifierProvider.select( - (value) => value.getManager(walletId).fees, + Padding( + padding: const EdgeInsets.all(10), + child: (feeSelectionResult?.$2 == null) + ? FutureBuilder( + future: ref.watch( + walletsChangeNotifierProvider.select( + (value) => value.getManager(walletId).fees, + ), ), - ), - builder: (context, snapshot) { - if (snapshot.connectionState == ConnectionState.done && - snapshot.hasData) { - return DesktopFeeItem( - feeObject: snapshot.data, - feeRateType: FeeRateType.average, - walletId: walletId, - feeFor: ({ - required Amount amount, - required FeeRateType feeRateType, - required int feeRate, - required Coin coin, - }) async { - if (ref - .read(feeSheetSessionCacheProvider) - .average[amount] == - null) { - final manager = ref - .read(walletsChangeNotifierProvider) - .getManager(walletId); + builder: (context, snapshot) { + if (snapshot.connectionState == ConnectionState.done && + snapshot.hasData) { + return DesktopFeeItem( + feeObject: snapshot.data, + feeRateType: FeeRateType.average, + walletId: walletId, + isButton: false, + feeFor: ({ + required Amount amount, + required FeeRateType feeRateType, + required int feeRate, + required Coin coin, + }) async { + if (ref + .read(feeSheetSessionCacheProvider) + .average[amount] == + null) { + final manager = ref + .read(walletsChangeNotifierProvider) + .getManager(walletId); - if (coin == Coin.monero || coin == Coin.wownero) { - final fee = await manager.estimateFeeFor(amount, - MoneroTransactionPriority.regular.raw!); - ref - .read(feeSheetSessionCacheProvider) - .average[amount] = fee; - } else if ((coin == Coin.firo || - coin == Coin.firoTestNet) && + if (coin == Coin.monero || + coin == Coin.wownero) { + final fee = await manager.estimateFeeFor( + amount, + MoneroTransactionPriority.regular.raw!); ref - .read( - publicPrivateBalanceStateProvider - .state) - .state != - "Private") { - ref - .read(feeSheetSessionCacheProvider) - .average[amount] = - await (manager.wallet as FiroWallet) - .estimateFeeForPublic(amount, feeRate); - } else { - ref - .read(feeSheetSessionCacheProvider) - .average[amount] = - await manager.estimateFeeFor( - amount, feeRate); + .read(feeSheetSessionCacheProvider) + .average[amount] = fee; + } else if ((coin == Coin.firo || + coin == Coin.firoTestNet) && + ref + .read( + publicPrivateBalanceStateProvider + .state) + .state != + "Private") { + ref + .read(feeSheetSessionCacheProvider) + .average[amount] = await (manager.wallet + as FiroWallet) + .estimateFeeForPublic(amount, feeRate); + } else { + ref + .read(feeSheetSessionCacheProvider) + .average[amount] = + await manager.estimateFeeFor( + amount, feeRate); + } } - } - return ref - .read(feeSheetSessionCacheProvider) - .average[amount]!; - }, - isSelected: true, - ); - } else { - return Row( + return ref + .read(feeSheetSessionCacheProvider) + .average[amount]!; + }, + isSelected: true, + ); + } else { + return Row( + children: [ + AnimatedText( + stringsToLoopThrough: stringsToLoopThrough, + style: STextStyles.desktopTextExtraExtraSmall( + context) + .copyWith( + color: Theme.of(context) + .extension()! + .textFieldActiveText, + ), + ), + ], + ); + } + }, + ) + : (coin == Coin.firo || coin == Coin.firoTestNet) && + ref + .watch( + publicPrivateBalanceStateProvider.state) + .state == + "Private" + ? Text( + "~${ref.watch(pAmountFormatter(coin)).format( + Amount( + rawValue: BigInt.parse("3794"), + fractionDigits: coin.decimals, + ), + indicatePrecisionLoss: false, + )}", + style: STextStyles.desktopTextExtraExtraSmall(context) + .copyWith( + color: Theme.of(context) + .extension()! + .textFieldActiveText, + ), + textAlign: TextAlign.left, + ) + : Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ - AnimatedText( - stringsToLoopThrough: stringsToLoopThrough, + Text( + feeSelectionResult?.$2 ?? "", style: STextStyles.desktopTextExtraExtraSmall( context) .copyWith( @@ -1494,36 +1542,21 @@ class _DesktopSendState extends ConsumerState { .extension()! .textFieldActiveText, ), + textAlign: TextAlign.left, + ), + Text( + feeSelectionResult?.$3 ?? "", + style: STextStyles.desktopTextExtraExtraSmall( + context) + .copyWith( + color: Theme.of(context) + .extension()! + .textFieldActiveSearchIconRight, + ), ), ], - ); - } - }, - ) - : Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Text( - feeSelectionResult?.$2 ?? "", - style: STextStyles.desktopTextExtraExtraSmall(context) - .copyWith( - color: Theme.of(context) - .extension()! - .textFieldActiveText, ), - textAlign: TextAlign.left, - ), - Text( - feeSelectionResult?.$3 ?? "", - style: STextStyles.desktopTextExtraExtraSmall(context) - .copyWith( - color: Theme.of(context) - .extension()! - .textFieldActiveSearchIconRight, - ), - ), - ], - ), + ), if (isCustomFee) Padding( padding: const EdgeInsets.only( diff --git a/lib/widgets/desktop/desktop_fee_dialog.dart b/lib/widgets/desktop/desktop_fee_dialog.dart index f2c8c9fba..d9bf51190 100644 --- a/lib/widgets/desktop/desktop_fee_dialog.dart +++ b/lib/widgets/desktop/desktop_fee_dialog.dart @@ -16,6 +16,7 @@ import 'package:stackwallet/utilities/enums/coin_enum.dart'; import 'package:stackwallet/utilities/enums/fee_rate_type_enum.dart'; import 'package:stackwallet/utilities/text_styles.dart'; import 'package:stackwallet/widgets/animated_text.dart'; +import 'package:stackwallet/widgets/conditional_parent.dart'; import 'package:stackwallet/widgets/desktop/desktop_dialog.dart'; import 'package:stackwallet/widgets/desktop/desktop_dialog_close_button.dart'; @@ -234,6 +235,7 @@ class DesktopFeeItem extends ConsumerStatefulWidget { required this.walletId, required this.feeFor, required this.isSelected, + this.isButton = true, }) : super(key: key); final FeeObject? feeObject; @@ -246,6 +248,7 @@ class DesktopFeeItem extends ConsumerStatefulWidget { required Coin coin, }) feeFor; final bool isSelected; + final bool isButton; @override ConsumerState createState() => _DesktopFeeItemState(); @@ -291,19 +294,50 @@ class _DesktopFeeItemState extends ConsumerState { Widget build(BuildContext context) { debugPrint("BUILD: $runtimeType : ${widget.feeRateType}"); - return MaterialButton( - materialTapTargetSize: MaterialTapTargetSize.shrinkWrap, - onPressed: () { - Navigator.of(context).pop( - ( - widget.feeRateType, - feeString, - timeString, - ), - ); - }, + return ConditionalParent( + condition: widget.isButton, + builder: (child) => MaterialButton( + materialTapTargetSize: MaterialTapTargetSize.shrinkWrap, + onPressed: () { + Navigator.of(context).pop( + ( + widget.feeRateType, + feeString, + timeString, + ), + ); + }, + child: child, + ), child: Builder( builder: (_) { + if (!widget.isButton) { + final coin = ref.watch( + walletsChangeNotifierProvider.select( + (value) => value.getManager(widget.walletId).coin, + ), + ); + if ((coin == Coin.firo || coin == Coin.firoTestNet) && + ref.watch(publicPrivateBalanceStateProvider.state).state == + "Private") { + return Text( + "~${ref.watch(pAmountFormatter(coin)).format( + Amount( + rawValue: BigInt.parse("3794"), + fractionDigits: coin.decimals, + ), + indicatePrecisionLoss: false, + )}", + style: STextStyles.desktopTextExtraExtraSmall(context).copyWith( + color: Theme.of(context) + .extension()! + .textFieldActiveText, + ), + textAlign: TextAlign.left, + ); + } + } + if (widget.feeRateType == FeeRateType.custom) { return Row( mainAxisAlignment: MainAxisAlignment.spaceBetween,