From e2cc371f995044086706fa383dfdc5a4e5122c55 Mon Sep 17 00:00:00 2001 From: julian Date: Tue, 11 Apr 2023 14:57:19 -0600 Subject: [PATCH] add token fees to fee dropdown on desktop --- .../sub_widgets/desktop_fee_dropdown.dart | 105 +++++++++++------- .../sub_widgets/desktop_token_send.dart | 2 +- 2 files changed, 64 insertions(+), 43 deletions(-) diff --git a/lib/pages_desktop_specific/my_stack_view/wallet_view/sub_widgets/desktop_fee_dropdown.dart b/lib/pages_desktop_specific/my_stack_view/wallet_view/sub_widgets/desktop_fee_dropdown.dart index 9bd260a34..f2da6b9ac 100644 --- a/lib/pages_desktop_specific/my_stack_view/wallet_view/sub_widgets/desktop_fee_dropdown.dart +++ b/lib/pages_desktop_specific/my_stack_view/wallet_view/sub_widgets/desktop_fee_dropdown.dart @@ -5,6 +5,7 @@ import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:flutter_svg/svg.dart'; import 'package:stackwallet/models/models.dart'; import 'package:stackwallet/pages/send_view/sub_widgets/transaction_fee_selection_sheet.dart'; +import 'package:stackwallet/pages/token_view/token_view.dart'; import 'package:stackwallet/providers/global/wallets_provider.dart'; import 'package:stackwallet/providers/ui/fee_rate_type_state_provider.dart'; import 'package:stackwallet/providers/wallet/public_private_balance_state_provider.dart'; @@ -22,9 +23,11 @@ class DesktopFeeDropDown extends ConsumerStatefulWidget { const DesktopFeeDropDown({ Key? key, required this.walletId, + this.isToken = false, }) : super(key: key); final String walletId; + final bool isToken; @override ConsumerState createState() => _DesktopFeeDropDownState(); @@ -52,66 +55,84 @@ class _DesktopFeeDropDownState extends ConsumerState { switch (feeRateType) { case FeeRateType.fast: if (ref.read(feeSheetSessionCacheProvider).fast[amount] == null) { - final manager = - ref.read(walletsChangeNotifierProvider).getManager(walletId); + if (widget.isToken == false) { + final manager = + ref.read(walletsChangeNotifierProvider).getManager(walletId); - if (coin == Coin.monero || coin == Coin.wownero) { - final fee = await manager.estimateFeeFor( - amount, MoneroTransactionPriority.fast.raw!); - ref.read(feeSheetSessionCacheProvider).fast[amount] = fee; - } else if ((coin == Coin.firo || coin == Coin.firoTestNet) && - ref.read(publicPrivateBalanceStateProvider.state).state != - "Private") { - ref.read(feeSheetSessionCacheProvider).fast[amount] = - await (manager.wallet as FiroWallet) - .estimateFeeForPublic(amount, feeRate); + if (coin == Coin.monero || coin == Coin.wownero) { + final fee = await manager.estimateFeeFor( + amount, MoneroTransactionPriority.fast.raw!); + ref.read(feeSheetSessionCacheProvider).fast[amount] = fee; + } else if ((coin == Coin.firo || coin == Coin.firoTestNet) && + ref.read(publicPrivateBalanceStateProvider.state).state != + "Private") { + ref.read(feeSheetSessionCacheProvider).fast[amount] = + await (manager.wallet as FiroWallet) + .estimateFeeForPublic(amount, feeRate); + } else { + ref.read(feeSheetSessionCacheProvider).fast[amount] = + await manager.estimateFeeFor(amount, feeRate); + } } else { - ref.read(feeSheetSessionCacheProvider).fast[amount] = - await manager.estimateFeeFor(amount, feeRate); + final tokenWallet = ref.read(tokenServiceProvider)!; + final fee = tokenWallet.estimateFeeFor(feeRate); + ref.read(feeSheetSessionCacheProvider).fast[amount] = fee; } } return ref.read(feeSheetSessionCacheProvider).fast[amount]!; case FeeRateType.average: if (ref.read(feeSheetSessionCacheProvider).average[amount] == null) { - final manager = - ref.read(walletsChangeNotifierProvider).getManager(walletId); + if (widget.isToken == false) { + 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) && - ref.read(publicPrivateBalanceStateProvider.state).state != - "Private") { - ref.read(feeSheetSessionCacheProvider).average[amount] = - await (manager.wallet as FiroWallet) - .estimateFeeForPublic(amount, feeRate); + 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) && + 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); + } } else { - ref.read(feeSheetSessionCacheProvider).average[amount] = - await manager.estimateFeeFor(amount, feeRate); + final tokenWallet = ref.read(tokenServiceProvider)!; + final fee = tokenWallet.estimateFeeFor(feeRate); + ref.read(feeSheetSessionCacheProvider).average[amount] = fee; } } return ref.read(feeSheetSessionCacheProvider).average[amount]!; case FeeRateType.slow: if (ref.read(feeSheetSessionCacheProvider).slow[amount] == null) { - final manager = - ref.read(walletsChangeNotifierProvider).getManager(walletId); + if (widget.isToken == false) { + final manager = + ref.read(walletsChangeNotifierProvider).getManager(walletId); - if (coin == Coin.monero || coin == Coin.wownero) { - final fee = await manager.estimateFeeFor( - amount, MoneroTransactionPriority.slow.raw!); - ref.read(feeSheetSessionCacheProvider).slow[amount] = fee; - } else if ((coin == Coin.firo || coin == Coin.firoTestNet) && - ref.read(publicPrivateBalanceStateProvider.state).state != - "Private") { - ref.read(feeSheetSessionCacheProvider).slow[amount] = - await (manager.wallet as FiroWallet) - .estimateFeeForPublic(amount, feeRate); + if (coin == Coin.monero || coin == Coin.wownero) { + final fee = await manager.estimateFeeFor( + amount, MoneroTransactionPriority.slow.raw!); + ref.read(feeSheetSessionCacheProvider).slow[amount] = fee; + } else if ((coin == Coin.firo || coin == Coin.firoTestNet) && + ref.read(publicPrivateBalanceStateProvider.state).state != + "Private") { + ref.read(feeSheetSessionCacheProvider).slow[amount] = + await (manager.wallet as FiroWallet) + .estimateFeeForPublic(amount, feeRate); + } else { + ref.read(feeSheetSessionCacheProvider).slow[amount] = + await manager.estimateFeeFor(amount, feeRate); + } } else { - ref.read(feeSheetSessionCacheProvider).slow[amount] = - await manager.estimateFeeFor(amount, feeRate); + final tokenWallet = ref.read(tokenServiceProvider)!; + final fee = tokenWallet.estimateFeeFor(feeRate); + ref.read(feeSheetSessionCacheProvider).slow[amount] = fee; } } return ref.read(feeSheetSessionCacheProvider).slow[amount]!; diff --git a/lib/pages_desktop_specific/my_stack_view/wallet_view/sub_widgets/desktop_token_send.dart b/lib/pages_desktop_specific/my_stack_view/wallet_view/sub_widgets/desktop_token_send.dart index 0f16a3cd0..b6f0d9ebe 100644 --- a/lib/pages_desktop_specific/my_stack_view/wallet_view/sub_widgets/desktop_token_send.dart +++ b/lib/pages_desktop_specific/my_stack_view/wallet_view/sub_widgets/desktop_token_send.dart @@ -1004,9 +1004,9 @@ class _DesktopTokenSendState extends ConsumerState { const SizedBox( height: 10, ), - // TODO mod this for token fees DesktopFeeDropDown( walletId: walletId, + isToken: true, ), const SizedBox( height: 20,