Improve label fetching for suggestions.
MODIFY
WalletWasabi.Gui/Controls/WalletExplorer/ReceiveTabViewModel.cs
WalletWasabi.Gui/Controls/WalletExplorer/ReceiveTabViewModel.cs
@@ -35,7 +35,7 @@ namespace WalletWasabi.Gui.Controls.WalletExplorer
Global = Locator.Current.GetService<Global>();
Wallet = wallet;
- LabelSuggestion = new SuggestLabelViewModel(Wallet);
+ LabelSuggestion = new SuggestLabelViewModel();
_addresses = new ObservableCollection<AddressViewModel>();
LabelSuggestion.Label = "";

MODIFY
WalletWasabi.Gui/Controls/WalletExplorer/SendControlViewModel.cs
WalletWasabi.Gui/Controls/WalletExplorer/SendControlViewModel.cs
@@ -109,7 +109,7 @@ namespace WalletWasabi.Gui.Controls.WalletExplorer
Global = Locator.Current.GetService<Global>();
Wallet = wallet;
- LabelSuggestion = new SuggestLabelViewModel(Wallet);
+ LabelSuggestion = new SuggestLabelViewModel();
BuildTransactionButtonText = DoButtonText;
ResetUi();

MODIFY
WalletWasabi.Gui/Suggestions/SuggestLabelViewModel.cs
WalletWasabi.Gui/Suggestions/SuggestLabelViewModel.cs
@@ -16,17 +16,19 @@ namespace WalletWasabi.Gui.Suggestions
private int _caretIndex;
private string _label;
- public SuggestLabelViewModel(Wallet wallet)
+ public SuggestLabelViewModel()
{
+ Global = Locator.Current.GetService<Global>();
_suggestions = new ObservableCollection<SuggestionViewModel>();
this.WhenAnyValue(x => x.Label)
.Throttle(TimeSpan.FromMilliseconds(100))
.ObserveOn(RxApp.MainThreadScheduler)
.Subscribe(UpdateSuggestions);
- Wallet = wallet;
}
+ private Global Global { get; }
+
public int CaretIndex
{
get => _caretIndex;
@@ -45,8 +47,6 @@ namespace WalletWasabi.Gui.Suggestions
set => this.RaiseAndSetIfChanged(ref _suggestions, value);
}
- private Wallet Wallet { get; }
-
public void Reset()
{
Suggestions = new ObservableCollection<SuggestionViewModel>();
@@ -89,7 +89,8 @@ namespace WalletWasabi.Gui.Suggestions
return;
}
- var labels = Wallet.GetLabels();
+ var labels = Global.WalletManager.GetLabels().SelectMany(x => x.Labels).ToHashSet();
+
IEnumerable<string> suggestedWords = labels.Where(w => w.StartsWith(lastWord, StringComparison.InvariantCultureIgnoreCase))
.Union(labels.Where(w => w.Contains(lastWord, StringComparison.InvariantCultureIgnoreCase)))
.Except(enteredWordList)

MODIFY
WalletWasabi/Blockchain/Keys/KeyManager.cs
WalletWasabi/Blockchain/Keys/KeyManager.cs
@@ -571,6 +571,8 @@ namespace WalletWasabi.Blockchain.Keys
return extKeysAndPubs;
}
+ public IEnumerable<SmartLabel> GetLabels() => GetKeys().Select(x => x.Label);
+
public ExtKey GetMasterExtKey(string password)
{
if (password is null)

MODIFY
WalletWasabi/Blockchain/Transactions/AllTransactionStore.cs
WalletWasabi/Blockchain/Transactions/AllTransactionStore.cs
@@ -6,6 +6,7 @@ using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
+using WalletWasabi.Blockchain.Analysis.Clustering;
using WalletWasabi.Helpers;
using WalletWasabi.Logging;
@@ -253,6 +254,8 @@ namespace WalletWasabi.Blockchain.Transactions
}
}
+ public IEnumerable<SmartLabel> GetLabels() => GetTransactions().Select(x => x.Label);
+
#endregion Accessors
}
}

MODIFY
WalletWasabi/Wallets/Wallet.cs
WalletWasabi/Wallets/Wallet.cs
@@ -306,13 +306,6 @@ namespace WalletWasabi.Wallets
}
}
- public ISet<string> GetLabels() => TransactionProcessor.Coins.AsAllCoinsView()
- .SelectMany(x => x.Label.Labels)
- .Concat(KeyManager
- .GetKeys()
- .SelectMany(x => x.Label.Labels))
- .ToHashSet();
-
/// <inheritdoc/>
public async override Task StopAsync(CancellationToken cancel)
{

MODIFY
WalletWasabi/Wallets/WalletManager.cs
WalletWasabi/Wallets/WalletManager.cs
@@ -9,6 +9,7 @@ using System.Text;
using System.Threading;
using System.Threading.Tasks;
using WalletWasabi.BitcoinCore;
+using WalletWasabi.Blockchain.Analysis.Clustering;
using WalletWasabi.Blockchain.Analysis.FeesEstimation;
using WalletWasabi.Blockchain.Keys;
using WalletWasabi.Blockchain.TransactionOutputs;
@@ -79,6 +80,37 @@ namespace WalletWasabi.Wallets
}
}
+ public IEnumerable<SmartLabel> GetLabels()
+ {
+ var keyManagers = new List<KeyManager>();
+ lock (Lock)
+ {
+ keyManagers = Wallets.Keys
+ .Where(x => x.KeyManager is { })
+ .Select(x => x.KeyManager)
+ .ToList();
+ }
+
+ var labels = keyManagers
+ .SelectMany(x => x.GetLabels());
+
+ var txStore = BitcoinStore?.TransactionStore;
+ if (txStore is { })
+ {
+ labels = labels.Concat(txStore.GetLabels());
+ }
+
+ return labels;
+ }
+
+ public IEnumerable<SmartLabel> GetAllKeyLabels()
+ {
+ lock (Lock)
+ {
+ return Wallets.Keys.Where(x => x.KeyManager is { }).SelectMany(x => x.KeyManager.GetLabels());
+ }
+ }
+
private IFeeProvider FeeProvider { get; set; }
private CoreNode BitcoinCoreNode { get; set; }
public Network Network { get; }

Improve label fetching for suggestions.