Add enum extension to get description
MODIFY
WalletWasabi.Gui/Tabs/WalletManager/HardwareWallets/ConnectHardwareWalletViewModel.cs
WalletWasabi.Gui/Tabs/WalletManager/HardwareWallets/ConnectHardwareWalletViewModel.cs
@@ -324,7 +324,7 @@ namespace WalletWasabi.Gui.Tabs.WalletManager.HardwareWallets
else
{
Logger.LogInfo("Hardware wallet was not used previously on this computer. Creating a new wallet file.");
- walletName = WalletManager.WalletDirectories.GetNextHardwareWalletName(selectedWallet.HardwareWalletInfo?.Model ?? HardwareWalletModels.Unknown);
+ walletName = WalletManager.WalletDirectories.GetNextWalletName(selectedWallet.HardwareWalletInfo?.Model.FriendlyName() ?? HardwareWalletModels.Unknown.FriendlyName());
var path = WalletManager.WalletDirectories.GetWalletFilePaths(walletName).walletFilePath;
// Get xpub should had triggered passphrase request, so the fingerprint should be available here.

MODIFY
WalletWasabi.Tests/UnitTests/WalletDirTests.cs
WalletWasabi.Tests/UnitTests/WalletDirTests.cs
@@ -184,58 +184,5 @@ namespace WalletWasabi.Tests.UnitTests
Assert.Equal("Foo 2", walletDirectories.GetNextWalletName("Foo"));
IoHelpers.CreateEmptyFile(Path.Combine(walletDirectories.WalletsDir, "Foo 2.json"));
}
-
- [Fact]
- public async Task GetNextHardwareWalletNameAsync()
- {
- var baseDir = Path.Combine(Global.Instance.DataDir, EnvironmentHelpers.GetCallerFileName(), EnvironmentHelpers.GetMethodName());
- await CleanupWalletDirectoriesAsync(baseDir);
- var walletDirectories = new WalletDirectories(baseDir);
-
- Assert.Equal("Hardware Wallet", walletDirectories.GetNextHardwareWalletName(HardwareWalletModels.Unknown));
- IoHelpers.CreateEmptyFile(Path.Combine(walletDirectories.WalletsDir, "Hardware Wallet.json"));
- Assert.Equal("Hardware Wallet 2", walletDirectories.GetNextHardwareWalletName(HardwareWalletModels.Unknown));
- IoHelpers.CreateEmptyFile(Path.Combine(walletDirectories.WalletsDir, "Hardware Wallet 2.json"));
-
- Assert.Equal("Coldcard", walletDirectories.GetNextHardwareWalletName(HardwareWalletModels.Coldcard));
- IoHelpers.CreateEmptyFile(Path.Combine(walletDirectories.WalletsDir, "Coldcard.json"));
- Assert.Equal("Coldcard 2", walletDirectories.GetNextHardwareWalletName(HardwareWalletModels.Coldcard));
- IoHelpers.CreateEmptyFile(Path.Combine(walletDirectories.WalletsDir, "Coldcard 2.json"));
-
- Assert.Equal("Coldcard Simulator", walletDirectories.GetNextHardwareWalletName(HardwareWalletModels.Coldcard_Simulator));
- IoHelpers.CreateEmptyFile(Path.Combine(walletDirectories.WalletsDir, "Coldcard Simulator.json"));
- Assert.Equal("Coldcard Simulator 2", walletDirectories.GetNextHardwareWalletName(HardwareWalletModels.Coldcard_Simulator));
- IoHelpers.CreateEmptyFile(Path.Combine(walletDirectories.WalletsDir, "Coldcard Simulator 2.json"));
-
- IoHelpers.CreateEmptyFile(Path.Combine(walletDirectories.WalletsDir, "Trezor T.json"));
- Assert.Equal("Trezor T 2", walletDirectories.GetNextHardwareWalletName(HardwareWalletModels.Trezor_T));
- IoHelpers.CreateEmptyFile(Path.Combine(walletDirectories.WalletsDir, "Trezor T 2.json"));
- Assert.Equal("Trezor T 3", walletDirectories.GetNextHardwareWalletName(HardwareWalletModels.Trezor_T));
- IoHelpers.CreateEmptyFile(Path.Combine(walletDirectories.WalletsDir, "Trezor T 3.json"));
-
- Assert.Equal("BitBox", walletDirectories.GetNextHardwareWalletName(HardwareWalletModels.BitBox02_BTCOnly));
- IoHelpers.CreateEmptyFile(Path.Combine(walletDirectories.WalletsDir, "BitBox.json"));
- Assert.Equal("BitBox 2", walletDirectories.GetNextHardwareWalletName(HardwareWalletModels.BitBox02_Multi));
- IoHelpers.CreateEmptyFile(Path.Combine(walletDirectories.WalletsDir, "BitBox 2.json"));
- Assert.Equal("BitBox 3", walletDirectories.GetNextHardwareWalletName(HardwareWalletModels.BitBox02_BTCOnly));
- IoHelpers.CreateEmptyFile(Path.Combine(walletDirectories.WalletsDir, "BitBox 3.json"));
- Assert.Equal("BitBox 4", walletDirectories.GetNextHardwareWalletName(HardwareWalletModels.DigitalBitBox_01));
- IoHelpers.CreateEmptyFile(Path.Combine(walletDirectories.WalletsDir, "BitBox 4.json"));
-
- Assert.Equal("BitBox Simulator", walletDirectories.GetNextHardwareWalletName(HardwareWalletModels.DigitalBitBox_01_Simulator));
- IoHelpers.CreateEmptyFile(Path.Combine(walletDirectories.WalletsDir, "BitBox Simulator.json"));
- Assert.Equal("BitBox Simulator 2", walletDirectories.GetNextHardwareWalletName(HardwareWalletModels.DigitalBitBox_01_Simulator));
- IoHelpers.CreateEmptyFile(Path.Combine(walletDirectories.WalletsDir, "BitBox Simulator 2.json"));
-
- Assert.Equal("Ledger Nano S", walletDirectories.GetNextHardwareWalletName(HardwareWalletModels.Ledger_Nano_S));
- IoHelpers.CreateEmptyFile(Path.Combine(walletDirectories.WalletsDir, "Ledger Nano S.json"));
- Assert.Equal("Ledger Nano S 2", walletDirectories.GetNextHardwareWalletName(HardwareWalletModels.Ledger_Nano_S));
- IoHelpers.CreateEmptyFile(Path.Combine(walletDirectories.WalletsDir, "Ledger Nano S 2.json"));
-
- Assert.Equal("Trezor One", walletDirectories.GetNextHardwareWalletName(HardwareWalletModels.Trezor_1));
- IoHelpers.CreateEmptyFile(Path.Combine(walletDirectories.WalletsDir, "Trezor One.json"));
- Assert.Equal("Trezor One 2", walletDirectories.GetNextHardwareWalletName(HardwareWalletModels.Trezor_1));
- IoHelpers.CreateEmptyFile(Path.Combine(walletDirectories.WalletsDir, "Trezor One 2.json"));
- }
}
}

MODIFY
WalletWasabi/Hwi/Models/HardwareWalletModels.cs
WalletWasabi/Hwi/Models/HardwareWalletModels.cs
using System;
-using System.Collections.Generic;
-using System.Text;
+using System.ComponentModel;
+using System.Linq;
namespace WalletWasabi.Hwi.Models
{
@@ -9,19 +9,65 @@ namespace WalletWasabi.Hwi.Models
/// </summary>
public enum HardwareWalletModels
{
+ [Description("Hardware Wallet")]
Unknown,
+
+ [Description("Coldcard")]
Coldcard,
+
+ [Description("Coldcard Simulator")]
Coldcard_Simulator,
+
+ [Description("BitBox")]
DigitalBitBox_01,
+
+ [Description("BitBox Simulator")]
DigitalBitBox_01_Simulator,
+
+ [Description("KeepKey")]
KeepKey,
+
+ [Description("KeepKeySimulator")]
KeepKey_Simulator,
+
+ [Description("Ledger Nano S")]
Ledger_Nano_S,
+
+ [Description("Trezor One")]
Trezor_1,
+
+ [Description("Trezor One Simulator")]
Trezor_1_Simulator,
+
+ [Description("Trezor T")]
Trezor_T,
+
+ [Description("Trezor T Simulator")]
Trezor_T_Simulator,
+
+ [Description("BitBox")]
BitBox02_BTCOnly,
+
+ [Description("BitBox")]
BitBox02_Multi,
}
+
+ public static class EnumExtensions
+ {
+ public static T? GetAttribute<T>(this Enum value) where T : Attribute
+ {
+ var type = value.GetType();
+ var memberInfo = type.GetMember(value.ToString());
+ var attributes = memberInfo[0].GetCustomAttributes(typeof(T), false);
+
+ return attributes.Any() ? (T)attributes[0] : null;
+ }
+
+ public static string FriendlyName(this Enum value)
+ {
+ var attribute = value.GetAttribute<DescriptionAttribute>();
+
+ return attribute is { } ? attribute.Description : value.ToString();
+ }
+ }
}

MODIFY
WalletWasabi/Wallets/WalletDirectories.cs
WalletWasabi/Wallets/WalletDirectories.cs
@@ -84,38 +84,5 @@ namespace WalletWasabi.Wallets
i++;
}
}
-
- public string GetNextHardwareWalletName(HardwareWalletModels model)
- {
- string prefix;
- if (model == HardwareWalletModels.Unknown)
- {
- prefix = "Hardware Wallet";
- }
- else if (model == HardwareWalletModels.BitBox02_BTCOnly
- || model == HardwareWalletModels.BitBox02_Multi
- || model == HardwareWalletModels.DigitalBitBox_01)
- {
- prefix = "BitBox";
- }
- else if (model == HardwareWalletModels.DigitalBitBox_01_Simulator)
- {
- prefix = "BitBox Simulator";
- }
- else if (model == HardwareWalletModels.Trezor_1)
- {
- prefix = "Trezor One";
- }
- else if (model == HardwareWalletModels.Trezor_1_Simulator)
- {
- prefix = "Trezor One Simulator";
- }
- else
- {
- prefix = GetNextWalletName(model.ToString().Replace('_', ' '));
- }
-
- return GetNextWalletName(prefix);
- }
}
}

Add enum extension to get description