Add wallet action to navbar when when wallet is opened
MODIFY
WalletWasabi.Fluent/ViewModels/AddWallet/AddedWalletPageViewModel.cs
WalletWasabi.Fluent/ViewModels/AddWallet/AddedWalletPageViewModel.cs
@@ -4,6 +4,7 @@ using ReactiveUI;
using WalletWasabi.Blockchain.Keys;
using WalletWasabi.Fluent.ViewModels.NavBar;
using WalletWasabi.Fluent.ViewModels.Navigation;
+using WalletWasabi.Fluent.ViewModels.Wallets;
using WalletWasabi.Wallets;
namespace WalletWasabi.Fluent.ViewModels.AddWallet
@@ -30,7 +31,7 @@ namespace WalletWasabi.Fluent.ViewModels.AddWallet
var navBar = NavigationManager.Get<NavBarViewModel>();
- var wallet = navBar?.Items.FirstOrDefault(x => x.WalletName == WalletName);
+ var wallet = navBar?.Items.OfType<WalletViewModelBase>().FirstOrDefault(x => x.WalletName == WalletName);
if (wallet is { } && navBar is { })
{

MODIFY
WalletWasabi.Fluent/ViewModels/NavBar/NavBarViewModel.cs
WalletWasabi.Fluent/ViewModels/NavBar/NavBarViewModel.cs
@@ -72,7 +72,7 @@ namespace WalletWasabi.Fluent.ViewModels.NavBar
});
}
- public ObservableCollection<WalletViewModelBase> Items => _walletManager.Items;
+ public ObservableCollection<NavBarItemViewModel> Items => _walletManager.Items;
public NavBarItemViewModel? SelectedItem
{

MODIFY
WalletWasabi.Fluent/ViewModels/WalletManagerViewModel.cs
WalletWasabi.Fluent/ViewModels/WalletManagerViewModel.cs
@@ -5,6 +5,7 @@ using System.Linq;
using System.Reactive.Linq;
using Avalonia.Threading;
using ReactiveUI;
+using WalletWasabi.Fluent.ViewModels.NavBar;
using WalletWasabi.Fluent.ViewModels.Wallets;
using WalletWasabi.Gui;
using WalletWasabi.Gui.ViewModels;
@@ -15,15 +16,17 @@ namespace WalletWasabi.Fluent.ViewModels
public partial class WalletManagerViewModel : ViewModelBase
{
private readonly Dictionary<Wallet, WalletViewModelBase> _walletDictionary;
- [AutoNotify] private WalletViewModelBase? _selectedItem;
- [AutoNotify] private ObservableCollection<WalletViewModelBase> _items;
+ [AutoNotify] private ViewModelBase? _selectedItem;
+ [AutoNotify] private ObservableCollection<NavBarItemViewModel> _items;
+ [AutoNotify] private ObservableCollection<WalletViewModelBase> _wallets;
[AutoNotify] private bool _anyWalletStarted;
public WalletManagerViewModel(WalletManager walletManager, UiConfig uiConfig)
{
Model = walletManager;
_walletDictionary = new Dictionary<Wallet, WalletViewModelBase>();
- _items = new ObservableCollection<WalletViewModelBase>();
+ _items = new ObservableCollection<NavBarItemViewModel>();
+ _wallets = new ObservableCollection<WalletViewModelBase>();
Observable
.FromEventPattern<WalletState>(walletManager, nameof(WalletManager.WalletStateChanged))
@@ -45,7 +48,7 @@ namespace WalletWasabi.Fluent.ViewModels
}
}
- AnyWalletStarted = Items.Any(y => y.WalletState == WalletState.Started);
+ AnyWalletStarted = Items.OfType<WalletViewModelBase>().Any(y => y.WalletState == WalletState.Started);
});
Observable
@@ -83,7 +86,7 @@ namespace WalletWasabi.Fluent.ViewModels
private WalletViewModelBase OpenWallet(WalletManager walletManager, UiConfig uiConfig, Wallet wallet)
{
- if (_items.OfType<WalletViewModel>().Any(x => x.Title == wallet.WalletName))
+ if (_wallets.OfType<WalletViewModel>().Any(x => x.Title == wallet.WalletName))
{
throw new Exception("Wallet already opened.");
}
@@ -95,6 +98,17 @@ namespace WalletWasabi.Fluent.ViewModels
if (!walletManager.AnyWallet(x => x.State >= WalletState.Started && x != walletViewModel.Wallet))
{
walletViewModel.OpenWalletTabs();
+
+ // TODO: TEMP
+ var index = _wallets.IndexOf(walletViewModel);
+ if (index >= 0)
+ {
+ for (var i = 0; i < walletViewModel.Actions.Count; i++)
+ {
+ var action = walletViewModel.Actions[i];
+ _items.Insert(index + i + 1, action);
+ }
+ }
}
walletViewModel.IsExpanded = true;
@@ -104,7 +118,15 @@ namespace WalletWasabi.Fluent.ViewModels
private void InsertWallet(WalletViewModelBase wallet)
{
- Items.InsertSorted(wallet);
+ _wallets.InsertSorted(wallet);
+
+ // TODO: Handle wallet Action being present in Items collection.
+ var index = _wallets.IndexOf(wallet);
+ if (index >= 0)
+ {
+ _items.Insert(index, wallet);
+ }
+
_walletDictionary.Add(wallet.Wallet, wallet);
}
@@ -112,7 +134,10 @@ namespace WalletWasabi.Fluent.ViewModels
{
wallet.Dispose();
+ _wallets.Remove(wallet);
_items.Remove(wallet);
+ // TODO: Remove wallet Actions
+
_walletDictionary.Remove(wallet.Wallet);
}

MODIFY
WalletWasabi.Fluent/ViewModels/Wallets/WalletViewModel.cs
WalletWasabi.Fluent/ViewModels/Wallets/WalletViewModel.cs
@@ -2,6 +2,7 @@ using NBitcoin;
using ReactiveUI;
using Splat;
using System;
+using System.Collections;
using System.Collections.ObjectModel;
using System.Reactive;
using System.Reactive.Disposables;
@@ -16,13 +17,13 @@ namespace WalletWasabi.Fluent.ViewModels.Wallets
{
public partial class WalletViewModel : WalletViewModelBase
{
- [AutoNotify] private ObservableCollection<ViewModelBase> _actions;
+ [AutoNotify] private ObservableCollection<WalletActionViewModel> _actions;
protected WalletViewModel(UiConfig uiConfig, Wallet wallet) : base(wallet)
{
Disposables = Disposables is null ? new CompositeDisposable() : throw new NotSupportedException($"Cannot open {GetType().Name} before closing it.");
- _actions = new ObservableCollection<ViewModelBase>();
+ _actions = new ObservableCollection<WalletActionViewModel>();
uiConfig = Locator.Current.GetService<Global>().UiConfig;

Add wallet action to navbar when when wallet is opened