Skip to content

Commit

Permalink
show preview code
Browse files Browse the repository at this point in the history
  • Loading branch information
michielpost committed Sep 23, 2024
1 parent 8cdb511 commit eb86971
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 72 deletions.
30 changes: 28 additions & 2 deletions src/aoWebWallet/Pages/CreateTokenPage.razor
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,16 @@
<MudNumericField @bind-Value="tokenModel.Denomination" Label="Denomination" Required="true" />
<MudNumericField @bind-Value="tokenModel.TotalSupply" Format="@DenominationFormat" Label="Initial mint amount" Required="true" />

<MudButton Color="Color.Primary" Variant="Variant.Filled" Disabled="@IsDisabled" OnClick="Submit" Class="mt-8">Submit</MudButton>
@if (isPreview)
{
<br />
<MudTextField @bind-Value="data" Lines="15" Style="color:black;background-color:white;font-family:Consolas,Monaco,Lucida Console,Liberation Mono,DejaVu Sans Mono,Bitstream Vera Sans Mono,Courier New;" Label="Process Code" />
}

<MudStack Row="true">
<MudButton Color="Color.Secondary" Variant="Variant.Filled" Disabled="@IsDisabled" OnClick="Preview" Class="mt-8">Preview</MudButton>
<MudButton Color="Color.Primary" Variant="Variant.Filled" Disabled="@IsDisabled" OnClick="Submit" Class="mt-8">Submit</MudButton>
</MudStack>
</MudForm>
}
else
Expand Down Expand Up @@ -56,6 +65,8 @@
@code {
private bool readOnly = false;
private bool isSubmitting = false;
private bool isPreview = false;
private string? data = null;
private CreateTokenModel tokenModel = new CreateTokenModel();
private List<BreadcrumbItem> _items = new List<BreadcrumbItem>
{
Expand All @@ -66,6 +77,17 @@
public string DenominationFormat => "F" + (tokenModel.Denomination).ToString();
public bool IsDisabled => string.IsNullOrWhiteSpace(tokenModel.Name) || string.IsNullOrWhiteSpace(tokenModel.Ticker);

private void Preview()
{
var wallet = GetSelectedWallet();

if (wallet == null)
return;

isPreview = true;
data = CreateTokenService.GetTokenProcessCode(wallet.Address, tokenModel);
}

private async Task Submit()
{
isSubmitting = true;
Expand All @@ -75,7 +97,11 @@
if (wallet == null)
return;

await CreateTokenService.CreateToken(wallet, tokenModel);
//Run preview if not run yet
if (data == null)
data = CreateTokenService.GetTokenProcessCode(wallet.Address, tokenModel);

await CreateTokenService.CreateToken(wallet, tokenModel, data);
//Snackbar.Add("Token created successfully!", Severity.Success);
}
Expand Down
10 changes: 4 additions & 6 deletions src/aoWebWallet/Pages/WalletDetail.razor
Original file line number Diff line number Diff line change
Expand Up @@ -212,12 +212,10 @@
<MudItem xs="12" sm="6">
<ActionList ProcessId="@Address" />
</MudItem>
<MudItem xs="12" sm="6">
@if (BindingContext.SelectedWallet?.Wallet.OwnerAddress != null)
{
<HandlerList ProcessId="@Address" OwnerId="@BindingContext.SelectedWallet?.Wallet.OwnerAddress" />
}
</MudItem>
@if (BindingContext.SelectedWallet?.Wallet.OwnerAddress != null)
{
<HandlerList ProcessId="@Address" OwnerId="@BindingContext.SelectedWallet?.Wallet.OwnerAddress" />
}
</MudGrid>
</MudTabPanel>
</MudTabs>
Expand Down
55 changes: 32 additions & 23 deletions src/aoWebWallet/Services/CreateTokenService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,35 +15,26 @@ public void Reset()
CreateTokenProgress = new();
}

public Task<string?> CreateToken(Wallet wallet, CreateTokenModel tokenModel)
public string GetTokenProcessCode(string address, CreateTokenModel tokenModel)
{
string data = EmbeddedResourceReader.ReadResource("aoWebWallet.ProcessTemplates.token.lua");

data = data.Replace("ao.id", $"\"{address}\"");
data = data.Replace("$Denomination$", tokenModel.Denomination.ToString());
data = data.Replace("$Ticker$", tokenModel.Ticker);
data = data.Replace("$Logo$", tokenModel.LogoUrl);

return data;
}

public Task<string?> CreateToken(Wallet wallet, CreateTokenModel tokenModel, string data)
=> CreateTokenProgress.DataLoader.LoadAsync(async () =>
{
var address = wallet.Address;
string? jwk = wallet.Jwk;
string data = EmbeddedResourceReader.ReadResource("aoWebWallet.ProcessTemplates.token.lua");
data = data.Replace("ao.id", $"\"{address}\"");
data = data.Replace("$Denomination$", tokenModel.Denomination.ToString());
data = data.Replace("$Ticker$", tokenModel.Ticker);
data = data.Replace("$Logo$", tokenModel.LogoUrl);
string moduleId = "zx6_08gJzKNXxLCplINj6TPv9-ElRgeRqr9F6riRBK8";
//string previewModuleId = "PSPMkkFrJzYI2bQbkmeEQ5ONmeR-FJZu0fNQoSCU1-I";
CreateTokenProgress.DataLoader.ProgressMsg = "Deploying new process...";
CreateTokenProgress.ForcePropertyChanged();
string newProcessId = await arweaveService.CreateProcess(jwk, moduleId, new List<Tag> {
new Tag { Name = "App-Name", Value = "aoww" },
new Tag() { Name = "Name", Value = tokenModel.Name ?? string.Empty},
}
);
Console.WriteLine("process finish");
string newProcessId = await CreateEmptyProcess(tokenModel.Name, jwk);
if (string.IsNullOrWhiteSpace(newProcessId))
{
Expand Down Expand Up @@ -105,5 +96,23 @@ public void Reset()
CreateTokenProgress.DataLoader.ProgressMsg = "Token created successfully!";
return newProcessId;
}, x => CreateTokenProgress.Data = x);

private async Task<string> CreateEmptyProcess(string? processName, string? jwk)
{
string moduleId = "zx6_08gJzKNXxLCplINj6TPv9-ElRgeRqr9F6riRBK8";
//string previewModuleId = "PSPMkkFrJzYI2bQbkmeEQ5ONmeR-FJZu0fNQoSCU1-I";

CreateTokenProgress.DataLoader.ProgressMsg = "Deploying new process...";
CreateTokenProgress.ForcePropertyChanged();

string newProcessId = await arweaveService.CreateProcess(jwk, moduleId, new List<Tag> {
new Tag { Name = "App-Name", Value = "aoww" },
new Tag() { Name = "Name", Value = processName ?? string.Empty},

});

Console.WriteLine("Finished creating process");
return newProcessId;
}
}
}
85 changes: 44 additions & 41 deletions src/aoWebWallet/Shared/Components/HandlerList.razor
Original file line number Diff line number Diff line change
Expand Up @@ -4,53 +4,56 @@
@inject AODataClient aoDataClient
@inject NavigationManager NavigationManager

<MudPaper Class="pa-4">
<MudText Typo="Typo.h6">Handlers</MudText>
@if (handlers == null)
{
<MudProgressCircular Color="Color.Default" Indeterminate="true" />
}
else if (handlers.Count == 0)
{
<MudText>No handlers found.</MudText>
}
else
{
<MudList T="string">
@foreach (var handler in handlers)
{
<MudListItem>@handler</MudListItem>
}
</MudList>
}
</MudPaper>

@if(processType != null)
{
<MudPaper Class="pa-4">
<MudText Typo="Typo.h6">Process Type Detected: @processType</MudText>

@if (readActions.Any())
<MudItem xs="12" sm="6">
<MudPaper Class="pa-4">
<MudText Typo="Typo.h6">Handlers</MudText>
@if (handlers == null)
{
<MudButtonGroup Color="Color.Primary" Variant="Variant.Filled">
@foreach (var action in readActions)
{
<MudButton OnClick="() => GoToSend(action.AoAction)">@action.Name</MudButton>
}
</MudButtonGroup>
<MudProgressCircular Color="Color.Default" Indeterminate="true" />
}

@if (messageActions.Any())
else if (handlers.Count == 0)
{
<MudText>No handlers found.</MudText>
}
else
{
<MudButtonGroup Color="Color.Primary" Variant="Variant.Filled">
@foreach (var action in messageActions)
<MudList T="string">
@foreach (var handler in handlers)
{
<MudButton OnClick="() => GoToSend(action.AoAction)">@action.Name</MudButton>
<MudListItem>@handler</MudListItem>
}
</MudButtonGroup>
</MudList>
}
</MudPaper>
</MudPaper>
</MudItem>

@if (processType != null)
{
<MudItem xs="12" sm="6">
<MudPaper Class="pa-4">
<MudText Typo="Typo.h6">Process Type Detected: @processType</MudText>

@if (readActions.Any())
{
<MudButtonGroup Color="Color.Primary" Variant="Variant.Filled">
@foreach (var action in readActions)
{
<MudButton OnClick="() => GoToSend(action.AoAction)">@action.Name</MudButton>
}
</MudButtonGroup>
}

@if (messageActions.Any())
{
<MudButtonGroup Color="Color.Primary" Variant="Variant.Filled">
@foreach (var action in messageActions)
{
<MudButton OnClick="() => GoToSend(action.AoAction)">@action.Name</MudButton>
}
</MudButtonGroup>
}
</MudPaper>
</MudItem>
}

@code {
Expand Down Expand Up @@ -79,7 +82,7 @@

processType = DetectProcessType(handlers);

if(process != null)
if (process != null)
{
readActions = process.GetActionMetadata().ToList();
//readActions = process.GetVisibleDryRunActions().ToList();
Expand Down

0 comments on commit eb86971

Please sign in to comment.