mirror of
https://github.com/status-im/nft-faucet.git
synced 2025-02-24 04:28:29 +00:00
Add saving new token to AppState
This commit is contained in:
parent
b529f55ea9
commit
51a28e55cd
@ -6,10 +6,10 @@ namespace NftFaucetRadzen.Models;
|
|||||||
|
|
||||||
public class StateStorage
|
public class StateStorage
|
||||||
{
|
{
|
||||||
public IReadOnlyCollection<INetwork> Networks { get; set; }
|
public ICollection<INetwork> Networks { get; set; }
|
||||||
public IReadOnlyCollection<IProvider> Providers { get; set; }
|
public ICollection<IProvider> Providers { get; set; }
|
||||||
public IReadOnlyCollection<IContract> Contracts { get; set; }
|
public ICollection<IContract> Contracts { get; set; }
|
||||||
public IReadOnlyCollection<IToken> Tokens { get; set; }
|
public ICollection<IToken> Tokens { get; set; }
|
||||||
|
|
||||||
public Guid[] SelectedNetworks { get; set; }
|
public Guid[] SelectedNetworks { get; set; }
|
||||||
public Guid[] SelectedProviders { get; set; }
|
public Guid[] SelectedProviders { get; set; }
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using Microsoft.AspNetCore.Components;
|
using Microsoft.AspNetCore.Components;
|
||||||
using Microsoft.JSInterop;
|
using Microsoft.JSInterop;
|
||||||
|
using Newtonsoft.Json;
|
||||||
using NftFaucetRadzen.Components;
|
using NftFaucetRadzen.Components;
|
||||||
using NftFaucetRadzen.Components.CardList;
|
using NftFaucetRadzen.Components.CardList;
|
||||||
|
using NftFaucetRadzen.Models;
|
||||||
using NftFaucetRadzen.Plugins;
|
using NftFaucetRadzen.Plugins;
|
||||||
using Radzen;
|
using Radzen;
|
||||||
|
|
||||||
@ -28,16 +30,14 @@ public partial class TokensPage : BasicComponent
|
|||||||
protected override void OnInitialized()
|
protected override void OnInitialized()
|
||||||
{
|
{
|
||||||
// ToDo: Add loading from IndexedDB
|
// ToDo: Add loading from IndexedDB
|
||||||
Tokens = Array.Empty<IToken>();
|
|
||||||
RefreshData();
|
RefreshData();
|
||||||
}
|
}
|
||||||
|
|
||||||
private IToken[] Tokens { get; set; }
|
|
||||||
private CardListItem[] Data { get; set; }
|
private CardListItem[] Data { get; set; }
|
||||||
|
|
||||||
private void RefreshData()
|
private void RefreshData()
|
||||||
{
|
{
|
||||||
Data = Tokens.Select(MapCardListItem).ToArray();
|
Data = AppState?.Storage?.Tokens?.Select(MapCardListItem).ToArray() ?? Array.Empty<CardListItem>();
|
||||||
}
|
}
|
||||||
|
|
||||||
private CardListItem MapCardListItem(IToken token)
|
private CardListItem MapCardListItem(IToken token)
|
||||||
@ -71,8 +71,26 @@ public partial class TokensPage : BasicComponent
|
|||||||
|
|
||||||
private async Task OpenCreateTokenDialog()
|
private async Task OpenCreateTokenDialog()
|
||||||
{
|
{
|
||||||
await DialogService.OpenAsync<CreateTokenPage>("Create new token",
|
var newFileModel = (NewFileModel) await DialogService.OpenAsync<CreateTokenPage>("Create new token",
|
||||||
new Dictionary<string, object>(),
|
new Dictionary<string, object>(),
|
||||||
new DialogOptions() { Width = "700px", Height = "570px", Resizable = true, Draggable = true });
|
new DialogOptions() { Width = "700px", Height = "570px", Resizable = true, Draggable = true });
|
||||||
|
|
||||||
|
var token = new Token
|
||||||
|
{
|
||||||
|
Id = Guid.NewGuid(),
|
||||||
|
Name = newFileModel.Name,
|
||||||
|
Description = newFileModel.Description,
|
||||||
|
CreatedAt = DateTime.Now,
|
||||||
|
Image = new TokenMedia
|
||||||
|
{
|
||||||
|
FileName = newFileModel.FileName,
|
||||||
|
FileSize = newFileModel.FileSize!.Value,
|
||||||
|
FileData = newFileModel.FileData,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
AppState.Storage.Tokens ??= new List<IToken>();
|
||||||
|
AppState.Storage.Tokens.Add(token);
|
||||||
|
RefreshData();
|
||||||
|
StateHasChangedSafe();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,5 +2,7 @@ namespace NftFaucetRadzen.Plugins;
|
|||||||
|
|
||||||
public interface ITokenMedia
|
public interface ITokenMedia
|
||||||
{
|
{
|
||||||
|
public string FileData { get; }
|
||||||
|
public string FileName { get; }
|
||||||
|
public long FileSize { get; }
|
||||||
}
|
}
|
8
NftFaucetRadzen/Plugins/TokenMedia.cs
Normal file
8
NftFaucetRadzen/Plugins/TokenMedia.cs
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
namespace NftFaucetRadzen.Plugins;
|
||||||
|
|
||||||
|
public class TokenMedia : ITokenMedia
|
||||||
|
{
|
||||||
|
public string FileData { get; set; }
|
||||||
|
public string FileName { get; set; }
|
||||||
|
public long FileSize { get; set; }
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user