Refresh list until found
MODIFY
WalletWasabi.Gui/Tabs/WalletManager/LoadWalletViewModel.cs
WalletWasabi.Gui/Tabs/WalletManager/LoadWalletViewModel.cs
@@ -49,6 +49,9 @@ namespace WalletWasabi.Gui.Tabs.WalletManager
private List<HardwareWalletInfo> LastHardwareWalletEnumeration { get; set; }
+ private CancellationToken RefreshHwWalletCancellationToken { get; } = new CancellationToken();
+ private Task RefreshHwWalletTask { get; set; }
+
public LoadWalletViewModel(WalletManagerViewModel owner, LoadWalletType loadWalletType) : base(loadWalletType == LoadWalletType.Password ? "Test Password" : (loadWalletType == LoadWalletType.Desktop ? "Load Wallet" : "Hardware Wallet"))
{
Owner = owner;
@@ -220,10 +223,42 @@ namespace WalletWasabi.Gui.Tabs.WalletManager
SetValidationMessage("");
if (IsHardwareWallet)
+ {
+ if (RefreshHwWalletTask is null || RefreshHwWalletTask.IsCompleted)
{
Dispatcher.UIThread.PostLogException(async () =>
+ {
+ RefreshHwWalletTask = RefreshHardwareWalletListAsync();
+
+ await RefreshHwWalletTask;
+ });
+ }
+ }
+ else
+ {
+ if (!File.Exists(Global.WalletsDir))
+ {
+ Directory.CreateDirectory(Global.WalletsDir);
+ }
+
+ var directoryInfo = new DirectoryInfo(Global.WalletsDir);
+ var walletFiles = directoryInfo.GetFiles("*.json", SearchOption.TopDirectoryOnly).OrderByDescending(t => t.LastAccessTimeUtc);
+ foreach (var file in walletFiles)
+ {
+ Wallets.Add(Path.GetFileNameWithoutExtension(file.FullName));
+ }
+ }
+
+ SelectedWallet = Wallets.FirstOrDefault();
+ SetWalletStates();
+ }
+
+ private async Task RefreshHardwareWalletListAsync()
{
IsHwWalletSearchTextVisible = true;
+
+ while (!RefreshHwWalletCancellationToken.IsCancellationRequested)
+ {
try
{
var hwis = await HwiProcessManager.EnumerateAsync();
@@ -246,6 +281,7 @@ namespace WalletWasabi.Gui.Tabs.WalletManager
SelectedWallet = Wallets.FirstOrDefault();
SetWalletStates();
+ break;
}
}
catch (Exception ex)
@@ -257,25 +293,9 @@ namespace WalletWasabi.Gui.Tabs.WalletManager
{
IsHwWalletSearchTextVisible = false;
}
- });
- }
- else
- {
- if (!File.Exists(Global.WalletsDir))
- {
- Directory.CreateDirectory(Global.WalletsDir);
- }
- var directoryInfo = new DirectoryInfo(Global.WalletsDir);
- var walletFiles = directoryInfo.GetFiles("*.json", SearchOption.TopDirectoryOnly).OrderByDescending(t => t.LastAccessTimeUtc);
- foreach (var file in walletFiles)
- {
- Wallets.Add(Path.GetFileNameWithoutExtension(file.FullName));
- }
+ await Task.Delay(5000, RefreshHwWalletCancellationToken);
}
-
- SelectedWallet = Wallets.FirstOrDefault();
- SetWalletStates();
}
private void SetWalletStates()

Refresh list until found