Improve getting wallet file path
MODIFY
WalletWasabi.Gui/CommandLine/Daemon.cs
WalletWasabi.Gui/CommandLine/Daemon.cs
@@ -141,8 +141,7 @@ namespace WalletWasabi.Gui.CommandLine
KeyManager keyManager = null;
if (walletName != null)
{
- var walletFullPath = Global.GetWalletFullPath(walletName);
- var walletBackupFullPath = Global.GetWalletBackupFullPath(walletName);
+ (var walletFullPath, var walletBackupFullPath) = Global.WalletManager.WalletDirectories.GetWalletFilePaths(walletName);
if (!File.Exists(walletFullPath) && !File.Exists(walletBackupFullPath))
{
// The selected wallet is not available any more (someone deleted it?).

MODIFY
WalletWasabi.Gui/Global.cs
WalletWasabi.Gui/Global.cs
@@ -608,18 +608,6 @@ namespace WalletWasabi.Gui
Logger.LogInfo($"Transaction Notification ({notificationType}): {title} - {message} - {e.Transaction.GetHash()}");
}
- public string GetWalletFullPath(string walletName)
- {
- walletName = walletName.TrimEnd(".json", StringComparison.OrdinalIgnoreCase);
- return Path.Combine(WalletsDir, walletName + ".json");
- }
-
- public string GetWalletBackupFullPath(string walletName)
- {
- walletName = walletName.TrimEnd(".json", StringComparison.OrdinalIgnoreCase);
- return Path.Combine(WalletBackupsDir, walletName + ".json");
- }
-
public KeyManager LoadKeyManager(string walletFullPath, string walletBackupFullPath)
{
try

MODIFY
WalletWasabi.Gui/Tabs/WalletManager/LoadWallets/LoadWalletViewModel.cs
WalletWasabi.Gui/Tabs/WalletManager/LoadWallets/LoadWalletViewModel.cs
@@ -127,7 +127,7 @@ namespace WalletWasabi.Gui.Tabs.WalletManager.LoadWallets
Logger.LogInfo("Creating a new wallet file.");
var walletName = Global.GetNextHardwareWalletName(customPrefix: "Coldcard");
- var walletFullPath = Global.GetWalletFullPath(walletName);
+ var walletFullPath = Global.WalletManager.WalletDirectories.GetWalletFilePaths(walletName).walletFilePath;
KeyManager.CreateNewHardwareWalletWatchOnly(mfp, extPubKey, walletFullPath);
owner.SelectLoadWallet();
}
@@ -432,7 +432,7 @@ namespace WalletWasabi.Gui.Tabs.WalletManager.LoadWallets
else
{
walletName = Global.GetNextHardwareWalletName(selectedWallet.HardwareWalletInfo);
- var path = Global.GetWalletFullPath(walletName);
+ var path = Global.WalletManager.WalletDirectories.GetWalletFilePaths(walletName).walletFilePath;
// Get xpub should had triggered passphrase request, so the fingerprint should be available here.
if (!selectedWallet.HardwareWalletInfo.Fingerprint.HasValue)
@@ -448,8 +448,7 @@ namespace WalletWasabi.Gui.Tabs.WalletManager.LoadWallets
}
}
- var walletFullPath = Global.GetWalletFullPath(walletName);
- var walletBackupFullPath = Global.GetWalletBackupFullPath(walletName);
+ (string walletFullPath, string walletBackupFullPath) = Global.WalletManager.WalletDirectories.GetWalletFilePaths(walletName);
if (!File.Exists(walletFullPath) && !File.Exists(walletBackupFullPath))
{
// The selected wallet is not available any more (someone deleted it?).

MODIFY
WalletWasabi.Gui/Tabs/WalletManager/RecoverWallets/RecoverWalletViewModel.cs
WalletWasabi.Gui/Tabs/WalletManager/RecoverWallets/RecoverWalletViewModel.cs
@@ -44,7 +44,7 @@ namespace WalletWasabi.Gui.Tabs.WalletManager.RecoverWallets
MnemonicWords = Guard.Correct(MnemonicWords);
Password = Guard.Correct(Password); // Do not let whitespaces to the beginning and to the end.
- string walletFilePath = Global.WalletManager.WalletDirectories.GetWalletPath(WalletName);
+ string walletFilePath = Global.WalletManager.WalletDirectories.GetWalletFilePaths(WalletName).walletFilePath;
if (string.IsNullOrWhiteSpace(WalletName))
{

MODIFY
WalletWasabi.Tests/UnitTests/WalletDirTests.cs
WalletWasabi.Tests/UnitTests/WalletDirTests.cs
@@ -61,8 +61,7 @@ namespace WalletWasabi.Tests.UnitTests
var walletDirectories = new WalletDirectories(baseDir);
string walletName = "FooWallet.json";
- var walletPath = walletDirectories.GetWalletPath(walletName);
- var walletBackupPath = walletDirectories.GetWalletBackupPath(walletName);
+ (string walletPath, string walletBackupPath) = walletDirectories.GetWalletFilePaths(walletName);
Assert.Equal(Path.Combine(walletDirectories.WalletsDir, walletName), walletPath);
Assert.Equal(Path.Combine(walletDirectories.WalletsBackupDir, walletName), walletBackupPath);
@@ -78,8 +77,7 @@ namespace WalletWasabi.Tests.UnitTests
string walletName = "FooWallet";
string walletFileName = $"{walletName}.json";
- var walletPath = walletDirectories.GetWalletPath(walletName);
- var walletBackupPath = walletDirectories.GetWalletBackupPath(walletName);
+ (string walletPath, string walletBackupPath) = walletDirectories.GetWalletFilePaths(walletName);
Assert.Equal(Path.Combine(walletDirectories.WalletsDir, walletFileName), walletPath);
Assert.Equal(Path.Combine(walletDirectories.WalletsBackupDir, walletFileName), walletBackupPath);

MODIFY
WalletWasabi/Wallets/WalletDirectories.cs
WalletWasabi/Wallets/WalletDirectories.cs
@@ -25,23 +25,13 @@ namespace WalletWasabi.Wallets
public string WalletsDir => Path.Combine(WorkDir, WalletsDirName);
public string WalletsBackupDir => Path.Combine(WorkDir, WalletsBackupDirName);
- private static string GetWalltFilePath(string dir, string walletName)
+ public (string walletFilePath, string walletBackupFilePath) GetWalletFilePaths(string walletName)
{
- if (!walletName.ToLowerInvariant().EndsWith($".{WalletFileExtension}"))
+ if (!walletName.EndsWith($".{WalletFileExtension}", StringComparison.OrdinalIgnoreCase))
{
walletName = $"{walletName}.{WalletFileExtension}";
}
- return Path.Combine(dir, walletName);
- }
-
- public string GetWalletPath(string walletName)
- {
- return GetWalltFilePath(WalletsDir, walletName);
- }
-
- public string GetWalletBackupPath(string walletName)
- {
- return GetWalltFilePath(WalletsBackupDir, walletName);
+ return (Path.Combine(WalletsDir, walletName), Path.Combine(WalletsBackupDir, walletName));
}
public IEnumerable<FileInfo> EnumerateWalletFiles()

MODIFY
WalletWasabi/Wallets/WalletManager.cs
WalletWasabi/Wallets/WalletManager.cs
@@ -190,7 +190,7 @@ namespace WalletWasabi.Wallets
var keyManager = walletService.KeyManager;
if (keyManager is { } && WalletDirectories is { })
{
- string backupWalletFilePath = WalletDirectories.GetWalletBackupPath(Path.GetFileName(keyManager.FilePath));
+ string backupWalletFilePath = WalletDirectories.GetWalletFilePaths(Path.GetFileName(keyManager.FilePath)).walletBackupFilePath;
keyManager.ToFile(backupWalletFilePath);
Logger.LogInfo($"{nameof(walletService.KeyManager)} backup saved to `{backupWalletFilePath}`.");
}

Improve getting wallet file path