Fixed inability to create a wallet without an image
This commit is contained in:
@@ -11,17 +11,17 @@ public class CreateWalletHandler(IWalletHostFactory componentFactory,
|
|||||||
public async Task<bool> Handle(CreateEventArgs<Wallet<(string, string, IImageDescriptor?)>> args,
|
public async Task<bool> Handle(CreateEventArgs<Wallet<(string, string, IImageDescriptor?)>> args,
|
||||||
CancellationToken cancellationToken)
|
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,
|
(string name, string password, IImageDescriptor? imageDescriptor) = wallet.Value;
|
||||||
IImageDescriptor thumbnail) &&
|
|
||||||
name is { Length: > 0 } &&
|
if (name is { Length: > 0 } &&
|
||||||
password is { Length: > 0 })
|
password is { Length: > 0 })
|
||||||
{
|
{
|
||||||
if (componentFactory.Create(name) is IComponentHost host)
|
if (componentFactory.Create(name) is IComponentHost host)
|
||||||
{
|
{
|
||||||
IWalletFactory factory = host.Services.GetRequiredService<IWalletFactory>();
|
IWalletFactory factory = host.Services.GetRequiredService<IWalletFactory>();
|
||||||
if (await factory.Create(name, password, thumbnail))
|
if (await factory.Create(name, password, imageDescriptor))
|
||||||
{
|
{
|
||||||
host.Start();
|
host.Start();
|
||||||
publisher.Publish(Activated.As(new Wallet<IComponentHost>(host)));
|
publisher.Publish(Activated.As(new Wallet<IComponentHost>(host)));
|
||||||
|
|||||||
@@ -6,5 +6,5 @@ public interface IWalletFactory
|
|||||||
{
|
{
|
||||||
Task<bool> Create(string name,
|
Task<bool> Create(string name,
|
||||||
string password,
|
string password,
|
||||||
IImageDescriptor thumbnail);
|
IImageDescriptor? imageDescriptor);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ public class SynchronizeMainViewModelHandler(IPublisher publisher,
|
|||||||
Wallet.Services.GetRequiredService<IDecoratorService<ProfileImage<IImageDescriptor>>>();
|
Wallet.Services.GetRequiredService<IDecoratorService<ProfileImage<IImageDescriptor>>>();
|
||||||
ProfileImage<IImageDescriptor>? profileImage = profileImageDecorator.Service;
|
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)
|
is WalletNavigationViewModel viewModel)
|
||||||
{
|
{
|
||||||
publisher.Publish(Create.As<IMainNavigationViewModel>(viewModel),
|
publisher.Publish(Create.As<IMainNavigationViewModel>(viewModel),
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ public class WalletFactory(ISecurityKeyFactory securityKeyFactory,
|
|||||||
{
|
{
|
||||||
public async Task<bool> Create(string name,
|
public async Task<bool> Create(string name,
|
||||||
string password,
|
string password,
|
||||||
IImageDescriptor thumbnail)
|
IImageDescriptor? imageDescriptor)
|
||||||
{
|
{
|
||||||
if (securityKeyFactory.Create(Encoding.UTF8.GetBytes(password)) is SecurityKey key)
|
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)}:" +
|
configuration.Write(args => args.Key = $"{Convert.ToBase64String(key.Salt)}:" +
|
||||||
$"{Convert.ToBase64String(key.EncryptedKey)}:{Convert.ToBase64String(key.DecryptedKey)}");
|
$"{Convert.ToBase64String(key.EncryptedKey)}:{Convert.ToBase64String(key.DecryptedKey)}");
|
||||||
|
|
||||||
|
if (imageDescriptor is not null)
|
||||||
|
{
|
||||||
string file = Path.Combine(environment.ContentRootPath, "Thumbnail.png");
|
string file = Path.Combine(environment.ContentRootPath, "Thumbnail.png");
|
||||||
using FileStream stream = File.OpenWrite(file);
|
using FileStream stream = File.OpenWrite(file);
|
||||||
|
|
||||||
imageWriter.Write(thumbnail, stream);
|
imageWriter.Write(imageDescriptor, stream);
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ public partial class WalletNavigationViewModel :
|
|||||||
private bool isActivated;
|
private bool isActivated;
|
||||||
|
|
||||||
[ObservableProperty]
|
[ObservableProperty]
|
||||||
private IImageDescriptor imageDescriptor;
|
private IImageDescriptor? imageDescriptor;
|
||||||
|
|
||||||
public WalletNavigationViewModel(IServiceProvider provider,
|
public WalletNavigationViewModel(IServiceProvider provider,
|
||||||
IServiceFactory factory,
|
IServiceFactory factory,
|
||||||
@@ -38,8 +38,8 @@ public partial class WalletNavigationViewModel :
|
|||||||
IDisposer disposer,
|
IDisposer disposer,
|
||||||
IContentTemplate template,
|
IContentTemplate template,
|
||||||
string name,
|
string name,
|
||||||
IImageDescriptor imageDescriptor,
|
IImageDescriptor? imageDescriptor = default,
|
||||||
bool isSelected) : base(provider, factory, mediator, publisher, subscriber, disposer)
|
bool isSelected = false) : base(provider, factory, mediator, publisher, subscriber, disposer)
|
||||||
{
|
{
|
||||||
Template = template;
|
Template = template;
|
||||||
Name = name;
|
Name = name;
|
||||||
|
|||||||
Reference in New Issue
Block a user