Refresh hw wallet list
MODIFY
WalletWasabi.Gui/MainWindow.xaml.cs
WalletWasabi.Gui/MainWindow.xaml.cs
@@ -182,22 +182,6 @@ namespace WalletWasabi.Gui
{
walletManagerViewModel.SelectGenerateWallet();
}
-
- try
- {
- // Likely HwiProcessManager is not initialized at this point so make sure it is.
- await HwiProcessManager.EnsureHwiInstalledAsync(Global.DataDir, Global.Network, logFound: false);
- var res = await HwiProcessManager.EnumerateAsync();
- var isAnyHardwareWalletAvailable = res.Any();
- if (isAnyHardwareWalletAvailable)
- {
- walletManagerViewModel.SelectHardwareWallet();
- }
- }
- catch (Exception ex)
- {
- Logging.Logger.LogWarning<MainWindow>(ex);
- }
}
}
}

MODIFY
WalletWasabi.Gui/Tabs/WalletManager/LoadWalletViewModel.cs
WalletWasabi.Gui/Tabs/WalletManager/LoadWalletViewModel.cs
@@ -4,6 +4,7 @@ using AvalonStudio.Shell;
using NBitcoin;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
+using Nito.AsyncEx;
using ReactiveUI;
using System;
using System.Collections.Generic;
@@ -47,12 +48,15 @@ namespace WalletWasabi.Gui.Tabs.WalletManager
public bool IsHardwareWallet => LoadWalletType == LoadWalletType.Hardware;
public bool IsDesktopWallet => LoadWalletType == LoadWalletType.Desktop;
+ private object WalletLock { get; }
+
public LoadWalletViewModel(WalletManagerViewModel owner, LoadWalletType loadWalletType) : base(loadWalletType == LoadWalletType.Password ? "Test Password" : (loadWalletType == LoadWalletType.Desktop ? "Load Wallet" : "Hardware Wallet"))
{
Owner = owner;
Password = "";
LoadWalletType = loadWalletType;
Wallets = new ObservableCollection<string>();
+ WalletLock = new object();
this.WhenAnyValue(x => x.SelectedWallet)
.Subscribe(selectedWallet => SetWalletStates());
@@ -89,6 +93,8 @@ namespace WalletWasabi.Gui.Tabs.WalletManager
OpenFolderCommand.ThrownExceptions.Subscribe(ex => Logger.LogWarning<LoadWalletViewModel>(ex));
SetLoadButtonText(IsBusy);
+
+ IsHwWalletSearchTextVisible = LoadWalletType == LoadWalletType.Hardware;
}
public bool IsHwWalletSearchTextVisible
@@ -211,16 +217,14 @@ namespace WalletWasabi.Gui.Tabs.WalletManager
}
public override void OnCategorySelected()
+ {
+ if (IsHardwareWallet) return;
+ lock (WalletLock)
{
Wallets.Clear();
Password = "";
SetValidationMessage("");
- if (IsHardwareWallet)
- {
- }
- else
- {
if (!File.Exists(Global.WalletsDir))
{
Directory.CreateDirectory(Global.WalletsDir);
@@ -232,11 +236,11 @@ namespace WalletWasabi.Gui.Tabs.WalletManager
{
Wallets.Add(Path.GetFileNameWithoutExtension(file.FullName));
}
- }
SelectedWallet = Wallets.FirstOrDefault();
SetWalletStates();
}
+ }
private void SetWalletStates()
{
@@ -427,5 +431,31 @@ namespace WalletWasabi.Gui.Tabs.WalletManager
var path = Global.WalletsDir;
IoHelpers.OpenFolderInFileExplorer(path);
}
+
+ public void RefreshHardwareWallets(IEnumerable<HardwareWalletInfo> hwis)
+ {
+ if (hwis.Any())
+ {
+ var alltypesunique = hwis.Count() == hwis.Select(x => x.Type).ToHashSet().Count();
+ lock (WalletLock)
+ {
+ foreach (HardwareWalletInfo hwi in hwis)
+ {
+ if (alltypesunique)
+ {
+ Wallets.Add(hwi.Type.ToString());
+ }
+ else
+ {
+ Wallets.Add($"{hwi.Type}-{hwi.Fingerprint}");
+ }
+ }
+
+ SelectedWallet = Wallets.FirstOrDefault();
+ SetWalletStates();
+ IsHwWalletSearchTextVisible = false;
+ }
+ }
+ }
}
}

MODIFY
WalletWasabi.Gui/Tabs/WalletManager/WalletManagerViewModel.cs
WalletWasabi.Gui/Tabs/WalletManager/WalletManagerViewModel.cs
@@ -9,6 +9,7 @@ using System.Threading.Tasks;
using WalletWasabi.Gui.ViewModels;
using WalletWasabi.Hwi;
using WalletWasabi.Hwi.Models;
+using WalletWasabi.Logging;
namespace WalletWasabi.Gui.Tabs.WalletManager
{
@@ -17,17 +18,21 @@ namespace WalletWasabi.Gui.Tabs.WalletManager
private ObservableCollection<CategoryViewModel> _categories;
private CategoryViewModel _selectedCategory;
private ViewModelBase _currentView;
- private Task DetectHardwareWalletTask { get; set; }
+ private LoadWalletViewModel LoadWalletViewModelDesktop { get; }
+ private LoadWalletViewModel LoadWalletViewModelHardware { get; }
public WalletManagerViewModel() : base("Wallet Manager")
{
+ LoadWalletViewModelDesktop = new LoadWalletViewModel(this, LoadWalletType.Desktop);
+ LoadWalletViewModelHardware = new LoadWalletViewModel(this, LoadWalletType.Hardware);
+
Categories = new ObservableCollection<CategoryViewModel>
{
new GenerateWalletViewModel(this),
new RecoverWalletViewModel(this),
- new LoadWalletViewModel(this, LoadWalletType.Desktop),
+ LoadWalletViewModelDesktop,
new LoadWalletViewModel(this, LoadWalletType.Password),
- new LoadWalletViewModel(this, LoadWalletType.Hardware)
+ LoadWalletViewModelHardware
};
SelectedCategory = Categories.FirstOrDefault();
@@ -90,7 +95,6 @@ namespace WalletWasabi.Gui.Tabs.WalletManager
Dispatcher.UIThread.PostLogException(async () =>
{
- DetectHardwareWalletTask = RefreshHardwareWalletListAsync();
await RefreshHardwareWalletListAsync();
HardwareWalletRefreshCancel?.Dispose();
});
@@ -100,6 +104,8 @@ namespace WalletWasabi.Gui.Tabs.WalletManager
private CancellationTokenSource HardwareWalletRefreshCancel { get; }
private async Task RefreshHardwareWalletListAsync()
+ {
+ try
{
while (!HardwareWalletRefreshCancel.IsCancellationRequested)
{
@@ -110,39 +116,30 @@ namespace WalletWasabi.Gui.Tabs.WalletManager
if (hwis.Any())
{
- var alltypesunique = hwis.Count() == hwis.Select(x => x.Type).ToHashSet().Count();
+ LoadWalletViewModelHardware.RefreshHardwareWallets(hwlist);
- //foreach (HardwareWalletInfo hwi in hwis)
- //{
- // if (alltypesunique)
- // {
- // Wallets.Add(hwi.Type.ToString());
- // }
- // else
- // {
- // Wallets.Add($"{hwi.Type}-{hwi.Fingerprint}");
- // }
- //}
-
- //SelectedWallet = Wallets.FirstOrDefault();
- //SetWalletStates();
- //break;
+ try
+ {
+ SelectHardwareWallet();
+ }
+ catch (Exception ex)
+ {
+ Logging.Logger.LogWarning<MainWindow>(ex);
}
- await Task.Delay(3000, HardwareWalletRefreshCancel.Token);
+ break;
}
- catch (TaskCanceledException)
- {
}
catch (Exception ex)
{
- //SetWarningMessage(ex.ToTypeMessageString());
- //Logger.LogError<LoadWalletViewModel>(ex);
+ Logger.LogError<WalletManagerViewModel>(ex);
+ }
+
+ await Task.Delay(3000, HardwareWalletRefreshCancel.Token);
}
- finally
- {
- //IsHwWalletSearchTextVisible = false;
}
+ catch (TaskCanceledException)
+ {
}
}

Refresh hw wallet list