diff --git a/Wallet/CreateWalletHandler.cs b/Wallet/CreateWalletHandler.cs index d1f825a..20a3d5a 100644 --- a/Wallet/CreateWalletHandler.cs +++ b/Wallet/CreateWalletHandler.cs @@ -11,17 +11,17 @@ public class CreateWalletHandler(IWalletHostFactory componentFactory, public async Task Handle(CreateEventArgs> args, CancellationToken cancellationToken) { - if (args.Sender is Wallet <(string, string, IImageDescriptor?)> Wallet) + if (args.Sender is Wallet<(string, string, IImageDescriptor?)> wallet) { - if (Wallet.Value is (string name, string password, - IImageDescriptor thumbnail) && - name is { Length: > 0 } && + (string name, string password, IImageDescriptor? imageDescriptor) = wallet.Value; + + if (name is { Length: > 0 } && password is { Length: > 0 }) { if (componentFactory.Create(name) is IComponentHost host) { IWalletFactory factory = host.Services.GetRequiredService(); - if (await factory.Create(name, password, thumbnail)) + if (await factory.Create(name, password, imageDescriptor)) { host.Start(); publisher.Publish(Activated.As(new Wallet(host))); diff --git a/Wallet/IWalletFactory.cs b/Wallet/IWalletFactory.cs index 0ee1d2b..ba6ab95 100644 --- a/Wallet/IWalletFactory.cs +++ b/Wallet/IWalletFactory.cs @@ -6,5 +6,5 @@ public interface IWalletFactory { Task Create(string name, string password, - IImageDescriptor thumbnail); + IImageDescriptor? imageDescriptor); } diff --git a/Wallet/SynchronizeMainViewModelHandler.cs b/Wallet/SynchronizeMainViewModelHandler.cs index a8501d7..1189415 100644 --- a/Wallet/SynchronizeMainViewModelHandler.cs +++ b/Wallet/SynchronizeMainViewModelHandler.cs @@ -23,7 +23,7 @@ public class SynchronizeMainViewModelHandler(IPublisher publisher, Wallet.Services.GetRequiredService>>(); ProfileImage? profileImage = profileImageDecorator.Service; - if (factory.Create(args => args.Initialize(), configuration.Name, profileImage?.Value, selected) + if (factory.Create(args => args.Initialize(), configuration.Name, profileImage?.Value ?? null, selected) is WalletNavigationViewModel viewModel) { publisher.Publish(Create.As(viewModel), diff --git a/Wallet/WalletFactory.cs b/Wallet/WalletFactory.cs index b2d1c63..766a64e 100644 --- a/Wallet/WalletFactory.cs +++ b/Wallet/WalletFactory.cs @@ -14,7 +14,7 @@ public class WalletFactory(ISecurityKeyFactory securityKeyFactory, { public async Task Create(string name, string password, - IImageDescriptor thumbnail) + IImageDescriptor? imageDescriptor) { if (securityKeyFactory.Create(Encoding.UTF8.GetBytes(password)) is SecurityKey key) { @@ -25,10 +25,14 @@ public class WalletFactory(ISecurityKeyFactory securityKeyFactory, configuration.Write(args => args.Key = $"{Convert.ToBase64String(key.Salt)}:" + $"{Convert.ToBase64String(key.EncryptedKey)}:{Convert.ToBase64String(key.DecryptedKey)}"); - string file = Path.Combine(environment.ContentRootPath, "Thumbnail.png"); - using FileStream stream = File.OpenWrite(file); + if (imageDescriptor is not null) + { + string file = Path.Combine(environment.ContentRootPath, "Thumbnail.png"); + using FileStream stream = File.OpenWrite(file); + + imageWriter.Write(imageDescriptor, stream); + } - imageWriter.Write(thumbnail, stream); return true; } } diff --git a/Wallet/WalletNavigationViewModel.cs b/Wallet/WalletNavigationViewModel.cs index e7bc172..78d752a 100644 --- a/Wallet/WalletNavigationViewModel.cs +++ b/Wallet/WalletNavigationViewModel.cs @@ -28,7 +28,7 @@ public partial class WalletNavigationViewModel : private bool isActivated; [ObservableProperty] - private IImageDescriptor imageDescriptor; + private IImageDescriptor? imageDescriptor; public WalletNavigationViewModel(IServiceProvider provider, IServiceFactory factory, @@ -38,8 +38,8 @@ public partial class WalletNavigationViewModel : IDisposer disposer, IContentTemplate template, string name, - IImageDescriptor imageDescriptor, - bool isSelected) : base(provider, factory, mediator, publisher, subscriber, disposer) + IImageDescriptor? imageDescriptor = default, + bool isSelected = false) : base(provider, factory, mediator, publisher, subscriber, disposer) { Template = template; Name = name;