use sourcelist, (remove unnecessary stuff)
MODIFY
WalletWasabi.Fluent/ViewModels/AddWallet/HardwareWallet/ConnectHardwareWalletViewModel.cs
WalletWasabi.Fluent/ViewModels/AddWallet/HardwareWallet/ConnectHardwareWalletViewModel.cs
@@ -29,7 +29,7 @@ public partial class ConnectHardwareWalletViewModel : RoutableViewModel
{
_message = "";
WalletName = walletName;
- Wallets = UiServices.WalletManager.Wallets;
+ Wallets = UiServices.WalletManager.Items;
AbandonedTasks = new AbandonedTasks();
CancelCts = new CancellationTokenSource();

MODIFY
WalletWasabi.Fluent/ViewModels/MainViewModel.cs
WalletWasabi.Fluent/ViewModels/MainViewModel.cs
@@ -182,7 +182,7 @@ public partial class MainViewModel : ViewModelBase
public void InvalidateIsCoinJoinActive()
{
- IsCoinJoinActive = UiServices.WalletManager.Wallets.OfType<WalletViewModel>()
+ IsCoinJoinActive = UiServices.WalletManager.Items.OfType<WalletViewModel>()
.Any(x => x.IsCoinJoining);
}

MODIFY
WalletWasabi.Fluent/ViewModels/NavBar/NavBarViewModel.cs
WalletWasabi.Fluent/ViewModels/NavBar/NavBarViewModel.cs
@@ -43,7 +43,7 @@ public partial class NavBarViewModel : ViewModelBase
this.WhenAnyValue(x => x.Items.Count)
.Where(count => count > 0 && SelectedItem is null && !UiServices.WalletManager.IsLoadingWallet)
- .Select(_ => Items.FirstOrDefault(item => item is WalletViewModelBase wallet && wallet.WalletName == Services.UiConfig.LastSelectedWallet) ?? Items.FirstOrDefault())
+ .Select(_ => Items.FirstOrDefault(item => item.WalletName == Services.UiConfig.LastSelectedWallet) ?? Items.FirstOrDefault())
.Subscribe(itemToSelect => SelectedItem = itemToSelect);
UiServices.WalletManager.WhenAnyValue(x => x.SelectedWallet)
@@ -52,9 +52,7 @@ public partial class NavBarViewModel : ViewModelBase
.Subscribe(x => SelectedItem = x);
}
- public ReadOnlyObservableCollection<NavBarItemViewModel> Items => UiServices.WalletManager.Items;
-
- public ObservableCollection<WalletViewModelBase> Wallets => UiServices.WalletManager.Wallets;
+ public ObservableCollection<WalletViewModelBase> Items => UiServices.WalletManager.Items;
public NavBarItemViewModel? SelectedItem
{

MODIFY
WalletWasabi.Fluent/ViewModels/WalletManagerViewModel.cs
WalletWasabi.Fluent/ViewModels/WalletManagerViewModel.cs
-using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
@@ -20,31 +19,21 @@ namespace WalletWasabi.Fluent.ViewModels;
public partial class WalletManagerViewModel : ViewModelBase
{
- private readonly ReadOnlyObservableCollection<NavBarItemViewModel> _items;
+ private readonly SourceList<WalletViewModelBase> _walletsSourceList = new();
+ private readonly ObservableCollectionExtended<WalletViewModelBase> _items = new();
+
private NavBarItemViewModel? _currentSelection;
[AutoNotify] private WalletViewModelBase? _selectedWallet;
[AutoNotify(SetterModifier = AccessModifier.Private)] private bool _isLoadingWallet;
- [AutoNotify] private ObservableCollection<WalletViewModelBase> _wallets;
public WalletManagerViewModel()
{
- _wallets = new ObservableCollection<WalletViewModelBase>();
-
- static Func<WalletViewModelBase, bool> SelectedWalletFilter(WalletViewModelBase? selected)
- {
- return item => selected is null || item != selected;
- }
-
- var selectedWalletFilter = this.WhenValueChanged(t => t.SelectedWallet).Select(SelectedWalletFilter);
-
- _wallets
- .ToObservableChangeSet()
- .Filter(selectedWalletFilter)
+ _walletsSourceList
+ .Connect()
.Sort(SortExpressionComparer<WalletViewModelBase>.Descending(i => i.WalletState).ThenByDescending(i => i.IsLoggedIn).ThenByAscending(i => i.Title))
- .Transform(x => x as NavBarItemViewModel)
.ObserveOn(RxApp.MainThreadScheduler)
- .Bind(out _items)
- .AsObservableList();
+ .Bind(_items)
+ .Subscribe();
Observable
.FromEventPattern<WalletState>(Services.WalletManager, nameof(WalletManager.WalletStateChanged))
@@ -123,7 +112,7 @@ public partial class WalletManagerViewModel : ViewModelBase
RxApp.MainThreadScheduler.Schedule(() => EnumerateWallets());
}
- public ReadOnlyObservableCollection<NavBarItemViewModel> Items => _items;
+ public ObservableCollection<WalletViewModelBase> Items => _items;
public WalletViewModel GetWalletViewModel(Wallet wallet)
{
@@ -174,7 +163,7 @@ public partial class WalletManagerViewModel : ViewModelBase
private WalletViewModel OpenWallet(Wallet wallet)
{
- if (_wallets.Any(x => x.Title == wallet.WalletName))
+ if (Items.Any(x => x.Title == wallet.WalletName))
{
throw new Exception("Wallet already opened.");
}
@@ -190,12 +179,12 @@ public partial class WalletManagerViewModel : ViewModelBase
private void InsertWallet(WalletViewModelBase wallet)
{
- _wallets.InsertSorted(wallet);
+ _walletsSourceList.Add(wallet);
}
private void RemoveWallet(WalletViewModelBase walletViewModel)
{
- _wallets.Remove(walletViewModel);
+ _walletsSourceList.Remove(walletViewModel);
}
private void EnumerateWallets()
@@ -240,8 +229,7 @@ public partial class WalletManagerViewModel : ViewModelBase
private bool TryGetWalletViewModel(Wallet wallet, [NotNullWhen(true)] out WalletViewModelBase? walletViewModel)
{
- walletViewModel = _wallets.FirstOrDefault(x => x.Wallet == wallet);
-
+ walletViewModel = _walletsSourceList.Items.FirstOrDefault(x => x.Wallet == wallet);
return walletViewModel is { };
}
}

MODIFY
WalletWasabi.Fluent/Views/NavBar/NavBar.axaml
WalletWasabi.Fluent/Views/NavBar/NavBar.axaml
<Separator DockPanel.Dock="Bottom" />
<!-- Wallet List -->
<DockPanel Background="Transparent">
- <c:NavBarListBox Items="{Binding Wallets}"
+ <c:NavBarListBox Items="{Binding Items}"
SelectedItem="{Binding SelectedItem, Mode=TwoWay}"
ReSelectSelectedItem="False"
Name="ItemsListBox"

use sourcelist, (remove unnecessary stuff)