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

57 lines
2.0 KiB
C#
Raw Normal View History

2022-08-19 20:46:45 -05:00
using Microsoft.JSInterop;
using Microsoft.AspNetCore.Components;
using NftFaucetRadzen.Components;
2022-08-19 20:46:45 -05:00
using NftFaucetRadzen.Models;
2022-08-27 12:37:49 -05:00
using NftFaucetRadzen.Plugins.NetworkPlugins;
2022-08-19 20:46:45 -05:00
using Radzen;
namespace NftFaucetRadzen.Pages;
2022-08-26 17:39:23 -05:00
public partial class NetworkPage : BasicComponent
2022-08-19 20:46:45 -05:00
{
[Inject]
protected IJSRuntime JSRuntime { get; set; }
2022-08-19 20:46:45 -05:00
[Inject]
protected DialogService DialogService { get; set; }
2022-08-19 20:46:45 -05:00
[Inject]
protected TooltipService TooltipService { get; set; }
2022-08-19 20:46:45 -05:00
[Inject]
protected ContextMenuService ContextMenuService { get; set; }
2022-08-19 20:46:45 -05:00
[Inject]
protected NotificationService NotificationService { get; set; }
2022-08-19 20:46:45 -05:00
protected override void OnInitialized()
{
2022-08-27 16:18:49 -05:00
PluginLoader?.EnsurePluginsLoaded();
var networkPlugins = PluginLoader?.NetworkPlugins;
var networks = networkPlugins?.SelectMany(x => x?.Networks).Where(x => x != null).OrderBy(x => x.ChainId ?? ulong.MaxValue).ToArray() ?? Array.Empty<INetwork>();
2022-08-27 16:18:49 -05:00
NetworksLookup = networks.ToLookup(x => x.Type, MapCardListItem);
}
2022-08-19 20:46:45 -05:00
2022-08-27 12:37:49 -05:00
private ILookup<NetworkType, CardListItem> NetworksLookup { get; set; }
2022-08-20 21:10:54 -05:00
2022-08-27 12:37:49 -05:00
private static CardListItem MapCardListItem(INetwork model)
=> new CardListItem
2022-08-20 21:10:54 -05:00
{
2022-08-26 17:48:40 -05:00
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(),
};
2022-08-19 20:46:45 -05:00
}