nft-faucet/NftFaucetRadzen/Pages/NetworkPage.razor.cs
2022-08-27 14:55:34 -05:00

55 lines
1.9 KiB
C#

using Microsoft.JSInterop;
using Microsoft.AspNetCore.Components;
using NftFaucetRadzen.Components;
using NftFaucetRadzen.Models;
using NftFaucetRadzen.Plugins.NetworkPlugins;
using Radzen;
namespace NftFaucetRadzen.Pages;
public partial class NetworkPage : BasicComponent
{
[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; }
protected override void OnInitialized()
{
PluginLoader.EnsurePluginsLoaded();
NetworksLookup = PluginLoader.NetworkPlugins.SelectMany(x => x.GetNetworks()).OrderBy(x => x.ChainId ?? ulong.MaxValue).ToLookup(x => x.Type, MapCardListItem);
}
private ILookup<NetworkType, CardListItem> NetworksLookup { get; set; }
private static CardListItem MapCardListItem(INetwork model)
=> new CardListItem
{
Id = model.Id,
ImageName = model.ImageName,
Header = model.Name,
IsDisabled = !model.IsSupported,
Properties = new[]
{
new CardListItemProperty { Name = "ChainID", Value = model.ChainId?.ToString() },
new CardListItemProperty { Name = "Currency", Value = model.Currency },
},
Badges = new[]
{
!model.IsSupported ? new CardListItemBadge { Style = BadgeStyle.Light, Text = "Not Supported" } : null,
!model.IsTestnet ? new CardListItemBadge { Style = BadgeStyle.Danger, Text = "Mainnet" } : null,
model.IsDeprecated ? new CardListItemBadge { Style = BadgeStyle.Warning, Text = "Deprecated" } : null,
}.Where(x => x != null).ToArray(),
};
}