Skip to content

Commit

Permalink
Create token improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
michielpost committed Sep 6, 2024
1 parent 1ef836e commit d2fe4ab
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 20 deletions.
10 changes: 7 additions & 3 deletions src/aoWebWallet/Models/CreateTokenModel.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
namespace aoWebWallet.Models
using aoWebWallet.Services;

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; }
public int Denomination { get; set; } = 2;
public decimal TotalSupply { get; set; } = 100;
public string MintQuantityForTag => BalanceHelper.DecimalToTokenAmount(TotalSupply, Denomination).ToString();

}
}
25 changes: 15 additions & 10 deletions src/aoWebWallet/Pages/CreateTokenPage.razor
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,28 @@
<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" />
<MudTextField @bind-Value="tokenModel.LogoUrl" Label="ArweaveId of logo" MaxLength="43"/>
<MudNumericField @bind-Value="tokenModel.Denomination" Label="Denomination" Required="true" />
<MudNumericField @bind-Value="tokenModel.TotalSupply" Format="@DenominationFormat" Label="Initial mint amount" 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>
<MudButton Color="Color.Primary" Variant="Variant.Filled" Disabled="@IsDisabled" OnClick="Submit" Class="mt-8">Submit</MudButton>
</MudForm>
}
else
{
<SendTransactionProgress DataLoader="CreateTokenService.CreateTokenProgress.DataLoader" Title="Creating token..." />

@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>
if (!string.IsNullOrEmpty(CreateTokenService.CreateTokenProgress.Data))
{

<br />
<MudText Class="mt-4">New tokenId: @CreateTokenService.CreateTokenProgress.Data</MudText>
<br />
}

<MudButton Color="Color.Primary" Variant="Variant.Filled" OnClick="ReturnToWallet" Class="mt-8">Return to Wallet</MudButton>
}
}
</MudContainer>
Expand All @@ -58,6 +60,9 @@
new BreadcrumbItem("Create Token", href: null, disabled: true)
};

public string DenominationFormat => "F" + (tokenModel.Denomination).ToString();
public bool IsDisabled => string.IsNullOrWhiteSpace(tokenModel.Name) || string.IsNullOrWhiteSpace(tokenModel.Ticker);

private async Task Submit()
{
isSubmitting = true;
Expand Down
5 changes: 4 additions & 1 deletion src/aoWebWallet/Pages/CreateTokenPage.razor.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using aoWebWallet.ViewModels;
using aoWebWallet.Services;
using aoWebWallet.ViewModels;
using aoww.ProcesModels.Action;
using Microsoft.AspNetCore.Components.Routing;

Expand All @@ -8,6 +9,8 @@ public partial class CreateTokenPage : MvvmComponentBase<MainViewModel>
{
protected override void OnInitialized()
{
CreateTokenService.Reset();

WatchProp(nameof(BindingContext.ActiveWalletAddress));
WatchDataLoaderVM(BindingContext.WalletList);
WatchDataLoaderVM(CreateTokenService.CreateTokenProgress);
Expand Down
16 changes: 12 additions & 4 deletions src/aoWebWallet/Services/CreateTokenService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ public class CreateTokenService(ArweaveService arweaveService, TransactionServic
{
public DataLoaderViewModel<string> CreateTokenProgress { get; set; } = new();

public void Reset()
{
CreateTokenProgress = new();
}

public Task<string?> CreateToken(Wallet wallet, CreateTokenModel tokenModel)
=> CreateTokenProgress.DataLoader.LoadAsync(async () =>
{
Expand Down Expand Up @@ -45,7 +50,8 @@ public class CreateTokenService(ArweaveService arweaveService, TransactionServic
if (string.IsNullOrWhiteSpace(newProcessId))
{
return "Failed to create new process";
CreateTokenProgress.DataLoader.ProgressMsg = "Failed to create new process";
return null;
}
else
{
Expand Down Expand Up @@ -80,7 +86,8 @@ public class CreateTokenService(ArweaveService arweaveService, TransactionServic
if (dataId == null)
{
return $"Failed to reach process after maximum retries ({maxRetries})";
CreateTokenProgress.DataLoader.ProgressMsg = $"Failed to reach process after maximum retries ({maxRetries})";
return null;
}
if (dataId != null)
Expand All @@ -92,13 +99,14 @@ public class CreateTokenService(ArweaveService arweaveService, TransactionServic
{
new ArweaveBlazor.Models.Tag { Name = "Target", Value = newProcessId},
new ArweaveBlazor.Models.Tag { Name = "Action", Value = "Mint"},
new ArweaveBlazor.Models.Tag { Name = "Quantity", Value = tokenModel.TotalSupply.ToString()}
new ArweaveBlazor.Models.Tag { Name = "Quantity", Value = tokenModel.MintQuantityForTag}
});
Console.WriteLine("mintResult: " + mintResult);
}
return "Token created successfully!";
CreateTokenProgress.DataLoader.ProgressMsg = "Token created successfully!";
return newProcessId;
}, x => CreateTokenProgress.Data = x);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
return;

<MudText Typo="Typo.overline">@Title</MudText>
<MudText Typo="Typo.overline">@DataLoader?.ProgressMsg</MudText>
@if (!string.IsNullOrWhiteSpace(DataLoader?.ProgressMsg))
{
<br />
<MudText Typo="Typo.overline">@DataLoader?.ProgressMsg</MudText>
}
<MudProgressLinear Color="Color.Primary" Indeterminate="true" Class="my-7" />

@code {
Expand Down
2 changes: 1 addition & 1 deletion src/aoWebWallet/aoWebWallet.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<PackageReference Include="ArweaveBlazor" Version="0.0.11" />
<PackageReference Include="ClipLazor" Version="2.1.1" />
<PackageReference Include="CodeBeam.MudBlazor.Extensions" Version="7.0.1" />
<PackageReference Include="MudBlazor" Version="7.7.0" />
<PackageReference Include="MudBlazor" Version="7.8.0" />
<PackageReference Include="Blazored.LocalStorage" Version="4.5.0" />
<PackageReference Include="BlazorWasmPreRendering.Build" Version="4.0.0" />
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.3.0" />
Expand Down

0 comments on commit d2fe4ab

Please sign in to comment.