Skip to content

Commit

Permalink
Progress creating new tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
michielpost committed Sep 6, 2024
1 parent e18a237 commit 1ef836e
Show file tree
Hide file tree
Showing 16 changed files with 494 additions and 51 deletions.
2 changes: 1 addition & 1 deletion src/aoWebWallet.Tests/aoWebWallet.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageReference Include="MSTest.TestAdapter" Version="3.5.2" />
<PackageReference Include="MSTest.TestFramework" Version="3.5.2" />
</ItemGroup>
Expand Down
11 changes: 11 additions & 0 deletions src/aoWebWallet/Models/CreateTokenModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace aoWebWallet.Models
{
public class CreateTokenModel
{
public string? Name { get; set; }
public string? Ticker { get; set; }
public string? LogoUrl { get; set; }
public int Denomination { get; set; }
public int TotalSupply { get; set; }
}
}
83 changes: 50 additions & 33 deletions src/aoWebWallet/Pages/CreateTokenPage.razor
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
@inject WalletDetailViewModel WalletDetailViewModel
@using Soenneker.Blazor.Utils.Navigation.Abstract
@inject INavigationUtil NavigationUtil
@inject CreateTokenService CreateTokenService

<PageTitle>Create Token @Program.PageTitlePostFix</PageTitle>

Expand All @@ -18,57 +19,73 @@

<MudText Typo="Typo.h5">Create a new token</MudText>

<MudForm @ref="form" Model="tokenModel" Validated="OnValidated">
<MudTextField @bind-Value="tokenModel.Name" Label="Token Name" Required="true" />
<MudTextField @bind-Value="tokenModel.Ticker" Label="Ticker Symbol" MaxLength="5" Required="true" />
<MudTextField @bind-Value="tokenModel.LogoUrl" Label="Logo URL" />
<MudNumericField @bind-Value="tokenModel.Denomination" Label="Denomination" Required="true" />
<MudNumericField @bind-Value="tokenModel.TotalSupply" Label="Total Number of Tokens" Required="true" />
@if (!isSubmitting && !string.IsNullOrEmpty(BindingContext.ActiveWalletAddress))
{
<MudForm Model="tokenModel">
<MudTextField @bind-Value="tokenModel.Name" Label="Token Name" Required="true" />
<MudTextField @bind-Value="tokenModel.Ticker" Label="Ticker Symbol" MaxLength="5" Required="true" />
<MudTextField @bind-Value="tokenModel.LogoUrl" Label="Logo URL" />
<MudNumericField @bind-Value="tokenModel.Denomination" Label="Denomination" Required="true" />

<MudNumericField @bind-Value="tokenModel.TotalSupply" Label="Initial mint amount" Required="true" />

<MudButton Color="Color.Primary" Variant="Variant.Filled" OnClick="Submit" Class="mt-8">Submit</MudButton>
</MudForm>
}
else
{
<SendTransactionProgress DataLoader="CreateTokenService.CreateTokenProgress.DataLoader" Title="Creating token..." />

<MudButton Color="Color.Primary" Variant="Variant.Filled" OnClick="Submit" Class="mt-8">Submit</MudButton>
</MudForm>
@if (!string.IsNullOrEmpty(CreateTokenService.CreateTokenProgress.Data))
{
<MudText Class="mt-4">@CreateTokenService.CreateTokenProgress.Data</MudText>
}

@if (CreateTokenService.CreateTokenProgress.DataLoader.LoadingState == LoadingState.Finished)
{
<MudButton Color="Color.Primary" Variant="Variant.Filled" OnClick="ReturnToWallet" Class="mt-8">Return to Wallet</MudButton>
}
}
</MudContainer>

@code {
private bool readOnly = false;
private MudForm? form;
private TokenModel tokenModel = new TokenModel();
private bool isSubmitting = false;
private CreateTokenModel tokenModel = new CreateTokenModel();
private List<BreadcrumbItem> _items = new List<BreadcrumbItem>
{
new BreadcrumbItem("Home", href: "/"),
new BreadcrumbItem("Create Token", href: null, disabled: true)
};

private async void Submit()
private async Task Submit()
{
if(form != null)
await form.Validate();
isSubmitting = true;

Snackbar.Add("TEST", Severity.Success);
if (BindingContext.WalletList.Data == null)
return;

}

private async void OnValidated()
{
if (form?.IsValid ?? false)
{
// Create a new process and load token code
//await dataService.CreateTokenProcess(tokenModel);
Snackbar.Add("Token created successfully!", Severity.Success);
NavigationManager.NavigateTo("/wallet");
}
else
var wallet = BindingContext.WalletList.Data.Where(x => x.Address == BindingContext.ActiveWalletAddress).FirstOrDefault();
if (wallet == null)
{
Snackbar.Add("Please fill in all required fields.", Severity.Error);
if (BindingContext.ActiveWallet?.Address == BindingContext.ActiveWalletAddress)
{
wallet = BindingContext.ActiveWallet;
}
}

if (wallet == null)
return;

await CreateTokenService.CreateToken(wallet, tokenModel);
//Snackbar.Add("Token created successfully!", Severity.Success);
}

private class TokenModel
private void ReturnToWallet()
{
public string? Name { get; set; }
public string? Ticker { get; set; }
public string? LogoUrl { get; set; }
public int Denomination { get; set; }
public int TotalSupply { get; set; }
NavigationManager.NavigateTo($"/wallet/{BindingContext.ActiveWalletAddress}");
}


}
33 changes: 33 additions & 0 deletions src/aoWebWallet/Pages/CreateTokenPage.razor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using aoWebWallet.ViewModels;
using aoww.ProcesModels.Action;
using Microsoft.AspNetCore.Components.Routing;

namespace aoWebWallet.Pages
{
public partial class CreateTokenPage : MvvmComponentBase<MainViewModel>
{
protected override void OnInitialized()
{
WatchProp(nameof(BindingContext.ActiveWalletAddress));
WatchDataLoaderVM(BindingContext.WalletList);
WatchDataLoaderVM(CreateTokenService.CreateTokenProgress);


base.OnInitialized();
}

protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
{
await BindingContext.CheckHasArConnectExtension();

await BindingContext.LoadWalletList();
//await dataService.LoadTokenList();
}

await base.OnAfterRenderAsync(firstRender);
}

}
}
Loading

0 comments on commit 1ef836e

Please sign in to comment.