Fix wallet ordering on creation

This commit is contained in:
TheXamlGuy
2024-07-07 21:27:37 +01:00
parent 45624031c0
commit afa72d8e14
3 changed files with 7 additions and 6 deletions
+3 -1
View File
@@ -5,6 +5,7 @@ using Toolkit.Foundation;
namespace Wallet;
public class CreateWalletHandler(IWalletHostFactory componentFactory,
IWalletHostCollection wallets,
IPublisher publisher) :
IHandler<CreateEventArgs<Wallet<(string, string, IImageDescriptor?)>>, bool>
{
@@ -23,9 +24,10 @@ public class CreateWalletHandler(IWalletHostFactory componentFactory,
IWalletFactory walletFactory = host.Services.GetRequiredService<IWalletFactory>();
if (await walletFactory.Create(name, password, imageDescriptor))
{
wallets.Add(host);
host.Start();
publisher.Publish(Activated.As(new Wallet<IComponentHost>(host)));
publisher.Publish(Activated.As(new Wallet<IComponentHost>(host)));
return true;
}
}
+2 -3
View File
@@ -3,7 +3,7 @@ using Toolkit.Foundation;
namespace Wallet;
public class WalletActivatedHandler(IWalletHostCollection Wallets,
public class WalletActivatedHandler(IWalletHostCollection wallets,
IPublisher publisher) :
INotificationHandler<ActivatedEventArgs<Wallet<IComponentHost>>>
{
@@ -11,8 +11,7 @@ public class WalletActivatedHandler(IWalletHostCollection Wallets,
{
if (args.Sender is Wallet<IComponentHost> wallet && wallet.Value is IComponentHost host)
{
List<IComponentHost> sortedWallets = [.. Wallets, host];
sortedWallets = [.. sortedWallets.OrderBy(x => x.Services.GetRequiredService<IConfigurationDescriptor<WalletConfiguration>>() is
List<IComponentHost> sortedWallets = [.. wallets.OrderBy(x => x.Services.GetRequiredService<IConfigurationDescriptor<WalletConfiguration>>() is
IConfigurationDescriptor<WalletConfiguration> descriptor ? descriptor.Name : null)];
int index = sortedWallets.IndexOf(host);
+2 -2
View File
@@ -5,7 +5,7 @@ namespace Wallet;
public class WalletCollectionInitializer(IHostEnvironment environment,
IComponentFactory componentFactory,
IWalletHostCollection Wallets) :
IWalletHostCollection wallets) :
IInitialization
{
public void Initialize()
@@ -25,7 +25,7 @@ public class WalletCollectionInitializer(IHostEnvironment environment,
WalletConfiguration>(section, new WalletConfiguration())
is IComponentHost host)
{
Wallets.Add(host);
wallets.Add(host);
host.Start();
}
}