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,66 +55,84 @@ 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) {
final manager = if (widget.isToken == false) {
ref.read(walletsChangeNotifierProvider).getManager(walletId); final manager =
ref.read(walletsChangeNotifierProvider).getManager(walletId);
if (coin == Coin.monero || coin == Coin.wownero) { if (coin == Coin.monero || coin == Coin.wownero) {
final fee = await manager.estimateFeeFor( final fee = await manager.estimateFeeFor(
amount, MoneroTransactionPriority.fast.raw!); amount, MoneroTransactionPriority.fast.raw!);
ref.read(feeSheetSessionCacheProvider).fast[amount] = fee; ref.read(feeSheetSessionCacheProvider).fast[amount] = fee;
} else if ((coin == Coin.firo || coin == Coin.firoTestNet) && } else if ((coin == Coin.firo || coin == Coin.firoTestNet) &&
ref.read(publicPrivateBalanceStateProvider.state).state != ref.read(publicPrivateBalanceStateProvider.state).state !=
"Private") { "Private") {
ref.read(feeSheetSessionCacheProvider).fast[amount] = ref.read(feeSheetSessionCacheProvider).fast[amount] =
await (manager.wallet as FiroWallet) await (manager.wallet as FiroWallet)
.estimateFeeForPublic(amount, feeRate); .estimateFeeForPublic(amount, feeRate);
} else {
ref.read(feeSheetSessionCacheProvider).fast[amount] =
await manager.estimateFeeFor(amount, feeRate);
}
} else { } else {
ref.read(feeSheetSessionCacheProvider).fast[amount] = final tokenWallet = ref.read(tokenServiceProvider)!;
await manager.estimateFeeFor(amount, feeRate); 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) {
final manager = if (widget.isToken == false) {
ref.read(walletsChangeNotifierProvider).getManager(walletId); final manager =
ref.read(walletsChangeNotifierProvider).getManager(walletId);
if (coin == Coin.monero || coin == Coin.wownero) { if (coin == Coin.monero || coin == Coin.wownero) {
final fee = await manager.estimateFeeFor( final fee = await manager.estimateFeeFor(
amount, MoneroTransactionPriority.regular.raw!); amount, MoneroTransactionPriority.regular.raw!);
ref.read(feeSheetSessionCacheProvider).average[amount] = fee; ref.read(feeSheetSessionCacheProvider).average[amount] = fee;
} else if ((coin == Coin.firo || coin == Coin.firoTestNet) && } else if ((coin == Coin.firo || coin == Coin.firoTestNet) &&
ref.read(publicPrivateBalanceStateProvider.state).state != ref.read(publicPrivateBalanceStateProvider.state).state !=
"Private") { "Private") {
ref.read(feeSheetSessionCacheProvider).average[amount] = ref.read(feeSheetSessionCacheProvider).average[amount] =
await (manager.wallet as FiroWallet) await (manager.wallet as FiroWallet)
.estimateFeeForPublic(amount, feeRate); .estimateFeeForPublic(amount, feeRate);
} else {
ref.read(feeSheetSessionCacheProvider).average[amount] =
await manager.estimateFeeFor(amount, feeRate);
}
} else { } else {
ref.read(feeSheetSessionCacheProvider).average[amount] = final tokenWallet = ref.read(tokenServiceProvider)!;
await manager.estimateFeeFor(amount, feeRate); 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) {
final manager = if (widget.isToken == false) {
ref.read(walletsChangeNotifierProvider).getManager(walletId); final manager =
ref.read(walletsChangeNotifierProvider).getManager(walletId);
if (coin == Coin.monero || coin == Coin.wownero) { if (coin == Coin.monero || coin == Coin.wownero) {
final fee = await manager.estimateFeeFor( final fee = await manager.estimateFeeFor(
amount, MoneroTransactionPriority.slow.raw!); amount, MoneroTransactionPriority.slow.raw!);
ref.read(feeSheetSessionCacheProvider).slow[amount] = fee; ref.read(feeSheetSessionCacheProvider).slow[amount] = fee;
} else if ((coin == Coin.firo || coin == Coin.firoTestNet) && } else if ((coin == Coin.firo || coin == Coin.firoTestNet) &&
ref.read(publicPrivateBalanceStateProvider.state).state != ref.read(publicPrivateBalanceStateProvider.state).state !=
"Private") { "Private") {
ref.read(feeSheetSessionCacheProvider).slow[amount] = ref.read(feeSheetSessionCacheProvider).slow[amount] =
await (manager.wallet as FiroWallet) await (manager.wallet as FiroWallet)
.estimateFeeForPublic(amount, feeRate); .estimateFeeForPublic(amount, feeRate);
} else {
ref.read(feeSheetSessionCacheProvider).slow[amount] =
await manager.estimateFeeFor(amount, feeRate);
}
} else { } else {
ref.read(feeSheetSessionCacheProvider).slow[amount] = final tokenWallet = ref.read(tokenServiceProvider)!;
await manager.estimateFeeFor(amount, feeRate); 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,