Fix filtering of labels
MODIFY
WalletWasabi.Fluent/ViewModels/Wallets/Receive/ReceiveViewModel.cs
WalletWasabi.Fluent/ViewModels/Wallets/Receive/ReceiveViewModel.cs
@@ -27,16 +27,16 @@ namespace WalletWasabi.Fluent.ViewModels.Wallets.Receive
public partial class ReceiveViewModel : NavBarItemViewModel
{
private readonly Wallet _wallet;
- private readonly ObservableCollection<SuggestionLabelViewModel>? _suggestionLabels;
- private readonly ReadOnlyObservableCollection<SuggestionLabelViewModel>? _suggestionLabelResults;
- [AutoNotify] private ObservableCollection<string> _labels;
+ private readonly SourceList<SuggestionLabelViewModel> _suggestionLabels;
+ private readonly ObservableCollectionExtended<SuggestionLabelViewModel> _suggestionLabelResults;
+ private readonly ObservableCollectionExtended<string> _labels;
[AutoNotify] private HashSet<string> _suggestions;
[AutoNotify] private bool _isExistingAddressesButtonVisible;
public ReceiveViewModel(Wallet wallet) : base(NavigationMode.Normal)
{
_wallet = wallet;
- _labels = new ObservableCollection<string>();
+ _labels = new ObservableCollectionExtended<string>();
var allLabels = GetLabels();
var mostUsedLabels = allLabels.GroupBy(x => x)
@@ -50,7 +50,10 @@ namespace WalletWasabi.Fluent.ViewModels.Wallets.Receive
_suggestions = mostUsedLabels.Select(x => x.Label).ToHashSet();
- _suggestionLabels = new ObservableCollection<SuggestionLabelViewModel>(
+ _suggestionLabels = new SourceList<SuggestionLabelViewModel>();
+ _suggestionLabelResults = new ObservableCollectionExtended<SuggestionLabelViewModel>();
+
+ _suggestionLabels.AddRange(
mostUsedLabels.Select(x =>
{
return new SuggestionLabelViewModel(
@@ -64,13 +67,13 @@ namespace WalletWasabi.Fluent.ViewModels.Wallets.Receive
.Select(SuggestionLabelsFilter);
_suggestionLabels
- .ToObservableChangeSet()
+ .Connect()
.Filter(suggestionLabelsFilter)
.Sort(SortExpressionComparer<SuggestionLabelViewModel>.Descending(x => x.Count))
- .Take(3)
+ .Top(3)
.ObserveOn(RxApp.MainThreadScheduler)
- .Bind(out _suggestionLabelResults)
- .AsObservableList();
+ .Bind(_suggestionLabelResults)
+ .Subscribe();
SelectionMode = NavBarItemSelectionMode.Button;
@@ -84,7 +87,9 @@ namespace WalletWasabi.Fluent.ViewModels.Wallets.Receive
ShowExistingAddressesCommand = ReactiveCommand.Create(OnShowExistingAddresses);
}
- public ReadOnlyObservableCollection<SuggestionLabelViewModel> SuggestionLabelResults => _suggestionLabelResults!;
+ public ObservableCollection<SuggestionLabelViewModel> SuggestionLabelResults => _suggestionLabelResults;
+
+ public ObservableCollection<string> Labels => _labels;
private Func<SuggestionLabelViewModel, bool> SuggestionLabelsFilter(Unit unit)
{

Fix filtering of labels