Skip to content

Commit

Permalink
Merge pull request #12569 from soosr/fix-11122-fee-chart-values
Browse files Browse the repository at this point in the history
[UI] FeeChart - Integrate WildEstimations
  • Loading branch information
soosr committed Mar 4, 2024
2 parents 0a439f2 + 97de9a1 commit 46c8835
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
2 changes: 1 addition & 1 deletion WalletWasabi.Fluent/Helpers/TransactionFeeHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ private static bool EnsureFeeRateIsPossible(Wallet wallet, FeeRate feeRate)
}

var feeChartViewModel = new FeeChartViewModel();
feeChartViewModel.UpdateFeeEstimates(feeEstimates.Estimations);
feeChartViewModel.UpdateFeeEstimates(feeEstimates.WildEstimations);

if (!feeChartViewModel.TryGetConfirmationTarget(feeRate, out var blockTarget))
{
Expand Down
18 changes: 11 additions & 7 deletions WalletWasabi.Fluent/ViewModels/Wallets/Send/FeeChartViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -213,14 +213,18 @@ private int GetSliderValue(double x, double[] xs)
return 0;
}

public void UpdateFeeEstimates(Dictionary<int, int> feeEstimates, FeeRate? maxFee = null)
public void UpdateFeeEstimates(IEnumerable<(TimeSpan timeSpan, FeeRate feeRate)> wildFeeEstimates, FeeRate? maxFee = null)
{
Dictionary<int, double> feeEstimates = wildFeeEstimates.ToDictionary(
x => (int)x.timeSpan.TotalMinutes / 10,
x => Math.Round((double)x.feeRate.SatoshiPerByte, 3));

var enableCursor = true;
var areAllValuesEqual = AreEstimatedFeeRatesEqual(feeEstimates);
var correctedFeeEstimates = areAllValuesEqual ? feeEstimates : DistinctByValues(feeEstimates);

var xs = correctedFeeEstimates.Select(x => (double)x.Key).ToArray();
var ys = correctedFeeEstimates.Select(x => (double)x.Value).ToArray();
var ys = correctedFeeEstimates.Select(x => x.Value).ToArray();

List<double>? xts;
List<double>? yts;
Expand Down Expand Up @@ -353,13 +357,13 @@ public void InitCurrentConfirmationTarget(FeeRate feeRate)
return values;
}

private Dictionary<int, int> DistinctByValues(Dictionary<int, int> feeEstimates)
private Dictionary<int, double> DistinctByValues(Dictionary<int, double> feeEstimates)
{
Dictionary<int, int> valuesToReturn = new();
Dictionary<int, double> valuesToReturn = new();

foreach (var estimate in feeEstimates)
{
var similarBlockTargets = feeEstimates.Where(x => x.Value == estimate.Value);
var similarBlockTargets = feeEstimates.Where(x => Math.Abs(x.Value - estimate.Value) == 0);
var fasterSimilarBlockTarget = similarBlockTargets.First();

if (fasterSimilarBlockTarget.Key == estimate.Key)
Expand All @@ -371,11 +375,11 @@ public void InitCurrentConfirmationTarget(FeeRate feeRate)
return valuesToReturn;
}

private bool AreEstimatedFeeRatesEqual(Dictionary<int, int> feeEstimates)
private bool AreEstimatedFeeRatesEqual(Dictionary<int, double> feeEstimates)
{
var first = feeEstimates.First();
var last = feeEstimates.Last();

return first.Value == last.Value;
return Math.Abs(first.Value - last.Value) == 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ protected override void OnNavigatedTo(bool isInHistory, CompositeDisposable disp
})
.WhereNotNull()
.ObserveOn(RxApp.MainThreadScheduler)
.Subscribe(estimations => FeeChart.UpdateFeeEstimates(estimations.Estimations, _transactionInfo.MaximumPossibleFeeRate))
.Subscribe(estimations => FeeChart.UpdateFeeEstimates(estimations.WildEstimations, _transactionInfo.MaximumPossibleFeeRate))
.DisposeWith(disposables);

RxApp.MainThreadScheduler.Schedule(async () =>
Expand All @@ -129,7 +129,7 @@ protected override void OnNavigatedTo(bool isInHistory, CompositeDisposable disp
return;
}
FeeChart.UpdateFeeEstimates(feeEstimates.Estimations, _transactionInfo.MaximumPossibleFeeRate);
FeeChart.UpdateFeeEstimates(feeEstimates.WildEstimations, _transactionInfo.MaximumPossibleFeeRate);
if (_transactionInfo.FeeRate != FeeRate.Zero)
{
Expand Down

0 comments on commit 46c8835

Please sign in to comment.