diff --git a/src/aoWebWallet/Pages/CreateTokenPage.razor b/src/aoWebWallet/Pages/CreateTokenPage.razor index 150db8e..15cb823 100644 --- a/src/aoWebWallet/Pages/CreateTokenPage.razor +++ b/src/aoWebWallet/Pages/CreateTokenPage.razor @@ -28,7 +28,16 @@ - Submit + @if (isPreview) + { +
+ + } + + + Preview + Submit + } else @@ -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 _items = new List { @@ -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; @@ -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); } diff --git a/src/aoWebWallet/Pages/WalletDetail.razor b/src/aoWebWallet/Pages/WalletDetail.razor index 1ac54fa..8e549a5 100644 --- a/src/aoWebWallet/Pages/WalletDetail.razor +++ b/src/aoWebWallet/Pages/WalletDetail.razor @@ -212,12 +212,10 @@ - - @if (BindingContext.SelectedWallet?.Wallet.OwnerAddress != null) - { - - } - + @if (BindingContext.SelectedWallet?.Wallet.OwnerAddress != null) + { + + } diff --git a/src/aoWebWallet/Services/CreateTokenService.cs b/src/aoWebWallet/Services/CreateTokenService.cs index 3ed1ee1..7ed1ca3 100644 --- a/src/aoWebWallet/Services/CreateTokenService.cs +++ b/src/aoWebWallet/Services/CreateTokenService.cs @@ -15,35 +15,26 @@ public void Reset() CreateTokenProgress = new(); } - public Task 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 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 { - 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)) { @@ -105,5 +96,23 @@ public void Reset() CreateTokenProgress.DataLoader.ProgressMsg = "Token created successfully!"; return newProcessId; }, x => CreateTokenProgress.Data = x); + + private async Task 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 { + new Tag { Name = "App-Name", Value = "aoww" }, + new Tag() { Name = "Name", Value = processName ?? string.Empty}, + + }); + + Console.WriteLine("Finished creating process"); + return newProcessId; + } } } \ No newline at end of file diff --git a/src/aoWebWallet/Shared/Components/HandlerList.razor b/src/aoWebWallet/Shared/Components/HandlerList.razor index b656f72..1d9230f 100644 --- a/src/aoWebWallet/Shared/Components/HandlerList.razor +++ b/src/aoWebWallet/Shared/Components/HandlerList.razor @@ -4,53 +4,56 @@ @inject AODataClient aoDataClient @inject NavigationManager NavigationManager - - Handlers - @if (handlers == null) - { - - } - else if (handlers.Count == 0) - { - No handlers found. - } - else - { - - @foreach (var handler in handlers) - { - @handler - } - - } - - -@if(processType != null) -{ - - Process Type Detected: @processType - - @if (readActions.Any()) + + + Handlers + @if (handlers == null) { - - @foreach (var action in readActions) - { - @action.Name - } - + } - - @if (messageActions.Any()) + else if (handlers.Count == 0) + { + No handlers found. + } + else { - - @foreach (var action in messageActions) + + @foreach (var handler in handlers) { - @action.Name + @handler } - + } - + + + +@if (processType != null) +{ + + + Process Type Detected: @processType + @if (readActions.Any()) + { + + @foreach (var action in readActions) + { + @action.Name + } + + } + + @if (messageActions.Any()) + { + + @foreach (var action in messageActions) + { + @action.Name + } + + } + + } @code { @@ -79,7 +82,7 @@ processType = DetectProcessType(handlers); - if(process != null) + if (process != null) { readActions = process.GetActionMetadata().ToList(); //readActions = process.GetVisibleDryRunActions().ToList();