From da88f6640c2255ebb97e8e5d31d3a66d1fc208ea Mon Sep 17 00:00:00 2001 From: julian Date: Wed, 10 Jan 2024 14:09:16 -0600 Subject: [PATCH] firo fee sheet fixes --- .../transaction_fee_selection_sheet.dart | 58 +++++++++++----- .../sub_widgets/desktop_fee_dropdown.dart | 67 ++++++++++++------- lib/widgets/desktop/desktop_fee_dialog.dart | 65 ++++++++++++------ 3 files changed, 132 insertions(+), 58 deletions(-) diff --git a/lib/pages/send_view/sub_widgets/transaction_fee_selection_sheet.dart b/lib/pages/send_view/sub_widgets/transaction_fee_selection_sheet.dart index c70845aa7..bf80fa94a 100644 --- a/lib/pages/send_view/sub_widgets/transaction_fee_selection_sheet.dart +++ b/lib/pages/send_view/sub_widgets/transaction_fee_selection_sheet.dart @@ -90,11 +90,21 @@ class _TransactionFeeSelectionSheetState final fee = await wallet.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 (wallet as FiroWallet).estimateFeeForLelantus(amount); + } else if (coin == Coin.firo || coin == Coin.firoTestNet) { + final Amount fee; + switch (ref.read(publicPrivateBalanceStateProvider.state).state) { + case FiroType.spark: + fee = + await (wallet as FiroWallet).estimateFeeForSpark(amount); + case FiroType.lelantus: + fee = await (wallet as FiroWallet) + .estimateFeeForLelantus(amount); + case FiroType.public: + fee = await (wallet as FiroWallet) + .estimateFeeFor(amount, feeRate); + } + + ref.read(feeSheetSessionCacheProvider).fast[amount] = fee; } else { ref.read(feeSheetSessionCacheProvider).fast[amount] = await wallet.estimateFeeFor(amount, feeRate); @@ -115,11 +125,20 @@ class _TransactionFeeSelectionSheetState final fee = await wallet.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 (wallet as FiroWallet).estimateFeeForLelantus(amount); + } else if (coin == Coin.firo || coin == Coin.firoTestNet) { + final Amount fee; + switch (ref.read(publicPrivateBalanceStateProvider.state).state) { + case FiroType.spark: + fee = + await (wallet as FiroWallet).estimateFeeForSpark(amount); + case FiroType.lelantus: + fee = await (wallet as FiroWallet) + .estimateFeeForLelantus(amount); + case FiroType.public: + fee = await (wallet as FiroWallet) + .estimateFeeFor(amount, feeRate); + } + ref.read(feeSheetSessionCacheProvider).average[amount] = fee; } else { ref.read(feeSheetSessionCacheProvider).average[amount] = await wallet.estimateFeeFor(amount, feeRate); @@ -140,11 +159,20 @@ class _TransactionFeeSelectionSheetState final fee = await wallet.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 (wallet as FiroWallet).estimateFeeForLelantus(amount); + } else if (coin == Coin.firo || coin == Coin.firoTestNet) { + final Amount fee; + switch (ref.read(publicPrivateBalanceStateProvider.state).state) { + case FiroType.spark: + fee = + await (wallet as FiroWallet).estimateFeeForSpark(amount); + case FiroType.lelantus: + fee = await (wallet as FiroWallet) + .estimateFeeForLelantus(amount); + case FiroType.public: + fee = await (wallet as FiroWallet) + .estimateFeeFor(amount, feeRate); + } + ref.read(feeSheetSessionCacheProvider).slow[amount] = fee; } else { ref.read(feeSheetSessionCacheProvider).slow[amount] = await wallet.estimateFeeFor(amount, feeRate); 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 88519092b..a84ed8ccb 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 @@ -28,6 +28,7 @@ import 'package:stackwallet/utilities/enums/coin_enum.dart'; import 'package:stackwallet/utilities/enums/fee_rate_type_enum.dart'; import 'package:stackwallet/utilities/text_styles.dart'; import 'package:stackwallet/wallets/isar/providers/wallet_info_provider.dart'; +import 'package:stackwallet/wallets/wallet/impl/firo_wallet.dart'; import 'package:stackwallet/widgets/animated_text.dart'; final tokenFeeSessionCacheProvider = @@ -83,14 +84,20 @@ class _DesktopFeeDropDownState extends ConsumerState { final fee = await wallet.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") { - // TODO: [prio=high] firo fees - throw UnimplementedError("Firo public fees"); - // ref.read(feeSheetSessionCacheProvider).fast[amount] = - // await (manager.wallet as FiroWallet) - // .estimateFeeForPublic(amount, feeRate); + } else if (coin == Coin.firo || coin == Coin.firoTestNet) { + final Amount fee; + switch (ref.read(publicPrivateBalanceStateProvider.state).state) { + case FiroType.spark: + fee = + await (wallet as FiroWallet).estimateFeeForSpark(amount); + case FiroType.lelantus: + fee = await (wallet as FiroWallet) + .estimateFeeForLelantus(amount); + case FiroType.public: + fee = await (wallet as FiroWallet) + .estimateFeeFor(amount, feeRate); + } + ref.read(feeSheetSessionCacheProvider).fast[amount] = fee; } else { ref.read(feeSheetSessionCacheProvider).fast[amount] = await wallet.estimateFeeFor(amount, feeRate); @@ -121,14 +128,20 @@ class _DesktopFeeDropDownState extends ConsumerState { final fee = await wallet.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") { - // TODO: [prio=high] firo fees - throw UnimplementedError("Firo public fees"); - // ref.read(feeSheetSessionCacheProvider).average[amount] = - // await (manager.wallet as FiroWallet) - // .estimateFeeForPublic(amount, feeRate); + } else if (coin == Coin.firo || coin == Coin.firoTestNet) { + final Amount fee; + switch (ref.read(publicPrivateBalanceStateProvider.state).state) { + case FiroType.spark: + fee = + await (wallet as FiroWallet).estimateFeeForSpark(amount); + case FiroType.lelantus: + fee = await (wallet as FiroWallet) + .estimateFeeForLelantus(amount); + case FiroType.public: + fee = await (wallet as FiroWallet) + .estimateFeeFor(amount, feeRate); + } + ref.read(feeSheetSessionCacheProvider).average[amount] = fee; } else { ref.read(feeSheetSessionCacheProvider).average[amount] = await wallet.estimateFeeFor(amount, feeRate); @@ -159,14 +172,20 @@ class _DesktopFeeDropDownState extends ConsumerState { final fee = await wallet.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") { - // TODO: [prio=high] firo fees - throw UnimplementedError("Firo public fees"); - // ref.read(feeSheetSessionCacheProvider).slow[amount] = - // await (manager.wallet as FiroWallet) - // .estimateFeeForPublic(amount, feeRate); + } else if (coin == Coin.firo || coin == Coin.firoTestNet) { + final Amount fee; + switch (ref.read(publicPrivateBalanceStateProvider.state).state) { + case FiroType.spark: + fee = + await (wallet as FiroWallet).estimateFeeForSpark(amount); + case FiroType.lelantus: + fee = await (wallet as FiroWallet) + .estimateFeeForLelantus(amount); + case FiroType.public: + fee = await (wallet as FiroWallet) + .estimateFeeFor(amount, feeRate); + } + ref.read(feeSheetSessionCacheProvider).slow[amount] = fee; } else { ref.read(feeSheetSessionCacheProvider).slow[amount] = await wallet.estimateFeeFor(amount, feeRate); diff --git a/lib/widgets/desktop/desktop_fee_dialog.dart b/lib/widgets/desktop/desktop_fee_dialog.dart index d70acc538..6036d5886 100644 --- a/lib/widgets/desktop/desktop_fee_dialog.dart +++ b/lib/widgets/desktop/desktop_fee_dialog.dart @@ -61,18 +61,27 @@ class _DesktopFeeDialogState extends ConsumerState { final fee = await wallet.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 (wallet as FiroWallet).estimateFeeForLelantus(amount); + } else if (coin == Coin.firo || coin == Coin.firoTestNet) { + final Amount fee; + switch (ref.read(publicPrivateBalanceStateProvider.state).state) { + case FiroType.spark: + fee = + await (wallet as FiroWallet).estimateFeeForSpark(amount); + case FiroType.lelantus: + fee = await (wallet as FiroWallet) + .estimateFeeForLelantus(amount); + case FiroType.public: + fee = await (wallet as FiroWallet) + .estimateFeeFor(amount, feeRate); + } + ref.read(feeSheetSessionCacheProvider).fast[amount] = fee; } else { ref.read(feeSheetSessionCacheProvider).fast[amount] = await wallet.estimateFeeFor(amount, feeRate); } } else { - final tokenWallet = ref.read(tokenServiceProvider)!; - final fee = tokenWallet.estimateFeeFor(feeRate); + final tokenWallet = ref.read(pCurrentTokenWallet)!; + final fee = await tokenWallet.estimateFeeFor(amount, feeRate); ref.read(tokenFeeSessionCacheProvider).fast[amount] = fee; } } @@ -96,18 +105,27 @@ class _DesktopFeeDialogState extends ConsumerState { final fee = await wallet.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 (wallet as FiroWallet).estimateFeeForLelantus(amount); + } else if (coin == Coin.firo || coin == Coin.firoTestNet) { + final Amount fee; + switch (ref.read(publicPrivateBalanceStateProvider.state).state) { + case FiroType.spark: + fee = + await (wallet as FiroWallet).estimateFeeForSpark(amount); + case FiroType.lelantus: + fee = await (wallet as FiroWallet) + .estimateFeeForLelantus(amount); + case FiroType.public: + fee = await (wallet as FiroWallet) + .estimateFeeFor(amount, feeRate); + } + ref.read(feeSheetSessionCacheProvider).average[amount] = fee; } else { ref.read(feeSheetSessionCacheProvider).average[amount] = await wallet.estimateFeeFor(amount, feeRate); } } else { - final tokenWallet = ref.read(tokenServiceProvider)!; - final fee = tokenWallet.estimateFeeFor(feeRate); + final tokenWallet = ref.read(pCurrentTokenWallet)!; + final fee = await tokenWallet.estimateFeeFor(amount, feeRate); ref.read(tokenFeeSessionCacheProvider).average[amount] = fee; } } @@ -131,11 +149,20 @@ class _DesktopFeeDialogState extends ConsumerState { final fee = await wallet.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 (wallet as FiroWallet).estimateFeeForLelantus(amount); + } else if (coin == Coin.firo || coin == Coin.firoTestNet) { + final Amount fee; + switch (ref.read(publicPrivateBalanceStateProvider.state).state) { + case FiroType.spark: + fee = + await (wallet as FiroWallet).estimateFeeForSpark(amount); + case FiroType.lelantus: + fee = await (wallet as FiroWallet) + .estimateFeeForLelantus(amount); + case FiroType.public: + fee = await (wallet as FiroWallet) + .estimateFeeFor(amount, feeRate); + } + ref.read(feeSheetSessionCacheProvider).slow[amount] = fee; } else { ref.read(feeSheetSessionCacheProvider).slow[amount] = await wallet.estimateFeeFor(amount, feeRate);