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 fc049e093..557d4549c 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 @@ -19,6 +19,11 @@ import 'package:stackwallet/utilities/text_styles.dart'; import 'package:stackwallet/utilities/theme/stack_colors.dart'; import 'package:stackwallet/widgets/animated_text.dart'; +final tokenFeeSessionCacheProvider = + ChangeNotifierProvider((ref) { + return FeeSheetSessionCache(); +}); + class DesktopFeeDropDown extends ConsumerStatefulWidget { const DesktopFeeDropDown({ Key? key, @@ -54,7 +59,12 @@ class _DesktopFeeDropDownState extends ConsumerState { }) async { switch (feeRateType) { case FeeRateType.fast: - if (ref.read(feeSheetSessionCacheProvider).fast[amount] == null) { + if (ref + .read(widget.isToken + ? tokenFeeSessionCacheProvider + : feeSheetSessionCacheProvider) + .fast[amount] == + null) { if (widget.isToken == false) { final manager = ref.read(walletsChangeNotifierProvider).getManager(walletId); @@ -76,13 +86,22 @@ class _DesktopFeeDropDownState extends ConsumerState { } else { final tokenWallet = ref.read(tokenServiceProvider)!; final fee = tokenWallet.estimateFeeFor(feeRate); - ref.read(feeSheetSessionCacheProvider).fast[amount] = fee; + ref.read(tokenFeeSessionCacheProvider).fast[amount] = fee; } } - return ref.read(feeSheetSessionCacheProvider).fast[amount]!; + return ref + .read(widget.isToken + ? tokenFeeSessionCacheProvider + : feeSheetSessionCacheProvider) + .fast[amount]!; case FeeRateType.average: - if (ref.read(feeSheetSessionCacheProvider).average[amount] == null) { + if (ref + .read(widget.isToken + ? tokenFeeSessionCacheProvider + : feeSheetSessionCacheProvider) + .average[amount] == + null) { if (widget.isToken == false) { final manager = ref.read(walletsChangeNotifierProvider).getManager(walletId); @@ -104,13 +123,22 @@ class _DesktopFeeDropDownState extends ConsumerState { } else { final tokenWallet = ref.read(tokenServiceProvider)!; final fee = tokenWallet.estimateFeeFor(feeRate); - ref.read(feeSheetSessionCacheProvider).average[amount] = fee; + ref.read(tokenFeeSessionCacheProvider).average[amount] = fee; } } - return ref.read(feeSheetSessionCacheProvider).average[amount]!; + return ref + .read(widget.isToken + ? tokenFeeSessionCacheProvider + : feeSheetSessionCacheProvider) + .average[amount]!; case FeeRateType.slow: - if (ref.read(feeSheetSessionCacheProvider).slow[amount] == null) { + if (ref + .read(widget.isToken + ? tokenFeeSessionCacheProvider + : feeSheetSessionCacheProvider) + .slow[amount] == + null) { if (widget.isToken == false) { final manager = ref.read(walletsChangeNotifierProvider).getManager(walletId); @@ -132,10 +160,14 @@ class _DesktopFeeDropDownState extends ConsumerState { } else { final tokenWallet = ref.read(tokenServiceProvider)!; final fee = tokenWallet.estimateFeeFor(feeRate); - ref.read(feeSheetSessionCacheProvider).slow[amount] = fee; + ref.read(tokenFeeSessionCacheProvider).slow[amount] = fee; } } - return ref.read(feeSheetSessionCacheProvider).slow[amount]!; + return ref + .read(widget.isToken + ? tokenFeeSessionCacheProvider + : 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 e418c4283..127798d4a 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 @@ -9,7 +9,6 @@ import 'package:stackwallet/models/paynym/paynym_account_lite.dart'; import 'package:stackwallet/models/send_view_auto_fill_data.dart'; import 'package:stackwallet/pages/send_view/confirm_transaction_view.dart'; import 'package:stackwallet/pages/send_view/sub_widgets/building_transaction_dialog.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/pages_desktop_specific/desktop_home_view.dart'; import 'package:stackwallet/pages_desktop_specific/my_stack_view/wallet_view/sub_widgets/address_book_address_chooser/address_book_address_chooser.dart'; @@ -416,7 +415,7 @@ class _DesktopTokenSendState extends ConsumerState { .read(walletsChangeNotifierProvider) .getManager(walletId) .validateAddress(address ?? ""); - ref.read(previewTxButtonStateProvider.state).state = + ref.read(previewTokenTxButtonStateProvider.state).state = (isValidAddress && amount != null && amount > Amount.zero); } @@ -574,8 +573,8 @@ class _DesktopTokenSendState extends ConsumerState { @override void initState() { WidgetsBinding.instance.addPostFrameCallback((_) { - ref.refresh(feeSheetSessionCacheProvider); - ref.read(previewTxButtonStateProvider.state).state = false; + ref.refresh(tokenFeeSessionCacheProvider); + ref.read(previewTokenTxButtonStateProvider.state).state = false; }); // _calculateFeesFuture = calculateFees(0); @@ -605,21 +604,25 @@ class _DesktopTokenSendState extends ConsumerState { _cryptoFocus.addListener(() { if (!_cryptoFocus.hasFocus && !_baseFocus.hasFocus) { - if (_amountToSend == null) { - ref.refresh(sendAmountProvider); - } else { - ref.read(sendAmountProvider.state).state = _amountToSend!; - } + WidgetsBinding.instance.addPostFrameCallback((_) { + if (_amountToSend == null) { + ref.refresh(sendAmountProvider); + } else { + ref.read(sendAmountProvider.state).state = _amountToSend!; + } + }); } }); _baseFocus.addListener(() { if (!_cryptoFocus.hasFocus && !_baseFocus.hasFocus) { - if (_amountToSend == null) { - ref.refresh(sendAmountProvider); - } else { - ref.read(sendAmountProvider.state).state = _amountToSend!; - } + WidgetsBinding.instance.addPostFrameCallback((_) { + if (_amountToSend == null) { + ref.refresh(sendAmountProvider); + } else { + ref.read(sendAmountProvider.state).state = _amountToSend!; + } + }); } }); @@ -1064,8 +1067,8 @@ class _DesktopTokenSendState extends ConsumerState { PrimaryButton( buttonHeight: ButtonHeight.l, label: "Preview send", - enabled: ref.watch(previewTxButtonStateProvider.state).state, - onPressed: ref.watch(previewTxButtonStateProvider.state).state + enabled: ref.watch(previewTokenTxButtonStateProvider.state).state, + onPressed: ref.watch(previewTokenTxButtonStateProvider.state).state ? previewSend : null, ) diff --git a/lib/providers/ui/preview_tx_button_state_provider.dart b/lib/providers/ui/preview_tx_button_state_provider.dart index 740356a20..68d4fc531 100644 --- a/lib/providers/ui/preview_tx_button_state_provider.dart +++ b/lib/providers/ui/preview_tx_button_state_provider.dart @@ -1,12 +1,9 @@ -import 'package:flutter/foundation.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; -int _count = 0; - final previewTxButtonStateProvider = StateProvider.autoDispose((_) { - if (kDebugMode) { - _count++; - } - + return false; +}); + +final previewTokenTxButtonStateProvider = StateProvider.autoDispose((_) { return false; });