token send form state fixes

This commit is contained in:
julian 2023-04-13 09:21:27 -06:00
parent 49b6e65ffe
commit 07f25cc9ff
3 changed files with 64 additions and 32 deletions

View file

@ -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<FeeSheetSessionCache>((ref) {
return FeeSheetSessionCache();
});
class DesktopFeeDropDown extends ConsumerStatefulWidget {
const DesktopFeeDropDown({
Key? key,
@ -54,7 +59,12 @@ class _DesktopFeeDropDownState extends ConsumerState<DesktopFeeDropDown> {
}) 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<DesktopFeeDropDown> {
} 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<DesktopFeeDropDown> {
} 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<DesktopFeeDropDown> {
} 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]!;
}
}

View file

@ -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<DesktopTokenSend> {
.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<DesktopTokenSend> {
@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<DesktopTokenSend> {
_cryptoFocus.addListener(() {
if (!_cryptoFocus.hasFocus && !_baseFocus.hasFocus) {
WidgetsBinding.instance.addPostFrameCallback((_) {
if (_amountToSend == null) {
ref.refresh(sendAmountProvider);
} else {
ref.read(sendAmountProvider.state).state = _amountToSend!;
}
});
}
});
_baseFocus.addListener(() {
if (!_cryptoFocus.hasFocus && !_baseFocus.hasFocus) {
WidgetsBinding.instance.addPostFrameCallback((_) {
if (_amountToSend == null) {
ref.refresh(sendAmountProvider);
} else {
ref.read(sendAmountProvider.state).state = _amountToSend!;
}
});
}
});
@ -1064,8 +1067,8 @@ class _DesktopTokenSendState extends ConsumerState<DesktopTokenSend> {
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,
)

View file

@ -1,12 +1,9 @@
import 'package:flutter/foundation.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
int _count = 0;
final previewTxButtonStateProvider = StateProvider.autoDispose<bool>((_) {
if (kDebugMode) {
_count++;
}
return false;
});
final previewTokenTxButtonStateProvider = StateProvider.autoDispose<bool>((_) {
return false;
});