do not throw exception
MODIFY
WalletWasabi.Fluent/Helpers/TransactionFeeHelper.cs
WalletWasabi.Fluent/Helpers/TransactionFeeHelper.cs
using System.Collections.Generic;
+using System.Diagnostics.CodeAnalysis;
using System.Linq;
using NBitcoin;
using WalletWasabi.Fluent.ViewModels.Wallets.Send;
@@ -24,19 +25,25 @@ public static class TransactionFeeHelper
[1008] = 1
};
- public static Dictionary<int, int> GetFeeEstimates(Wallet wallet)
+ public static bool TryGetFeeEstimates(Wallet wallet, [NotNullWhen(true)] out Dictionary<int, int>? estimates)
{
+ estimates = null;
+
if (wallet.FeeProvider.AllFeeEstimate is null)
{
- throw new InvalidOperationException($"Not possible to get the fee estimates. {nameof(wallet.FeeProvider.AllFeeEstimate)} is null.");
+ return false;
}
- return wallet.Network == Network.TestNet ? TestNetFeeEstimates : wallet.FeeProvider.AllFeeEstimate.Estimations;
+ estimates = wallet.Network == Network.TestNet ? TestNetFeeEstimates : wallet.FeeProvider.AllFeeEstimate.Estimations;
+ return true;
}
public static bool AreTransactionFeesEqual(Wallet wallet)
{
- var feeEstimates = GetFeeEstimates(wallet);
+ if (!TryGetFeeEstimates(wallet, out var feeEstimates))
+ {
+ return false;
+ }
var first = feeEstimates.First();
var last = feeEstimates.Last();
@@ -46,8 +53,13 @@ public static class TransactionFeeHelper
public static TimeSpan CalculateConfirmationTime(FeeRate feeRate, Wallet wallet)
{
+ if (!TryGetFeeEstimates(wallet, out var feeEstimates))
+ {
+ return TimeSpan.Zero;
+ }
+
var feeChartViewModel = new FeeChartViewModel();
- feeChartViewModel.UpdateFeeEstimates(GetFeeEstimates(wallet));
+ feeChartViewModel.UpdateFeeEstimates(feeEstimates);
return feeChartViewModel.TryGetConfirmationTarget(feeRate, out var target)
? CalculateConfirmationTime(target)
@@ -65,7 +77,7 @@ public static class TransactionFeeHelper
{
maximumPossibleFeeRate = FeeRate.Zero;
- if (percentageOfOverpayment <= 0)
+ if (percentageOfOverpayment <= 0 || !TryGetFeeEstimates(wallet, out var feeEstimates))
{
return false;
}
@@ -74,7 +86,7 @@ public static class TransactionFeeHelper
maximumPossibleFeeRate = new FeeRate(maxPossibleFeeRateInSatoshiPerByte);
var feeChartViewModel = new FeeChartViewModel();
- feeChartViewModel.UpdateFeeEstimates(GetFeeEstimates(wallet));
+ feeChartViewModel.UpdateFeeEstimates(feeEstimates);
if (!feeChartViewModel.TryGetConfirmationTarget(maximumPossibleFeeRate, out var blockTarget))
{

MODIFY
WalletWasabi.Fluent/ViewModels/Wallets/Send/SendFeeViewModel.cs
WalletWasabi.Fluent/ViewModels/Wallets/Send/SendFeeViewModel.cs
-using System.Collections.Generic;
-using System.Linq;
-using System.Reactive.Concurrency;
using System.Reactive.Disposables;
using System.Reactive.Linq;
-using System.Threading.Tasks;
using NBitcoin;
using ReactiveUI;
-using WalletWasabi.Blockchain.Analysis.FeesEstimation;
using WalletWasabi.Fluent.Helpers;
using WalletWasabi.Fluent.ViewModels.Dialogs.Base;
using WalletWasabi.Wallets;
@@ -66,19 +61,25 @@ public partial class SendFeeViewModel : DialogViewModelBase<FeeRate>
Observable
.FromEventPattern(feeProvider, nameof(feeProvider.AllFeeEstimateChanged))
- .Select(x => (x.EventArgs as AllFeeEstimate)!.Estimations)
+ .Select(_ =>
+ {
+ TransactionFeeHelper.TryGetFeeEstimates(_wallet, out var estimates);
+ return estimates;
+ })
+ .WhereNotNull()
.ObserveOn(RxApp.MainThreadScheduler)
- .Subscribe(estimations => FeeChart.UpdateFeeEstimates(TransactionFeeHelper.GetFeeEstimates(_wallet), _transactionInfo.MaximumPossibleFeeRate))
+ .Subscribe(estimations => FeeChart.UpdateFeeEstimates(estimations, _transactionInfo.MaximumPossibleFeeRate))
.DisposeWith(disposables);
- RxApp.MainThreadScheduler.Schedule(async () =>
- {
- while (feeProvider.AllFeeEstimate is null)
+
+ if (!TransactionFeeHelper.TryGetFeeEstimates(_wallet, out var feeEstimates))
{
- await Task.Delay(100);
+ // TODO: pop manual fee
+ Close();
+ return;
}
- FeeChart.UpdateFeeEstimates(TransactionFeeHelper.GetFeeEstimates(_wallet), _transactionInfo.MaximumPossibleFeeRate);
+ FeeChart.UpdateFeeEstimates(feeEstimates, _transactionInfo.MaximumPossibleFeeRate);
if (_transactionInfo.FeeRate != FeeRate.Zero)
{
@@ -95,6 +96,5 @@ public partial class SendFeeViewModel : DialogViewModelBase<FeeRate>
{
IsBusy = false;
}
- });
}
}

do not throw exception