using Microsoft.Extensions.DependencyInjection; using Toolkit.Foundation; namespace Wallet; public class WalletActivatedHandler(IWalletHostCollection Wallets, IPublisher publisher) : INotificationHandler>> { public Task Handle(ActivatedEventArgs> args) { if (args.Sender is Wallet wallet && wallet.Sender is IComponentHost host) { List sortedWallets = [.. Wallets, host]; sortedWallets = [.. sortedWallets.OrderBy(x => x.Services.GetRequiredService>() is IConfigurationDescriptor descriptor ? descriptor.Name : null)]; int index = sortedWallets.IndexOf(host); if (host.Services.GetRequiredService>() is ConfigurationDescriptor descriptor) { if (host.Services.GetRequiredService() is IServiceFactory serviceFactory) { if (serviceFactory.Create(args => args.OnInitialize(), descriptor.Name, false) is WalletNavigationViewModel viewModel) { publisher.Publish(Insert.As(index, viewModel), nameof(MainViewModel)); } } } } return Task.CompletedTask; } }