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

71 lines
2.3 KiB
C#
Raw Normal View History

2022-08-19 20:46:45 -05:00
using Microsoft.JSInterop;
using Microsoft.AspNetCore.Components;
using NftFaucetRadzen.Components;
using NftFaucetRadzen.Components.CardList;
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-27 20:16:31 -05:00
public partial class NetworksPage : 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 17:22:50 -05:00
Networks = AppState.Storage.Networks
2022-08-27 18:05:07 -05:00
.GroupBy(x => x.SubType)
2022-08-27 17:22:50 -05:00
.ToDictionary(x => x.Key, x => x.OrderBy(v => v.Order ?? int.MaxValue).Select(MapCardListItem).ToArray());
}
2022-08-19 20:46:45 -05:00
2022-08-27 18:05:07 -05:00
private Dictionary<NetworkSubtype, CardListItem[]> Networks { 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(),
};
private void ResetProviderSelectionIfNeeded()
{
var currentProvider = AppState.SelectedProvider;
if (currentProvider == null)
{
return;
}
var currentNetwork = AppState.SelectedNetwork;
if (currentNetwork == null || !currentProvider.IsNetworkSupported(currentNetwork))
{
AppState.Storage.SelectedProviders = Array.Empty<Guid>();
}
}
2022-08-19 20:46:45 -05:00
}