Fixed inability to create a wallet without an image

This commit is contained in:
TheXamlGuy
2024-07-02 11:58:07 +01:00
parent 840d8fb679
commit de1cd3db55
5 changed files with 18 additions and 14 deletions
+5 -5
View File
@@ -11,17 +11,17 @@ public class CreateWalletHandler(IWalletHostFactory componentFactory,
public async Task<bool> Handle(CreateEventArgs<Wallet<(string, string, IImageDescriptor?)>> 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<IWalletFactory>();
if (await factory.Create(name, password, thumbnail))
if (await factory.Create(name, password, imageDescriptor))
{
host.Start();
publisher.Publish(Activated.As(new Wallet<IComponentHost>(host)));
+1 -1
View File
@@ -6,5 +6,5 @@ public interface IWalletFactory
{
Task<bool> Create(string name,
string password,
IImageDescriptor thumbnail);
IImageDescriptor? imageDescriptor);
}
+1 -1
View File
@@ -23,7 +23,7 @@ public class SynchronizeMainViewModelHandler(IPublisher publisher,
Wallet.Services.GetRequiredService<IDecoratorService<ProfileImage<IImageDescriptor>>>();
ProfileImage<IImageDescriptor>? profileImage = profileImageDecorator.Service;
if (factory.Create<WalletNavigationViewModel>(args => args.Initialize(), configuration.Name, profileImage?.Value, selected)
if (factory.Create<WalletNavigationViewModel>(args => args.Initialize(), configuration.Name, profileImage?.Value ?? null, selected)
is WalletNavigationViewModel viewModel)
{
publisher.Publish(Create.As<IMainNavigationViewModel>(viewModel),
+8 -4
View File
@@ -14,7 +14,7 @@ public class WalletFactory(ISecurityKeyFactory securityKeyFactory,
{
public async Task<bool> 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;
}
}
+3 -3
View File
@@ -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;