Refactor wallet actions
MODIFY
WalletWasabi.Fluent/ViewModels/NavBar/NavBarViewModel.cs
WalletWasabi.Fluent/ViewModels/NavBar/NavBarViewModel.cs
@@ -197,13 +197,17 @@ namespace WalletWasabi.Fluent.ViewModels.NavBar
{
if (walletManager.Items.Contains(x) || _topItems.Contains(x) || _bottomItems.Contains(x))
{
- // TODO: TEMP
+ if (!_isNavigating)
+ {
+ _isNavigating = true;
+
walletManager.SelectionChanged(x);
- if (!_isNavigating && x.SelectionMode == NavBarItemSelectionMode.Selected)
+ if (x.SelectionMode == NavBarItemSelectionMode.Selected)
{
- _isNavigating = true;
SetSelectedItem(x);
+ }
+
_isNavigating = false;
}
}
@@ -219,7 +223,6 @@ namespace WalletWasabi.Fluent.ViewModels.NavBar
x.OpenCommand.Execute(default);
}
- // TODO: TEMP
_walletManager.SelectionChanged(x);
CollapseOnClickAction?.Invoke();

MODIFY
WalletWasabi.Fluent/ViewModels/WalletManagerViewModel.cs
WalletWasabi.Fluent/ViewModels/WalletManagerViewModel.cs
@@ -18,7 +18,7 @@ namespace WalletWasabi.Fluent.ViewModels
{
private readonly Dictionary<Wallet, WalletViewModelBase> _walletDictionary;
private readonly Dictionary<WalletViewModelBase, List<NavBarItemViewModel>> _walletActionsDictionary;
- [AutoNotify] private ViewModelBase? _selectedItem;
+ [AutoNotify] private WalletViewModelBase? _selectedWallet;
[AutoNotify] private bool _loggedInAndSelectedAlwaysFirst;
[AutoNotify] private ObservableCollection<NavBarItemViewModel> _items;
[AutoNotify] private ObservableCollection<WalletViewModelBase> _wallets;
@@ -28,12 +28,10 @@ namespace WalletWasabi.Fluent.ViewModels
{
Model = walletManager;
_walletDictionary = new Dictionary<Wallet, WalletViewModelBase>();
- // TODO: TEMP
_walletActionsDictionary = new Dictionary<WalletViewModelBase, List<NavBarItemViewModel>>();
_items = new ObservableCollection<NavBarItemViewModel>();
_wallets = new ObservableCollection<WalletViewModelBase>();
- // TODO: TEMP
- _loggedInAndSelectedAlwaysFirst = false;
+ _loggedInAndSelectedAlwaysFirst = true;
Observable
.FromEventPattern<WalletState>(walletManager, nameof(WalletManager.WalletStateChanged))
@@ -79,22 +77,11 @@ namespace WalletWasabi.Fluent.ViewModels
private void OpenClosedWallet(WalletManager walletManager, UiConfig uiConfig, ClosedWalletViewModel closedWalletViewModel)
{
- // TODO: TEMP
- // var select = SelectedItem == closedWalletViewModel;
-
RemoveWallet(closedWalletViewModel);
var walletViewModel = OpenWallet(walletManager, uiConfig, closedWalletViewModel.Wallet);
- // TODO: TEMP
- // walletViewModel.Navigate().Clear();
- // walletViewModel.Navigate(NavigationTarget.HomeScreen).To(walletViewModel);
-
- // TODO: TEMP
- // if (select)
- // {
- // SelectedItem = walletViewModel;
- // }
+ // TODO: Handle walletViewModel
}
private WalletViewModelBase OpenWallet(WalletManager walletManager, UiConfig uiConfig, Wallet wallet)
@@ -108,12 +95,6 @@ namespace WalletWasabi.Fluent.ViewModels
InsertWallet(walletViewModel);
- // TODO: TEMP
- // if (!walletManager.AnyWallet(x => x.State >= WalletState.Started && x != walletViewModel.Wallet))
- // {
- // walletViewModel.OpenWalletTabs();
- // }
-
walletViewModel.IsExpanded = true;
return walletViewModel;
@@ -152,48 +133,34 @@ namespace WalletWasabi.Fluent.ViewModels
}
}
- private void OpenActions(WalletViewModelBase walletViewModel, List<NavBarItemViewModel> result)
+ public void SelectionChanged(NavBarItemViewModel item)
{
- // TODO: Insert current lodged in wallet at the top of the items list.
- if (_loggedInAndSelectedAlwaysFirst)
+ if (SelectedWallet == item)
{
- _items.Remove(walletViewModel);
- _items.Insert(0, walletViewModel);
-
- _wallets.Remove(walletViewModel);
- _wallets.Insert(0, walletViewModel);
+ return;
}
- // TODO: TEMP
- var index = _wallets.IndexOf(walletViewModel);
- if (index >= 0)
+ if (SelectedWallet is WalletViewModelBase walletViewModelPrevious && walletViewModelPrevious.Wallet.IsLoggedIn)
{
- var insertIndex = index;
- // Add top separator only when wallet is not first item.
- if (index > 0)
+ if (item is WalletViewModelBase && SelectedWallet != item)
{
- var topSeparator = new SeparatorItemViewModel();
- _items.Insert(index, topSeparator);
- result.Add(topSeparator);
- insertIndex += 1;
- }
+ RemoveActions(walletViewModelPrevious);
- var actions = GetWalletActions(walletViewModel);
-
- for (var i = 0; i < actions.Count; i++)
- {
- var action = actions[i];
- _items.Insert(insertIndex + i + 1, action);
- result.Add(action);
+ SelectedWallet = null;
+ }
}
- // Add bottom separator only when wallet is not first or last item.
- if (_wallets.Count > 1 && index != _wallets.Count - 1)
+ if (item is WalletViewModelBase walletViewModelSelected && walletViewModelSelected.Wallet.IsLoggedIn)
{
- var bottomSeparator = new SeparatorItemViewModel();
- _items.Insert(insertIndex + actions.Count + 1, bottomSeparator);
- result.Add(bottomSeparator);
+ if (!_walletActionsDictionary.TryGetValue(walletViewModelSelected, out var actions))
+ {
+ actions = new List<NavBarItemViewModel>();
}
+
+ _walletActionsDictionary[walletViewModelSelected] = actions;
+ InsertActions(walletViewModelSelected, actions);
+
+ SelectedWallet = walletViewModelSelected;
}
}
@@ -219,39 +186,59 @@ namespace WalletWasabi.Fluent.ViewModels
return actions;
}
- public void SelectionChanged(NavBarItemViewModel item)
+ private void InsertActions(WalletViewModelBase walletViewModel, List<NavBarItemViewModel> result)
{
- if (SelectedItem == item)
+ // Insert current lodged in wallet at the top of the items list.
+ if (_loggedInAndSelectedAlwaysFirst)
{
- return;
- }
+ _items.Remove(walletViewModel);
+ _items.Insert(0, walletViewModel);
- var previousItem = SelectedItem;
+ _wallets.Remove(walletViewModel);
+ _wallets.Insert(0, walletViewModel);
+ }
- if (previousItem is WalletViewModelBase walletViewModelPrevious && previousItem != item && item is not WalletActionViewModel && walletViewModelPrevious.Wallet.IsLoggedIn)
+ var index = _wallets.IndexOf(walletViewModel);
+ if (index >= 0)
{
- var actions = _walletActionsDictionary[walletViewModelPrevious];
- foreach (var action in actions)
+ var insertIndex = index;
+ // Add top separator only when wallet is not first item.
+ if (index > 0)
{
- _items.Remove(action);
+ var topSeparator = new SeparatorItemViewModel();
+ _items.Insert(index, topSeparator);
+ result.Add(topSeparator);
+ insertIndex += 1;
}
- // actions.Clear();
- SelectedItem = null;
- }
+ var actions = GetWalletActions(walletViewModel);
- if (item is WalletViewModelBase walletViewModelSelected && walletViewModelSelected.Wallet.IsLoggedIn)
+ for (var i = 0; i < actions.Count; i++)
{
- SelectedItem = walletViewModelSelected;
+ var action = actions[i];
+ _items.Insert(insertIndex + i + 1, action);
+ result.Add(action);
+ }
- if (!_walletActionsDictionary.TryGetValue(walletViewModelSelected, out var actions))
+ // Add bottom separator only when wallet is not first or last item.
+ if (_wallets.Count > 1 && index != _wallets.Count - 1)
{
- actions = new List<NavBarItemViewModel>();
+ var bottomSeparator = new SeparatorItemViewModel();
+ _items.Insert(insertIndex + actions.Count + 1, bottomSeparator);
+ result.Add(bottomSeparator);
+ }
+ }
}
- _walletActionsDictionary[walletViewModelSelected] = actions;
- OpenActions(walletViewModelSelected, actions);
+ private void RemoveActions(WalletViewModelBase walletViewModelPrevious)
+ {
+ var actions = _walletActionsDictionary[walletViewModelPrevious];
+ foreach (var action in actions)
+ {
+ _items.Remove(action);
}
+
+ actions.Clear();
}
}
}
\ No newline at end of file

MODIFY
WalletWasabi.Fluent/ViewModels/Wallets/WalletViewModel.cs
WalletWasabi.Fluent/ViewModels/Wallets/WalletViewModel.cs
@@ -19,16 +19,10 @@ namespace WalletWasabi.Fluent.ViewModels.Wallets
{
public partial class WalletViewModel : WalletViewModelBase
{
- // TODO: TEMP
- // [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.");
- // TODO: TEMP
- // _actions = new ObservableCollection<WalletActionViewModel>();
-
uiConfig = Locator.Current.GetService<Global>().UiConfig;
Observable.Merge(
@@ -53,21 +47,6 @@ namespace WalletWasabi.Fluent.ViewModels.Wallets
}
})
.DisposeWith(Disposables);
-
- // TODO: TEMP
- /*if (Wallet.KeyManager.IsHardwareWallet || !Wallet.KeyManager.IsWatchOnly)
- {
- _actions.Add(new SendWalletActionViewModel(this));
- }
-
- _actions.Add(new ReceiveWalletActionViewModel(this));
-
- if (!Wallet.KeyManager.IsWatchOnly)
- {
- _actions.Add(new CoinJoinWalletActionViewModel(this));
- }
-
- _actions.Add(new AdvancedWalletActionViewModel(this));*/
}
private CompositeDisposable Disposables { get; set; }
@@ -82,12 +61,5 @@ namespace WalletWasabi.Fluent.ViewModels.Wallets
? new WatchOnlyWalletViewModel(uiConfig, wallet)
: new WalletViewModel(uiConfig, wallet);
}
-
- // TODO: TEMP
- /*
- public void OpenWalletTabs()
- {
- // TODO: Implement.
- }*/
}
}

Refactor wallet actions