2022-08-19 20:46:45 -05:00
|
|
|
using Microsoft.JSInterop;
|
|
|
|
using Microsoft.AspNetCore.Components;
|
2022-08-26 13:13:40 -05:00
|
|
|
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;
|
|
|
|
|
2022-08-26 13:13:40 -05:00
|
|
|
namespace NftFaucetRadzen.Pages;
|
|
|
|
|
2022-08-26 17:39:23 -05:00
|
|
|
public partial class NetworkPage : BasicComponent
|
2022-08-19 20:46:45 -05:00
|
|
|
{
|
2022-08-26 13:13:40 -05:00
|
|
|
[Inject]
|
|
|
|
protected IJSRuntime JSRuntime { get; set; }
|
2022-08-19 20:46:45 -05:00
|
|
|
|
2022-08-26 13:13:40 -05:00
|
|
|
[Inject]
|
|
|
|
protected DialogService DialogService { get; set; }
|
2022-08-19 20:46:45 -05:00
|
|
|
|
2022-08-26 13:13:40 -05:00
|
|
|
[Inject]
|
|
|
|
protected TooltipService TooltipService { get; set; }
|
2022-08-19 20:46:45 -05:00
|
|
|
|
2022-08-26 13:13:40 -05:00
|
|
|
[Inject]
|
|
|
|
protected ContextMenuService ContextMenuService { get; set; }
|
2022-08-19 20:46:45 -05:00
|
|
|
|
2022-08-26 13:13:40 -05:00
|
|
|
[Inject]
|
|
|
|
protected NotificationService NotificationService { get; set; }
|
2022-08-19 20:46:45 -05:00
|
|
|
|
2022-08-26 13:13:40 -05:00
|
|
|
protected override void OnInitialized()
|
|
|
|
{
|
2022-08-27 16:18:49 -05:00
|
|
|
PluginLoader?.EnsurePluginsLoaded();
|
|
|
|
var networkPlugins = PluginLoader?.NetworkPlugins;
|
2022-08-27 16:51:21 -05:00
|
|
|
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-26 13:13:40 -05:00
|
|
|
}
|
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)
|
2022-08-26 13:13:40 -05:00
|
|
|
=> new CardListItem
|
2022-08-20 21:10:54 -05:00
|
|
|
{
|
2022-08-26 17:48:40 -05:00
|
|
|
Id = model.Id,
|
2022-08-26 13:13:40 -05:00
|
|
|
ImageName = model.ImageName,
|
|
|
|
Header = model.Name,
|
|
|
|
IsDisabled = !model.IsSupported,
|
|
|
|
Properties = new[]
|
2022-08-25 20:28:24 -05:00
|
|
|
{
|
2022-08-26 13:13:40 -05:00
|
|
|
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
|
|
|
}
|