add token fees to fee dropdown on desktop

This commit is contained in:
julian 2023-04-11 14:57:19 -06:00
parent bb9916380d
commit e2cc371f99
2 changed files with 64 additions and 43 deletions

View file

@ -5,6 +5,7 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_svg/svg.dart'; import 'package:flutter_svg/svg.dart';
import 'package:stackwallet/models/models.dart'; import 'package:stackwallet/models/models.dart';
import 'package:stackwallet/pages/send_view/sub_widgets/transaction_fee_selection_sheet.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/global/wallets_provider.dart';
import 'package:stackwallet/providers/ui/fee_rate_type_state_provider.dart'; import 'package:stackwallet/providers/ui/fee_rate_type_state_provider.dart';
import 'package:stackwallet/providers/wallet/public_private_balance_state_provider.dart'; import 'package:stackwallet/providers/wallet/public_private_balance_state_provider.dart';
@ -22,9 +23,11 @@ class DesktopFeeDropDown extends ConsumerStatefulWidget {
const DesktopFeeDropDown({ const DesktopFeeDropDown({
Key? key, Key? key,
required this.walletId, required this.walletId,
this.isToken = false,
}) : super(key: key); }) : super(key: key);
final String walletId; final String walletId;
final bool isToken;
@override @override
ConsumerState<DesktopFeeDropDown> createState() => _DesktopFeeDropDownState(); ConsumerState<DesktopFeeDropDown> createState() => _DesktopFeeDropDownState();
@ -52,6 +55,7 @@ class _DesktopFeeDropDownState extends ConsumerState<DesktopFeeDropDown> {
switch (feeRateType) { switch (feeRateType) {
case FeeRateType.fast: case FeeRateType.fast:
if (ref.read(feeSheetSessionCacheProvider).fast[amount] == null) { if (ref.read(feeSheetSessionCacheProvider).fast[amount] == null) {
if (widget.isToken == false) {
final manager = final manager =
ref.read(walletsChangeNotifierProvider).getManager(walletId); ref.read(walletsChangeNotifierProvider).getManager(walletId);
@ -69,11 +73,17 @@ class _DesktopFeeDropDownState extends ConsumerState<DesktopFeeDropDown> {
ref.read(feeSheetSessionCacheProvider).fast[amount] = ref.read(feeSheetSessionCacheProvider).fast[amount] =
await manager.estimateFeeFor(amount, feeRate); await manager.estimateFeeFor(amount, feeRate);
} }
} else {
final tokenWallet = ref.read(tokenServiceProvider)!;
final fee = tokenWallet.estimateFeeFor(feeRate);
ref.read(feeSheetSessionCacheProvider).fast[amount] = fee;
}
} }
return ref.read(feeSheetSessionCacheProvider).fast[amount]!; return ref.read(feeSheetSessionCacheProvider).fast[amount]!;
case FeeRateType.average: case FeeRateType.average:
if (ref.read(feeSheetSessionCacheProvider).average[amount] == null) { if (ref.read(feeSheetSessionCacheProvider).average[amount] == null) {
if (widget.isToken == false) {
final manager = final manager =
ref.read(walletsChangeNotifierProvider).getManager(walletId); ref.read(walletsChangeNotifierProvider).getManager(walletId);
@ -91,11 +101,17 @@ class _DesktopFeeDropDownState extends ConsumerState<DesktopFeeDropDown> {
ref.read(feeSheetSessionCacheProvider).average[amount] = ref.read(feeSheetSessionCacheProvider).average[amount] =
await manager.estimateFeeFor(amount, feeRate); await manager.estimateFeeFor(amount, feeRate);
} }
} else {
final tokenWallet = ref.read(tokenServiceProvider)!;
final fee = tokenWallet.estimateFeeFor(feeRate);
ref.read(feeSheetSessionCacheProvider).average[amount] = fee;
}
} }
return ref.read(feeSheetSessionCacheProvider).average[amount]!; return ref.read(feeSheetSessionCacheProvider).average[amount]!;
case FeeRateType.slow: case FeeRateType.slow:
if (ref.read(feeSheetSessionCacheProvider).slow[amount] == null) { if (ref.read(feeSheetSessionCacheProvider).slow[amount] == null) {
if (widget.isToken == false) {
final manager = final manager =
ref.read(walletsChangeNotifierProvider).getManager(walletId); ref.read(walletsChangeNotifierProvider).getManager(walletId);
@ -113,6 +129,11 @@ class _DesktopFeeDropDownState extends ConsumerState<DesktopFeeDropDown> {
ref.read(feeSheetSessionCacheProvider).slow[amount] = ref.read(feeSheetSessionCacheProvider).slow[amount] =
await manager.estimateFeeFor(amount, feeRate); await manager.estimateFeeFor(amount, feeRate);
} }
} else {
final tokenWallet = ref.read(tokenServiceProvider)!;
final fee = tokenWallet.estimateFeeFor(feeRate);
ref.read(feeSheetSessionCacheProvider).slow[amount] = fee;
}
} }
return ref.read(feeSheetSessionCacheProvider).slow[amount]!; return ref.read(feeSheetSessionCacheProvider).slow[amount]!;
} }

View file

@ -1004,9 +1004,9 @@ class _DesktopTokenSendState extends ConsumerState<DesktopTokenSend> {
const SizedBox( const SizedBox(
height: 10, height: 10,
), ),
// TODO mod this for token fees
DesktopFeeDropDown( DesktopFeeDropDown(
walletId: walletId, walletId: walletId,
isToken: true,
), ),
const SizedBox( const SizedBox(
height: 20, height: 20,