fix when it is not possible to find a valid confirmation target
MODIFY
WalletWasabi.Fluent/Helpers/TransactionFeeHelper.cs
WalletWasabi.Fluent/Helpers/TransactionFeeHelper.cs
@@ -48,9 +48,10 @@ public static class TransactionFeeHelper
{
var feeChartViewModel = new FeeChartViewModel();
feeChartViewModel.UpdateFeeEstimates(GetFeeEstimates(wallet));
- var blockTarget = feeChartViewModel.GetConfirmationTarget(feeRate);
- return CalculateConfirmationTime(blockTarget);
+ return feeChartViewModel.TryGetConfirmationTarget(feeRate, out var target)
+ ? CalculateConfirmationTime(target)
+ : TimeSpan.Zero;
}
public static TimeSpan CalculateConfirmationTime(double targetBlock)
@@ -75,9 +76,12 @@ public static class TransactionFeeHelper
var feeChartViewModel = new FeeChartViewModel();
feeChartViewModel.UpdateFeeEstimates(GetFeeEstimates(wallet));
- var blockTarget = feeChartViewModel.GetConfirmationTarget(maximumPossibleFeeRate);
- var newFeeRate = new FeeRate(feeChartViewModel.GetSatoshiPerByte(blockTarget));
+ if (!feeChartViewModel.TryGetConfirmationTarget(maximumPossibleFeeRate, out var blockTarget))
+ {
+ return false;
+ }
+ var newFeeRate = new FeeRate(feeChartViewModel.GetSatoshiPerByte(blockTarget));
return newFeeRate <= maximumPossibleFeeRate;
}
}

MODIFY
WalletWasabi.Fluent/ViewModels/Wallets/Send/FeeChartViewModel.cs
WalletWasabi.Fluent/ViewModels/Wallets/Send/FeeChartViewModel.cs
@@ -12,8 +12,12 @@ namespace WalletWasabi.Fluent.ViewModels.Wallets.Send;
public partial class FeeChartViewModel : ViewModelBase
{
- [AutoNotify(SetterModifier = AccessModifier.Private)] private int _sliderMinimum;
- [AutoNotify(SetterModifier = AccessModifier.Private)] private int _sliderMaximum;
+ [AutoNotify(SetterModifier = AccessModifier.Private)]
+ private int _sliderMinimum;
+
+ [AutoNotify(SetterModifier = AccessModifier.Private)]
+ private int _sliderMaximum;
+
[AutoNotify] private int _sliderValue;
[AutoNotify] private string[]? _satoshiPerByteLabels;
[AutoNotify] private double[]? _satoshiPerByteValues;
@@ -170,17 +174,28 @@ public partial class FeeChartViewModel : ViewModelBase
return SliderMaximum;
}
- public double GetConfirmationTarget(FeeRate feeRate)
+ public bool TryGetConfirmationTarget(FeeRate feeRate, out double target)
{
+ target = -1;
+
if (SatoshiPerByteValues is null || ConfirmationTargetValues is null) // Should not happen
{
- return 1;
+ return false;
}
+ try
+ {
var closestValue = SatoshiPerByteValues.Last(x => (decimal)x <= feeRate.SatoshiPerByte);
var indexOfClosestValue = SatoshiPerByteValues.LastIndexOf(closestValue);
- return ConfirmationTargetValues[indexOfClosestValue];
+ target = ConfirmationTargetValues[indexOfClosestValue];
+ }
+ catch (Exception)
+ {
+ // Ignored.
+ }
+
+ return target > -1;
}
private int GetSliderValue(double x, double[] xs)
@@ -280,7 +295,7 @@ public partial class FeeChartViewModel : ViewModelBase
public void InitCurrentConfirmationTarget(FeeRate feeRate)
{
- CurrentConfirmationTarget = GetConfirmationTarget(feeRate);
+ CurrentConfirmationTarget = TryGetConfirmationTarget(feeRate, out var target) ? target : 1;
}
public Dictionary<double, double> GetValues()

MODIFY
WalletWasabi.Fluent/ViewModels/Wallets/Send/TransactionPreviewViewModel.cs
WalletWasabi.Fluent/ViewModels/Wallets/Send/TransactionPreviewViewModel.cs
@@ -319,7 +319,7 @@ public partial class TransactionPreviewViewModel : RoutableViewModel
? feeRate
: FeeRate.Zero;
- if (differenceOfFeePercentage <= TransactionFeeHelper.FeePercentageThreshold)
+ if (differenceOfFeePercentage is > 0 and TransactionFeeHelper.FeePercentageThreshold)
{
_info.MaximumPossibleFeeRate = maximumPossibleFeeRate;
_info.FeeRate = maximumPossibleFeeRate;

fix when it is not possible to find a valid confirmation target