sorting and normalising privacy optimisations.
MODIFY
WalletWasabi.Fluent/ViewModels/Wallets/Send/OptimisePrivacyViewModel.cs
WalletWasabi.Fluent/ViewModels/Wallets/Send/OptimisePrivacyViewModel.cs
using NBitcoin;
using System;
+using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Reactive.Concurrency;
@@ -9,6 +10,7 @@ using System.Threading.Tasks;
using ReactiveUI;
using WalletWasabi.Blockchain.TransactionBroadcasting;
using WalletWasabi.Blockchain.TransactionBuilding;
+using WalletWasabi.Fluent.Helpers;
using WalletWasabi.Fluent.ViewModels.Navigation;
using WalletWasabi.Wallets;
@@ -69,6 +71,8 @@ namespace WalletWasabi.Fluent.ViewModels.Wallets.Send
MoneyRequest.CreateAllRemaining(subtractFee: true),
_transactionInfo.Labels);
+ PrivacySuggestionControlViewModel? smallerSuggestion = null;
+
if (_requestedTransaction.SpentCoins.Count() > 1)
{
var smallerTransaction = await Task.Run(() => _wallet.BuildTransaction(
@@ -82,17 +86,15 @@ namespace WalletWasabi.Fluent.ViewModels.Wallets.Send
.Skip(1)
.Select(x => x.OutPoint)));
- _privacySuggestions.Add(new PrivacySuggestionControlViewModel(
+ smallerSuggestion = new PrivacySuggestionControlViewModel(
_transactionInfo.Amount.ToDecimal(MoneyUnit.BTC), smallerTransaction,
- PrivacyOptimisationLevel.Better, _wallet.Synchronizer.UsdExchangeRate, "Improved Privacy"));
+ PrivacyOptimisationLevel.Better, _wallet.Synchronizer.UsdExchangeRate, "Improved Privacy");
}
_defaultSelection = new PrivacySuggestionControlViewModel(
_transactionInfo.Amount.ToDecimal(MoneyUnit.BTC), _requestedTransaction,
PrivacyOptimisationLevel.Standard, _wallet.Synchronizer.UsdExchangeRate);
- _privacySuggestions.Add(_defaultSelection);
-
var largerTransaction = await Task.Run(() => _wallet.BuildTransaction(
_wallet.Kitchen.SaltSoup(),
intent,
@@ -100,9 +102,23 @@ namespace WalletWasabi.Fluent.ViewModels.Wallets.Send
true,
_requestedTransaction.SpentCoins.Select(x => x.OutPoint)));
- _privacySuggestions.Add(new PrivacySuggestionControlViewModel(
+ var largerSuggestion = new PrivacySuggestionControlViewModel(
_transactionInfo.Amount.ToDecimal(MoneyUnit.BTC), largerTransaction,
- PrivacyOptimisationLevel.Better, _wallet.Synchronizer.UsdExchangeRate, "Improved Privacy"));
+ PrivacyOptimisationLevel.Better, _wallet.Synchronizer.UsdExchangeRate, "Improved Privacy");
+
+ // There are several scenarios, both the alternate suggestions are <, or >, or 1 < and 1 >.
+ // We sort them and add the suggestions accordingly.
+ var suggestions = new List<PrivacySuggestionControlViewModel> {_defaultSelection, largerSuggestion};
+
+ if (smallerSuggestion is { })
+ {
+ suggestions.Add(smallerSuggestion);
+ }
+
+ foreach (var suggestion in NormalizeSuggestions(suggestions, _defaultSelection))
+ {
+ _privacySuggestions.Add(suggestion);
+ }
SelectedPrivacySuggestion = _defaultSelection;
@@ -110,5 +126,34 @@ namespace WalletWasabi.Fluent.ViewModels.Wallets.Send
});
}
}
+
+ private IEnumerable<PrivacySuggestionControlViewModel> NormalizeSuggestions(
+ IEnumerable<PrivacySuggestionControlViewModel> suggestions, PrivacySuggestionControlViewModel defaultSuggestion)
+ {
+ var normalized = suggestions
+ .OrderBy(x => x.TransactionResult.CalculateDestinationAmount())
+ .ToList();
+
+ if (normalized.Count == 3)
+ {
+ var index = normalized.IndexOf(defaultSuggestion);
+
+ switch (index)
+ {
+ case 1:
+ break;
+
+ case 0:
+ normalized = normalized.Take(2).ToList();
+ break;
+
+ case 2:
+ normalized = normalized.Skip(1).ToList();
+ break;
+ }
+ }
+
+ return normalized;
+ }
}
}

sorting and normalising privacy optimisations.