nft-faucet/NftFaucetRadzen/Pages/ProvidersPage.razor.cs

74 lines
2.4 KiB
C#
Raw Normal View History

2022-08-26 17:39:23 -05:00
using Microsoft.AspNetCore.Components;
using Microsoft.JSInterop;
using NftFaucetRadzen.Components;
using NftFaucetRadzen.Components.CardList;
2022-08-27 12:37:49 -05:00
using NftFaucetRadzen.Plugins.ProviderPlugins;
2022-08-26 17:39:23 -05:00
using Radzen;
namespace NftFaucetRadzen.Pages;
2022-08-27 20:16:31 -05:00
public partial class ProvidersPage : BasicComponent
2022-08-26 17:39:23 -05:00
{
[Inject]
protected IJSRuntime JSRuntime { get; set; }
[Inject]
protected DialogService DialogService { get; set; }
[Inject]
protected TooltipService TooltipService { get; set; }
[Inject]
protected ContextMenuService ContextMenuService { get; set; }
[Inject]
protected NotificationService NotificationService { get; set; }
2022-08-26 22:04:57 -05:00
protected override void OnInitialized()
2022-08-26 17:39:23 -05:00
{
Providers = AppState.Storage.Providers.Where(x => AppState.SelectedNetwork != null && x.IsNetworkSupported(AppState.SelectedNetwork)).ToArray();
2022-08-27 16:39:49 -05:00
RefreshData();
2022-08-26 22:34:27 -05:00
}
2022-08-27 16:39:49 -05:00
private IProvider[] Providers { get; set; }
private CardListItem[] Data { get; set; }
2022-08-27 12:37:49 -05:00
2022-08-27 16:39:49 -05:00
private void RefreshData()
2022-08-27 16:35:24 -05:00
{
2022-08-27 16:39:49 -05:00
Data = Providers.Select(MapCardListItem).ToArray();
}
private CardListItem MapCardListItem(IProvider provider)
=> new CardListItem
2022-08-26 22:34:27 -05:00
{
2022-08-27 12:37:49 -05:00
Id = provider.Id,
2022-08-28 09:28:10 -05:00
ImageLocation = provider.ImageName != null ? "./images/" + provider.ImageName : null,
2022-08-27 12:37:49 -05:00
Header = provider.Name,
IsDisabled = !provider.IsSupported,
2022-08-27 16:35:24 -05:00
Properties = provider.GetProperties().Select(x => new CardListItemProperty
{
Name = x.Name,
Value = x.Value,
}).ToArray(),
2022-08-26 22:34:27 -05:00
Badges = new[]
{
2022-08-27 16:39:49 -05:00
(Settings?.RecommendedProviders?.Contains(provider.Id) ?? false)
? new CardListItemBadge {Style = BadgeStyle.Success, Text = "Recommended"}
: null,
!provider.IsSupported
? new CardListItemBadge {Style = BadgeStyle.Light, Text = "Not Supported"}
: null,
2022-08-26 22:34:27 -05:00
}.Where(x => x != null).ToArray(),
2022-08-27 16:39:49 -05:00
Buttons = new[]
2022-08-27 15:18:43 -05:00
{
2022-08-27 16:39:49 -05:00
!provider.IsInitialized
? new CardListItemButton { Name = "Initialize", Style = ButtonStyle.Secondary, Action = () =>
{
provider.Initialize();
RefreshData();
}}
: null,
}.Where(x => x != null).ToArray()
2022-08-26 22:34:27 -05:00
};
2022-08-26 17:39:23 -05:00
}