Move GetNextWalletName/GetNextHardwareWalletName in Global
MODIFY
WalletWasabi.Gui/Global.cs
WalletWasabi.Gui/Global.cs
@@ -653,5 +653,31 @@ namespace WalletWasabi.Gui
Interlocked.Exchange(ref _dispose, 2);
}
}
+ public string GetNextWalletName()
+ {
+ for (int i = 0; i < int.MaxValue; i++)
+ {
+ if (!File.Exists(Path.Combine(WalletsDir, $"Wallet{i}.json")))
+ {
+ return $"Wallet{i}";
+ }
+ }
+
+ throw new NotSupportedException("This is impossible.");
+ }
+
+ public string GetNextHardwareWalletName(Hwi.Models.HardwareWalletInfo hwi)
+ {
+ for (int i = 0; i < int.MaxValue; i++)
+ {
+ var name = $"{hwi.Type}{i}";
+ if (!File.Exists(Path.Combine(WalletsDir, $"{name}.json")))
+ {
+ return name;
+ }
+ }
+
+ throw new NotSupportedException("This is impossible.");
+ }
}
}

MODIFY
WalletWasabi.Gui/Tabs/WalletManager/GenerateWalletViewModel.cs
WalletWasabi.Gui/Tabs/WalletManager/GenerateWalletViewModel.cs
@@ -156,7 +156,7 @@ namespace WalletWasabi.Gui.Tabs.WalletManager
base.OnCategorySelected();
Password = "";
- WalletName = Utils.GetNextWalletName();
+ WalletName = Global.Instance.GetNextWalletName();
TermsAccepted = false;
ValidationMessage = "";
}

MODIFY
WalletWasabi.Gui/Tabs/WalletManager/LoadWalletViewModel.cs
WalletWasabi.Gui/Tabs/WalletManager/LoadWalletViewModel.cs
@@ -499,7 +499,7 @@ namespace WalletWasabi.Gui.Tabs.WalletManager
Logger.LogInfo<LoadWalletViewModel>("Hardware wallet wasn't used previously on this computer. Creating new wallet file.");
- walletName = Utils.GetNextHardwareWalletName(selectedWallet.HardwareWalletInfo);
+ walletName = Global.Instance.GetNextHardwareWalletName(selectedWallet.HardwareWalletInfo);
var path = Global.Instance.GetWalletFullPath(walletName);
KeyManager.CreateNewHardwareWalletWatchOnly(selectedWallet.HardwareWalletInfo.MasterFingerprint.Value, extPubKey, path);
}

MODIFY
WalletWasabi.Gui/Tabs/WalletManager/RecoverWalletViewModel.cs
WalletWasabi.Gui/Tabs/WalletManager/RecoverWalletViewModel.cs
@@ -192,7 +192,7 @@ namespace WalletWasabi.Gui.Tabs.WalletManager
Password = null;
MnemonicWords = "";
- WalletName = Utils.GetNextWalletName();
+ WalletName = Global.Instance.GetNextWalletName();
ValidationMessage = null;
ShowAdvancedOptions = false;
AccountKeyPath = $"m/{KeyManager.DefaultAccountKeyPath}";

MODIFY
WalletWasabi.Gui/Utils.cs
WalletWasabi.Gui/Utils.cs
@@ -8,33 +8,6 @@ namespace WalletWasabi.Gui
{
public static class Utils
{
- public static string GetNextWalletName()
- {
- for (int i = 0; i < int.MaxValue; i++)
- {
- if (!File.Exists(Path.Combine(Global.Instance.WalletsDir, $"Wallet{i}.json")))
- {
- return $"Wallet{i}";
- }
- }
-
- throw new NotSupportedException("This is impossible.");
- }
-
- public static string GetNextHardwareWalletName(HardwareWalletInfo hwi)
- {
- for (int i = 0; i < int.MaxValue; i++)
- {
- var name = $"{hwi.Type}{i}";
- if (!File.Exists(Path.Combine(Global.Instance.WalletsDir, $"{name}.json")))
- {
- return name;
- }
- }
-
- throw new NotSupportedException("This is impossible.");
- }
-
public static void PostLogException(this Dispatcher dispatcher, Func<Task> action, DispatcherPriority priority = DispatcherPriority.Normal)
{
dispatcher.Post(async () =>

Move GetNextWalletName/GetNextHardwareWalletName in Global