Fix AutoSelectPockets
MODIFY
WalletWasabi.Fluent/ViewModels/Wallets/Send/LabelSelectionViewModel.cs
WalletWasabi.Fluent/ViewModels/Wallets/Send/LabelSelectionViewModel.cs
@@ -42,12 +42,8 @@ public partial class LabelSelectionViewModel : ViewModelBase
var knownPockets = NonPrivatePockets.Where(x => x.Labels != CoinPocketHelper.UnlabelledFundsText).ToArray();
var unknownPockets = NonPrivatePockets.Except(knownPockets).ToArray();
- var privateAndUnknownPockets = unknownPockets.Union(new[] { _privatePocket }).ToArray();
- var semiPrivateAndUnknownPockets = unknownPockets.Union(new[] { _semiPrivatePocket }).ToArray();
var privateAndSemiPrivateAndUnknownPockets = privateAndSemiPrivatePockets.Union(unknownPockets).ToArray();
- var privateAndKnownPockets = knownPockets.Union(new[] { _privatePocket }).ToArray();
- var semiPrivateAndKnownPockets = knownPockets.Union(new[] { _semiPrivatePocket }).ToArray();
var privateAndSemiPrivateAndKnownPockets = privateAndSemiPrivatePockets.Union(knownPockets).ToArray();
var knownByRecipientPockets = knownPockets.Where(pocket => pocket.Labels.Any(label => recipient.Contains(label, StringComparer.OrdinalIgnoreCase))).ToArray();
@@ -73,46 +69,11 @@ public partial class LabelSelectionViewModel : ViewModelBase
return pockets;
}
- if (knownPockets.Sum(x => x.Amount) >= _targetAmount)
- {
- return knownPockets;
- }
-
- if (unknownPockets.Sum(x => x.Amount) >= _targetAmount)
- {
- return unknownPockets;
- }
-
- if (NonPrivatePockets.Sum(x => x.Amount) >= _targetAmount)
- {
- return NonPrivatePockets;
- }
-
- if (privateAndKnownPockets.Sum(x => x.Amount) >= _targetAmount)
- {
- return privateAndKnownPockets;
- }
-
- if (semiPrivateAndKnownPockets.Sum(x => x.Amount) >= _targetAmount)
- {
- return semiPrivateAndKnownPockets;
- }
-
if (privateAndSemiPrivateAndKnownPockets.Sum(x => x.Amount) >= _targetAmount)
{
return privateAndSemiPrivateAndKnownPockets;
}
- if (privateAndUnknownPockets.Sum(x => x.Amount) >= _targetAmount)
- {
- return privateAndUnknownPockets;
- }
-
- if (semiPrivateAndUnknownPockets.Sum(x => x.Amount) >= _targetAmount)
- {
- return semiPrivateAndUnknownPockets;
- }
-
if (privateAndSemiPrivateAndUnknownPockets.Sum(x => x.Amount) >= _targetAmount)
{
return privateAndSemiPrivateAndUnknownPockets;

MODIFY
WalletWasabi.Tests/UnitTests/UserInterfaceTest/PocketSelectionTests.cs
WalletWasabi.Tests/UnitTests/UserInterfaceTest/PocketSelectionTests.cs
@@ -486,114 +486,6 @@ public class PocketSelectionTests
Assert.Contains(pocket4, output);
}
- [Fact]
- public void AutoSelectOnlyKnownPockets()
- {
- var selection = new LabelSelectionViewModel(Money.Parse("1.0"));
-
- var pockets = new List<Pocket>();
- pockets.AddPocket(0.8M, out var pocket1, CoinPocketHelper.PrivateFundsText);
- pockets.AddPocket(1.1M, out var pocket2, "Dan");
- pockets.AddPocket(0.5M, out var pocket3, CoinPocketHelper.UnlabelledFundsText);
- pockets.AddPocket(0.1M, out var pocket4, "David", "Lucas");
- pockets.AddPocket(0.15M, out var pocket5, "David");
- pockets.AddPocket(0.2M, out var pocket6, "Lucas");
- pockets.AddPocket(0.3M, out var pocket7, "David", "Lucas", "Dan");
- pockets.AddPocket(0.1M, out var pocket8, CoinPocketHelper.SemiPrivateFundsText);
-
- selection.Reset(pockets.ToArray());
-
- var output = selection.AutoSelectPockets(new SmartLabel("David", "Lucas"));
- Assert.DoesNotContain(pocket1, output);
- Assert.Contains(pocket2, output);
- Assert.DoesNotContain(pocket3, output);
- Assert.Contains(pocket4, output);
- Assert.Contains(pocket5, output);
- Assert.Contains(pocket6, output);
- Assert.Contains(pocket7, output);
- Assert.DoesNotContain(pocket8, output);
- }
-
- [Fact]
- public void AutoSelectOnlyUnknownPocket()
- {
- var selection = new LabelSelectionViewModel(Money.Parse("0.7"));
-
- var pockets = new List<Pocket>();
- pockets.AddPocket(0.5M, out var pocket1, CoinPocketHelper.PrivateFundsText);
- pockets.AddPocket(0.5M, out var pocket2, "Dan");
- pockets.AddPocket(0.8M, out var pocket3, CoinPocketHelper.UnlabelledFundsText);
- pockets.AddPocket(0.1M, out var pocket4, CoinPocketHelper.SemiPrivateFundsText);
-
- selection.Reset(pockets.ToArray());
-
- var output = selection.AutoSelectPockets("Dan");
- Assert.DoesNotContain(pocket1, output);
- Assert.DoesNotContain(pocket2, output);
- Assert.Contains(pocket3, output);
- Assert.DoesNotContain(pocket4, output);
- }
-
- [Fact]
- public void AutoSelectKnownAndUnknownPockets()
- {
- var selection = new LabelSelectionViewModel(Money.Parse("1.0"));
-
- var pockets = new List<Pocket>();
- pockets.AddPocket(0.5M, out var pocket1, CoinPocketHelper.PrivateFundsText);
- pockets.AddPocket(0.5M, out var pocket2, "Dan");
- pockets.AddPocket(0.8M, out var pocket3, CoinPocketHelper.UnlabelledFundsText);
- pockets.AddPocket(0.4M, out var pocket4, CoinPocketHelper.SemiPrivateFundsText);
-
- selection.Reset(pockets.ToArray());
-
- var output = selection.AutoSelectPockets("Dan");
- Assert.DoesNotContain(pocket1, output);
- Assert.Contains(pocket2, output);
- Assert.Contains(pocket3, output);
- Assert.DoesNotContain(pocket4, output);
- }
-
- [Fact]
- public void AutoSelectPrivateAndKnownPockets()
- {
- var selection = new LabelSelectionViewModel(Money.Parse("1.0"));
-
- var pockets = new List<Pocket>();
- pockets.AddPocket(0.8M, out var pocket1, CoinPocketHelper.PrivateFundsText);
- pockets.AddPocket(0.5M, out var pocket2, "Dan");
- pockets.AddPocket(0.4M, out var pocket3, CoinPocketHelper.UnlabelledFundsText);
- pockets.AddPocket(0.1M, out var pocket4, CoinPocketHelper.SemiPrivateFundsText);
-
- selection.Reset(pockets.ToArray());
-
- var output = selection.AutoSelectPockets("Dan");
- Assert.Contains(pocket1, output);
- Assert.Contains(pocket2, output);
- Assert.DoesNotContain(pocket3, output);
- Assert.DoesNotContain(pocket4, output);
- }
-
- [Fact]
- public void AutoSelectSemiPrivateAndKnownPockets()
- {
- var selection = new LabelSelectionViewModel(Money.Parse("1.0"));
-
- var pockets = new List<Pocket>();
- pockets.AddPocket(0.1M, out var pocket1, CoinPocketHelper.PrivateFundsText);
- pockets.AddPocket(0.5M, out var pocket2, "Dan");
- pockets.AddPocket(0.4M, out var pocket3, CoinPocketHelper.UnlabelledFundsText);
- pockets.AddPocket(0.8M, out var pocket4, CoinPocketHelper.SemiPrivateFundsText);
-
- selection.Reset(pockets.ToArray());
-
- var output = selection.AutoSelectPockets("Dan");
- Assert.DoesNotContain(pocket1, output);
- Assert.Contains(pocket2, output);
- Assert.DoesNotContain(pocket3, output);
- Assert.Contains(pocket4, output);
- }
-
[Fact]
public void AutoSelectPrivateAndSemiPrivateAndKnownPockets()
{
@@ -614,46 +506,6 @@ public class PocketSelectionTests
Assert.Contains(pocket4, output);
}
- [Fact]
- public void AutoSelectPrivateAndUnknownPockets()
- {
- var selection = new LabelSelectionViewModel(Money.Parse("1.0"));
-
- var pockets = new List<Pocket>();
- pockets.AddPocket(0.8M, out var pocket1, CoinPocketHelper.PrivateFundsText);
- pockets.AddPocket(0.1M, out var pocket2, "Dan");
- pockets.AddPocket(0.5M, out var pocket3, CoinPocketHelper.UnlabelledFundsText);
- pockets.AddPocket(0.05M, out var pocket4, CoinPocketHelper.SemiPrivateFundsText);
-
- selection.Reset(pockets.ToArray());
-
- var output = selection.AutoSelectPockets("Dan");
- Assert.Contains(pocket1, output);
- Assert.DoesNotContain(pocket2, output);
- Assert.Contains(pocket3, output);
- Assert.DoesNotContain(pocket4, output);
- }
-
- [Fact]
- public void AutoSelectSemiPrivateAndUnknownPockets()
- {
- var selection = new LabelSelectionViewModel(Money.Parse("1.0"));
-
- var pockets = new List<Pocket>();
- pockets.AddPocket(0.05M, out var pocket1, CoinPocketHelper.PrivateFundsText);
- pockets.AddPocket(0.1M, out var pocket2, "Dan");
- pockets.AddPocket(0.5M, out var pocket3, CoinPocketHelper.UnlabelledFundsText);
- pockets.AddPocket(0.8M, out var pocket4, CoinPocketHelper.SemiPrivateFundsText);
-
- selection.Reset(pockets.ToArray());
-
- var output = selection.AutoSelectPockets("Dan");
- Assert.DoesNotContain(pocket1, output);
- Assert.DoesNotContain(pocket2, output);
- Assert.Contains(pocket3, output);
- Assert.Contains(pocket4, output);
- }
-
[Fact]
public void AutoSelectPrivateAndSemiPrivateAndUnknownPockets()
{

Fix AutoSelectPockets