Add TryGetSelectedWalletViewModel to WalletManagerViewModel
MODIFY
WalletWasabi.Fluent/ViewModels/MainViewModel.cs
WalletWasabi.Fluent/ViewModels/MainViewModel.cs
@@ -194,7 +194,7 @@ public partial class MainViewModel : ViewModelBase
WalletCoinsViewModel.RegisterLazy(() =>
{
- if (UiServices.WalletManager.Wallets.FirstOrDefault(x => x.IsSelected) is WalletViewModel walletViewModel)
+ if (UiServices.WalletManager.TryGetSelectedWalletViewModel(out var walletViewModel))
{
return new WalletCoinsViewModel(walletViewModel);
}
@@ -204,7 +204,7 @@ public partial class MainViewModel : ViewModelBase
CoinJoinSettingsViewModel.RegisterLazy(() =>
{
- if (UiServices.WalletManager.Wallets.FirstOrDefault(x => x.IsSelected) is WalletViewModel walletViewModel && !walletViewModel.IsWatchOnly)
+ if (UiServices.WalletManager.TryGetSelectedWalletViewModel(out var walletViewModel) && !walletViewModel.IsWatchOnly)
{
return walletViewModel.CoinJoinSettings;
}
@@ -214,7 +214,7 @@ public partial class MainViewModel : ViewModelBase
WalletSettingsViewModel.RegisterLazy(() =>
{
- if (UiServices.WalletManager.Wallets.FirstOrDefault(x => x.IsSelected) is WalletViewModel walletViewModel)
+ if (UiServices.WalletManager.TryGetSelectedWalletViewModel(out var walletViewModel))
{
return walletViewModel.Settings;
}
@@ -224,7 +224,7 @@ public partial class MainViewModel : ViewModelBase
WalletStatsViewModel.RegisterLazy(() =>
{
- if (UiServices.WalletManager.Wallets.FirstOrDefault(x => x.IsSelected) is WalletViewModel walletViewModel)
+ if (UiServices.WalletManager.TryGetSelectedWalletViewModel(out var walletViewModel))
{
return new WalletStatsViewModel(walletViewModel);
}
@@ -234,7 +234,7 @@ public partial class MainViewModel : ViewModelBase
WalletInfoViewModel.RegisterLazy(() =>
{
- if (UiServices.WalletManager.Wallets.FirstOrDefault(x => x.IsSelected) is WalletViewModel walletViewModel)
+ if (UiServices.WalletManager.TryGetSelectedWalletViewModel(out var walletViewModel))
{
// TODO: Display password dialog if needed, see WalletInfoCommand execute action.
return new WalletInfoViewModel(walletViewModel);
@@ -245,7 +245,7 @@ public partial class MainViewModel : ViewModelBase
SendViewModel.RegisterLazy(() =>
{
- if (UiServices.WalletManager.Wallets.FirstOrDefault(x => x.IsSelected) is WalletViewModel walletViewModel)
+ if (UiServices.WalletManager.TryGetSelectedWalletViewModel(out var walletViewModel))
{
// TODO: Check if we can send?
return new SendViewModel(walletViewModel);
@@ -256,7 +256,7 @@ public partial class MainViewModel : ViewModelBase
ReceiveViewModel.RegisterLazy(() =>
{
- if (UiServices.WalletManager.Wallets.FirstOrDefault(x => x.IsSelected) is WalletViewModel walletViewModel)
+ if (UiServices.WalletManager.TryGetSelectedWalletViewModel(out var walletViewModel))
{
return new ReceiveViewModel(walletViewModel.Wallet);
}

MODIFY
WalletWasabi.Fluent/ViewModels/WalletManagerViewModel.cs
WalletWasabi.Fluent/ViewModels/WalletManagerViewModel.cs
@@ -110,6 +110,12 @@ public partial class WalletManagerViewModel : ViewModelBase
public ObservableCollection<WalletViewModelBase> Wallets => _wallets;
+ public bool TryGetSelectedWalletViewModel([NotNullWhen(true)] out WalletViewModel? walletViewModel)
+ {
+ walletViewModel = Wallets.OfType<WalletViewModel>().FirstOrDefault(x => x.IsSelected);
+ return walletViewModel is { };
+ }
+
public WalletViewModel GetWalletViewModel(Wallet wallet)
{
if (TryGetWalletViewModel(wallet, out var walletViewModel) && walletViewModel is WalletViewModel result)

Add TryGetSelectedWalletViewModel to WalletManagerViewModel