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 IComponentHost Wallet) { List sortedWallets = [.. Wallets, Wallet]; sortedWallets = [.. sortedWallets.OrderBy(x => x.Services.GetRequiredService>() is IConfigurationDescriptor descriptor ? descriptor.Name : null)]; int index = sortedWallets.IndexOf(Wallet); if (Wallet.Services.GetRequiredService>() is ConfigurationDescriptor descriptor) { if (Wallet.Services.GetRequiredService() is IServiceFactory serviceFactory) { if (serviceFactory.Create(descriptor.Name) is WalletNavigationViewModel viewModel) { publisher.Publish(new InsertEventArgs(index, viewModel), nameof(MainViewModel)); } } } } return Task.CompletedTask; } }