From ec3c05dd06e4c644b1d86dd96a569ba05f3c275f Mon Sep 17 00:00:00 2001 From: Nuno Lopes Date: Mon, 1 Apr 2024 16:43:43 +0100 Subject: [PATCH 1/9] meme frames 101 --- src/aoWebWallet/Pages/MemeFrames.razor | 64 ++++++++++++++++++++++++++ src/aoWebWallet/Shared/NavMenu.razor | 1 + 2 files changed, 65 insertions(+) create mode 100644 src/aoWebWallet/Pages/MemeFrames.razor diff --git a/src/aoWebWallet/Pages/MemeFrames.razor b/src/aoWebWallet/Pages/MemeFrames.razor new file mode 100644 index 0000000..671bb51 --- /dev/null +++ b/src/aoWebWallet/Pages/MemeFrames.razor @@ -0,0 +1,64 @@ +@page "/meme-frames" +@using aoWebWallet.Models +@inherits MvvmComponentBase +@inject IDialogService DialogService +@inject ISnackbar Snackbar + +@Program.PageTitlePostFix + + + + Meme Frames + + + + + + + I + + + Name: MEME + Creator: Andy Tudhope + Mint cap: 1,000,000 CRED + + + + + + 25% + + + + Theme: The zeroth memecoin minted on ao: winner of hackathon prizes, poet of iframes, informer of votes, verifier of processes, pilgrim of the hyper parallel spaces between, believer in dreams, drafter of the dankest memes. + + + + + + + Mint + Stake + Yay + Nay + + + + + + + + + . + + + . + + + + +@code +{ + + +} diff --git a/src/aoWebWallet/Shared/NavMenu.razor b/src/aoWebWallet/Shared/NavMenu.razor index 2f506d6..94caeb9 100644 --- a/src/aoWebWallet/Shared/NavMenu.razor +++ b/src/aoWebWallet/Shared/NavMenu.razor @@ -29,6 +29,7 @@ } Token Explorer + Meme Frames
From 675b2e43d755a36ef26864fc72c7d3fcb1cea145 Mon Sep 17 00:00:00 2001 From: Michiel Post Date: Wed, 19 Jun 2024 11:51:05 +0200 Subject: [PATCH 2/9] Refactoring setup to support MemeFrames --- src/aoWebWallet.sln | 7 + .../Extensions/AoActionParamExtensions.cs | 22 +++ src/aoWebWallet/Pages/ActionPage.razor.cs | 1 + src/aoWebWallet/Pages/MemeFrames.razor | 141 ++++++++++++------ src/aoWebWallet/Pages/ScanQrPage.razor | 3 +- src/aoWebWallet/Services/StorageService.cs | 12 ++ .../Services/TransactionService.cs | 1 + .../Shared/BalanceDataComponent.razor | 3 +- .../ViewModels/ReceiveViewModel.cs | 4 +- src/aoWebWallet/_Imports.razor | 3 +- src/aoWebWallet/aoWebWallet.csproj | 1 + .../Action}/ActionParam.cs | 57 +------ .../Interfaces/IProcessMetadata.cs | 14 ++ src/aoww.ProcesModels/MemeFrameProcess.cs | 137 +++++++++++++++++ .../Metadata/ActionMetadata.cs | 33 ++++ .../Metadata/ProcessMetadata.cs | 13 ++ src/aoww.ProcesModels/Process.cs | 14 ++ src/aoww.ProcesModels/TokenProcess.cs | 62 ++++++++ .../aoww.ProcesModels.csproj | 10 ++ src/aoww.Services/aoww.Services.csproj | 17 ++- 20 files changed, 450 insertions(+), 105 deletions(-) create mode 100644 src/aoWebWallet/Extensions/AoActionParamExtensions.cs rename src/{aoWebWallet/Models => aoww.ProcesModels/Action}/ActionParam.cs (68%) create mode 100644 src/aoww.ProcesModels/Interfaces/IProcessMetadata.cs create mode 100644 src/aoww.ProcesModels/MemeFrameProcess.cs create mode 100644 src/aoww.ProcesModels/Metadata/ActionMetadata.cs create mode 100644 src/aoww.ProcesModels/Metadata/ProcessMetadata.cs create mode 100644 src/aoww.ProcesModels/Process.cs create mode 100644 src/aoww.ProcesModels/TokenProcess.cs create mode 100644 src/aoww.ProcesModels/aoww.ProcesModels.csproj diff --git a/src/aoWebWallet.sln b/src/aoWebWallet.sln index 3cac0de..081a70f 100644 --- a/src/aoWebWallet.sln +++ b/src/aoWebWallet.sln @@ -17,6 +17,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "aoww.Services.Tests", "aoww EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "aoWebWallet.Tests", "aoWebWallet.Tests\aoWebWallet.Tests.csproj", "{12E9E40E-96D1-4501-A9A4-EBE4D4F43D8D}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "aoww.ProcesModels", "aoww.ProcesModels\aoww.ProcesModels.csproj", "{739E7471-30E4-4522-86B8-5D9BB5F0896A}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -43,6 +45,10 @@ Global {12E9E40E-96D1-4501-A9A4-EBE4D4F43D8D}.Debug|Any CPU.Build.0 = Debug|Any CPU {12E9E40E-96D1-4501-A9A4-EBE4D4F43D8D}.Release|Any CPU.ActiveCfg = Release|Any CPU {12E9E40E-96D1-4501-A9A4-EBE4D4F43D8D}.Release|Any CPU.Build.0 = Release|Any CPU + {739E7471-30E4-4522-86B8-5D9BB5F0896A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {739E7471-30E4-4522-86B8-5D9BB5F0896A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {739E7471-30E4-4522-86B8-5D9BB5F0896A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {739E7471-30E4-4522-86B8-5D9BB5F0896A}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -52,6 +58,7 @@ Global {178C3213-D574-4B39-A2DA-1FB1D2806242} = {06E5BC39-764A-48B9-B4F9-F48387A2C965} {322F4807-05CF-431D-B400-7420E1B29936} = {89AC47DF-65AD-4870-AA1D-74ABF1F3D8FE} {12E9E40E-96D1-4501-A9A4-EBE4D4F43D8D} = {89AC47DF-65AD-4870-AA1D-74ABF1F3D8FE} + {739E7471-30E4-4522-86B8-5D9BB5F0896A} = {06E5BC39-764A-48B9-B4F9-F48387A2C965} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {432E3F8E-53FF-4D9C-869D-48449BD3B8B4} diff --git a/src/aoWebWallet/Extensions/AoActionParamExtensions.cs b/src/aoWebWallet/Extensions/AoActionParamExtensions.cs new file mode 100644 index 0000000..8519562 --- /dev/null +++ b/src/aoWebWallet/Extensions/AoActionParamExtensions.cs @@ -0,0 +1,22 @@ +using aoww.ProcesModels.Action; + +namespace aoWebWallet.Extensions +{ + public static class AcActionParamExtensions + { + public static List ToEvalTags(this AoAction action) + { + return action.Params.Select(x => new ArweaveBlazor.Models.Tag { Name = x.Key, Value = x.Value ?? string.Empty }).ToList(); + } + + public static List ToTags(this AoAction action) + { + return action.AllWithoutTarget.Select(x => new ArweaveBlazor.Models.Tag { Name = x.Key, Value = x.Value ?? string.Empty }).ToList(); + } + + public static List ToDryRunTags(this AoAction action) + { + return action.AllWithoutTarget.Select(x => new ArweaveAO.Models.Tag { Name = x.Key, Value = x.Value ?? string.Empty }).ToList(); + } + } +} diff --git a/src/aoWebWallet/Pages/ActionPage.razor.cs b/src/aoWebWallet/Pages/ActionPage.razor.cs index a9e0dc0..15a74b7 100644 --- a/src/aoWebWallet/Pages/ActionPage.razor.cs +++ b/src/aoWebWallet/Pages/ActionPage.razor.cs @@ -1,5 +1,6 @@ using aoWebWallet.Models; using aoWebWallet.ViewModels; +using aoww.ProcesModels.Action; using Microsoft.AspNetCore.Components.Routing; namespace aoWebWallet.Pages diff --git a/src/aoWebWallet/Pages/MemeFrames.razor b/src/aoWebWallet/Pages/MemeFrames.razor index 671bb51..39b2fe7 100644 --- a/src/aoWebWallet/Pages/MemeFrames.razor +++ b/src/aoWebWallet/Pages/MemeFrames.razor @@ -1,8 +1,13 @@ @page "/meme-frames" @using aoWebWallet.Models +@using aoww.ProcesModels @inherits MvvmComponentBase @inject IDialogService DialogService @inject ISnackbar Snackbar +@inject NavigationManager NavigationManager +@inject StorageService StorageService +@inject TransactionService TransactionService + @Program.PageTitlePostFix @@ -11,54 +16,106 @@ Meme Frames - - - - - I - - - Name: MEME - Creator: Andy Tudhope - Mint cap: 1,000,000 CRED - - - - - - 25% + + @foreach (var meme in memeList) + { + var memeProcess = new MemeFrameProcess(meme); + var readActions = memeProcess.GetActionMetadata().Where(x => x.ActionType == aoww.ProcesModels.Metadata.ActionType.DryRun).ToList(); + var messageActions = memeProcess.GetActionMetadata().Where(x => x.ActionType == aoww.ProcesModels.Metadata.ActionType.Message).ToList(); + + + + + + I + + + Id: @meme + Name: MEME + Creator: Andy Tudhope + Mint cap: 1,000,000 CRED + + + + + + 25% + + + + Theme: The zeroth memecoin minted on ao: winner of hackathon prizes, poet of iframes, informer of votes, verifier of processes, pilgrim of the hyper parallel spaces between, believer in dreams, drafter of the dankest memes. - - - Theme: The zeroth memecoin minted on ao: winner of hackathon prizes, poet of iframes, informer of votes, verifier of processes, pilgrim of the hyper parallel spaces between, believer in dreams, drafter of the dankest memes. - - - - - - - Mint - Stake - Yay - Nay - - - - - - - - - . - - - . - + + + + @if (readActions.Any()) + { + + + @foreach (var action in readActions) + { + @action.Name + } + + + } + + @if (messageActions.Any()) + { + + + @foreach (var action in messageActions) + { + @action.Name + } + + + } + + + + + + + } + + @code { + private List memeList = new(); + + protected override void OnInitialized() + { + //WatchCollection(dataService.TokenList); + //WatchObject(dataService.TokenDataLoader); + + base.OnInitialized(); + } + + protected override async Task OnAfterRenderAsync(bool firstRender) + { + if (firstRender) + { + memeList = await StorageService.GetMemeFrames(); + StateHasChanged(); + } + + await base.OnAfterRenderAsync(firstRender); + } + + private async Task DryRun(AoAction aoAction) + { + var testWallet = new Wallet() { Address = "OT9qTE2467gcozb2g8R6D6N3nQS94ENcaAIJfUzHCww" }; + var result = await TransactionService.DryRunAction(testWallet, aoAction); + Console.WriteLine(result?.Messages.FirstOrDefault()?.Data); + } + private void GoToSend(AoAction aoAction) + { + NavigationManager.NavigateTo($"/action?{aoAction.ToQueryString()}"); + } } diff --git a/src/aoWebWallet/Pages/ScanQrPage.razor b/src/aoWebWallet/Pages/ScanQrPage.razor index 44b719b..6e7e487 100644 --- a/src/aoWebWallet/Pages/ScanQrPage.razor +++ b/src/aoWebWallet/Pages/ScanQrPage.razor @@ -1,6 +1,7 @@ @page "/scan-qr" @using ReactorBlazorQRCodeScanner @using aoWebWallet.Models +@using aoww.ProcesModels @inherits MvvmComponentBase @inject GatewayUrlHelper UrlHelper; @inject ISnackbar Snackbar @@ -59,7 +60,7 @@ { string tokenId = code.Substring(tokenStart + 9, 43); - var aoAction = AoAction.CreateForTokenTransaction(address, tokenId); + var aoAction = TokenProcess.CreateForTokenTransaction(address, tokenId); NavigationManager.NavigateTo($"/action?{aoAction.ToQueryString()}"); } diff --git a/src/aoWebWallet/Services/StorageService.cs b/src/aoWebWallet/Services/StorageService.cs index 4497480..e60d40c 100644 --- a/src/aoWebWallet/Services/StorageService.cs +++ b/src/aoWebWallet/Services/StorageService.cs @@ -16,6 +16,18 @@ public StorageService(ILocalStorageService localStorage) this.localStorage = localStorage; } + public async ValueTask> GetMemeFrames() + { + var result = new List(); + + result.Add("OT9qTE2467gcozb2g8R6D6N3nQS94ENcaAIJfUzHCww"); //TRUNK + result.Add("2gM9n9QO6JG1_bZhCWr3fuEKJtzRgx1xvYUB92nVFAs"); //AORTA + result.Add("-a4T7XLMDGTcu8_preKXdUT6__4sJkMhYLEJZkXUYd0"); //MEME + result.Add("rik3eCayInKVNzSMdoxeSEfpxNd5U7tx1H8NAveg4o8"); //FINCH-MEME + + return result; + } + public async ValueTask> GetTokenIds() { var result = await localStorage.GetItemAsync>(TOKEN_LIST_KEY); diff --git a/src/aoWebWallet/Services/TransactionService.cs b/src/aoWebWallet/Services/TransactionService.cs index 73e599e..8a79d9a 100644 --- a/src/aoWebWallet/Services/TransactionService.cs +++ b/src/aoWebWallet/Services/TransactionService.cs @@ -1,5 +1,6 @@ using aoWebWallet.Extensions; using aoWebWallet.Models; +using aoww.ProcesModels.Action; using ArweaveAO.Requests; using ArweaveAO.Responses; using ArweaveBlazor; diff --git a/src/aoWebWallet/Shared/BalanceDataComponent.razor b/src/aoWebWallet/Shared/BalanceDataComponent.razor index 7dd0fa5..6e4a789 100644 --- a/src/aoWebWallet/Shared/BalanceDataComponent.razor +++ b/src/aoWebWallet/Shared/BalanceDataComponent.razor @@ -1,4 +1,5 @@ @using aoWebWallet.Models +@using aoww.ProcesModels @inject GatewayUrlHelper UrlHelper @inject IDialogService DialogService @inject NavigationManager NavigationManager @@ -60,7 +61,7 @@ if (balanceDataVM?.Token == null) return; - var aoAction = AoAction.CreateForTokenTransaction(balanceDataVM.Token.TokenId); + var aoAction = TokenProcess.CreateForTokenTransaction(balanceDataVM.Token.TokenId); NavigationManager.NavigateTo($"/action?{aoAction.ToQueryString()}"); } diff --git a/src/aoWebWallet/ViewModels/ReceiveViewModel.cs b/src/aoWebWallet/ViewModels/ReceiveViewModel.cs index 367ce27..b8e3789 100644 --- a/src/aoWebWallet/ViewModels/ReceiveViewModel.cs +++ b/src/aoWebWallet/ViewModels/ReceiveViewModel.cs @@ -1,5 +1,7 @@ using aoWebWallet.Models; using aoWebWallet.Services; +using aoww.ProcesModels; +using aoww.ProcesModels.Action; using aoww.Services; using aoww.Services.Models; using ArweaveAO; @@ -41,7 +43,7 @@ public string ShareLink { if (!string.IsNullOrWhiteSpace(TokenId)) { - return "/action?" + AoAction.CreateForTokenTransaction(Address, TokenId).ToQueryString(); + return "/action?" + TokenProcess.CreateForTokenTransaction(Address, TokenId).ToQueryString(); } else return $"/wallet/{Address}"; diff --git a/src/aoWebWallet/_Imports.razor b/src/aoWebWallet/_Imports.razor index ad39343..b6e1dba 100644 --- a/src/aoWebWallet/_Imports.razor +++ b/src/aoWebWallet/_Imports.razor @@ -19,4 +19,5 @@ @using ArweaveAO @using ArweaveBlazor @using aoWebWallet.Extensions -@using aoww.Services.Models \ No newline at end of file +@using aoww.Services.Models +@using aoww.ProcesModels.Action; diff --git a/src/aoWebWallet/aoWebWallet.csproj b/src/aoWebWallet/aoWebWallet.csproj index d01605b..ecfa673 100644 --- a/src/aoWebWallet/aoWebWallet.csproj +++ b/src/aoWebWallet/aoWebWallet.csproj @@ -26,6 +26,7 @@ + diff --git a/src/aoWebWallet/Models/ActionParam.cs b/src/aoww.ProcesModels/Action/ActionParam.cs similarity index 68% rename from src/aoWebWallet/Models/ActionParam.cs rename to src/aoww.ProcesModels/Action/ActionParam.cs index 666a5ec..4746b23 100644 --- a/src/aoWebWallet/Models/ActionParam.cs +++ b/src/aoww.ProcesModels/Action/ActionParam.cs @@ -1,7 +1,6 @@ - -using System.Text; +using System.Text; -namespace aoWebWallet.Models +namespace aoww.ProcesModels.Action { public class AoAction { @@ -10,7 +9,7 @@ public class AoAction public ActionParam? Target => Params.Where(x => x.ParamType == ActionParamType.Target).FirstOrDefault(); public IEnumerable AllWithoutTarget => Params.Where(x => x.ParamType != ActionParamType.Target); public IEnumerable Filled => Params.Where(x => x.ParamType == ActionParamType.Filled); - public IEnumerable AllInputs => Params.Where(x => + public IEnumerable AllInputs => Params.Where(x => x.ParamType != ActionParamType.Filled && x.ParamType != ActionParamType.Target); @@ -19,7 +18,7 @@ public class AoAction if (Target == null) return "No Target process specified."; - foreach(var input in AllInputs) + foreach (var input in AllInputs) { if (string.IsNullOrEmpty(input.Value)) return $"Please enter a value for {input.Key}"; @@ -28,22 +27,6 @@ public class AoAction return null; } - public List ToEvalTags() - { - return Params.Select(x => new ArweaveBlazor.Models.Tag { Name = x.Key, Value = x.Value ?? string.Empty }).ToList(); - } - - public List ToTags() - { - return AllWithoutTarget.Select(x => new ArweaveBlazor.Models.Tag { Name = x.Key, Value = x.Value ?? string.Empty }).ToList(); - } - - public List ToDryRunTags() - { - return AllWithoutTarget.Select(x => new ArweaveAO.Models.Tag { Name = x.Key, Value = x.Value ?? string.Empty }).ToList(); - } - - public string ToQueryString() { if (Target == null) @@ -53,12 +36,12 @@ public string ToQueryString() sb.Append($"{Target.Key}={Target.Value}&"); - foreach (var param in this.Filled) + foreach (var param in Filled) { sb.Append($"{param.Key}={param.Value}&"); } - foreach (var param in this.AllInputs) + foreach (var param in AllInputs) { var args = string.Join(';', param.Args); if (args.Length > 0) @@ -134,35 +117,7 @@ public static AoAction CreateFromQueryString(string qstring) return action; } - public static AoAction CreateForTokenTransaction(string recipient, string tokenId) - { - return new AoAction - { - Params = new List - { - new ActionParam { Key= "Target", ParamType = ActionParamType.Target, Value= tokenId }, - new ActionParam { Key= "Action", ParamType = ActionParamType.Filled, Value= "Transfer" }, - new ActionParam { Key= "Recipient", ParamType = ActionParamType.Filled, Value = recipient }, - new ActionParam { Key= "Quantity", ParamType = ActionParamType.Balance, Args = new List { tokenId } } - } - - }; - } - - public static AoAction CreateForTokenTransaction(string tokenId) - { - return new AoAction - { - Params = new List - { - new ActionParam { Key= "Target", ParamType = ActionParamType.Target, Value= tokenId }, - new ActionParam { Key= "Action", ParamType = ActionParamType.Filled, Value= "Transfer" }, - new ActionParam { Key= "Recipient", ParamType = ActionParamType.Process }, - new ActionParam { Key= "Quantity", ParamType = ActionParamType.Balance, Args = new List { tokenId } } - } - }; - } } public class ActionParam diff --git a/src/aoww.ProcesModels/Interfaces/IProcessMetadata.cs b/src/aoww.ProcesModels/Interfaces/IProcessMetadata.cs new file mode 100644 index 0000000..28c921e --- /dev/null +++ b/src/aoww.ProcesModels/Interfaces/IProcessMetadata.cs @@ -0,0 +1,14 @@ +using aoww.ProcesModels.Metadata; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace aoww.ProcesModels.Interfaces +{ + public interface IProcessMetadata + { + List GetActionMetadata(); + } +} diff --git a/src/aoww.ProcesModels/MemeFrameProcess.cs b/src/aoww.ProcesModels/MemeFrameProcess.cs new file mode 100644 index 0000000..bda8574 --- /dev/null +++ b/src/aoww.ProcesModels/MemeFrameProcess.cs @@ -0,0 +1,137 @@ +using aoww.ProcesModels.Action; +using aoww.ProcesModels.Metadata; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace aoww.ProcesModels +{ + public class MemeFrameProcess : Process + { + public string? MintTokenId { get; set; } + + public Dictionary? InfoResult { get; set; } + + public MemeFrameProcess(string processId) : base(processId) { } + + public override List GetActionMetadata() + { + var actions = new List() + { + new ActionMetadata + { + Name = "Info", + AutoRun = true, + ActionType = ActionType.DryRun, + AoAction = CreateAoActionGetInfo() + }, + new ActionMetadata + { + Name = "View Stakers", + ActionType = ActionType.DryRun, + AoAction = CreateAoActionViewStakers() + }, + //new ActionMetadata + //{ + // Name = "Get Frame", + // ActionType = ActionType.DryRun, + // AoAction = TokenProcess.CreateForTokenTransaction(this.ProcessId) + //}, + + new ActionMetadata + { + Name = "Stake", + ActionType = ActionType.Message, + AoAction = CreateAoActionStake() + }, + new ActionMetadata + { + Name = "Vote yay", + ActionType = ActionType.Message, + AoAction = CreateAoActionVote("yay") + }, + new ActionMetadata + { + Name = "Vote nay", + ActionType = ActionType.Message, + AoAction = CreateAoActionVote("nay") + } + , + //new ActionMetadata + //{ + // Name = "Get Votes", + // ActionType = ActionType.DryRun, + // AoAction = TokenProcess.CreateForTokenTransaction(this.ProcessId) + //} + }; + + if (MintTokenId != null) + { + actions.Add( + new ActionMetadata + { + Name = "Mint", + ActionType = ActionType.Message, + AoAction = TokenProcess.CreateForTokenTransaction(this.ProcessId, this.MintTokenId) + } + ); + } + + return actions; + } + + private AoAction CreateAoActionStake() + { + return new AoAction + { + Params = new List + { + new ActionParam { Key= "Target", ParamType = ActionParamType.Target, Value= this.ProcessId }, + new ActionParam { Key= "Action", ParamType = ActionParamType.Filled, Value= "Stake" }, + new ActionParam { Key= "Quantity", ParamType = ActionParamType.Balance, Args = new List { this.ProcessId } }, + new ActionParam { Key= "UnstakeDelay", ParamType = ActionParamType.Integer }, + } + }; + } + + private AoAction CreateAoActionVote(string vote) + { + return new AoAction + { + Params = new List + { + new ActionParam { Key= "Target", ParamType = ActionParamType.Target, Value= this.ProcessId }, + new ActionParam { Key= "Action", ParamType = ActionParamType.Filled, Value= "Vote" }, + new ActionParam { Key= "Side", ParamType = ActionParamType.Filled, Value = vote }, + new ActionParam { Key= "VoteId", ParamType = ActionParamType.Process }, + } + }; + } + + private AoAction CreateAoActionGetInfo() + { + return new AoAction + { + Params = new List + { + new ActionParam { Key= "Target", ParamType = ActionParamType.Target, Value= this.ProcessId }, + new ActionParam { Key= "Action", ParamType = ActionParamType.Filled, Value= "Info" }, + } + }; + } + + private AoAction CreateAoActionViewStakers() + { + return new AoAction + { + Params = new List + { + new ActionParam { Key= "Target", ParamType = ActionParamType.Target, Value= this.ProcessId }, + new ActionParam { Key= "Action", ParamType = ActionParamType.Filled, Value= "Stakers" }, + } + }; + } + } +} diff --git a/src/aoww.ProcesModels/Metadata/ActionMetadata.cs b/src/aoww.ProcesModels/Metadata/ActionMetadata.cs new file mode 100644 index 0000000..56271f6 --- /dev/null +++ b/src/aoww.ProcesModels/Metadata/ActionMetadata.cs @@ -0,0 +1,33 @@ +using aoww.ProcesModels.Action; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace aoww.ProcesModels.Metadata +{ + public class ActionMetadata + { + public required string Name { get; set; } + public int Order { get; set; } + + public ActionType ActionType { get; set; } + + public required AoAction AoAction { get; set; } + + public Action? IsEnabled { get; set; } + + public string? LastResult { get; set; } + + //Run on initialization + public bool AutoRun { get; set; } + } + + + public enum ActionType + { + Message, + DryRun + } +} diff --git a/src/aoww.ProcesModels/Metadata/ProcessMetadata.cs b/src/aoww.ProcesModels/Metadata/ProcessMetadata.cs new file mode 100644 index 0000000..ed69b28 --- /dev/null +++ b/src/aoww.ProcesModels/Metadata/ProcessMetadata.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace aoww.ProcesModels.Metadata +{ + public class ProcessMetadata + { + + } +} diff --git a/src/aoww.ProcesModels/Process.cs b/src/aoww.ProcesModels/Process.cs new file mode 100644 index 0000000..4bc24f9 --- /dev/null +++ b/src/aoww.ProcesModels/Process.cs @@ -0,0 +1,14 @@ +using aoww.ProcesModels.Interfaces; +using aoww.ProcesModels.Metadata; + +namespace aoww.ProcesModels +{ + public abstract class Process : IProcessMetadata + { + public string ProcessId { get; set; } + + public Process(string processId) => ProcessId = processId; + + public abstract List GetActionMetadata(); + } +} diff --git a/src/aoww.ProcesModels/TokenProcess.cs b/src/aoww.ProcesModels/TokenProcess.cs new file mode 100644 index 0000000..550bc43 --- /dev/null +++ b/src/aoww.ProcesModels/TokenProcess.cs @@ -0,0 +1,62 @@ +using aoww.ProcesModels.Action; +using aoww.ProcesModels.Metadata; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace aoww.ProcesModels +{ + public class TokenProcess : Process + { + public TokenProcess(string processId) : base(processId) + { + } + + public override List GetActionMetadata() + { + return new List() + { + new ActionMetadata + { + Name = "Send", + ActionType = ActionType.Message, + AoAction = TokenProcess.CreateForTokenTransaction(this.ProcessId) + } + }; + } + + + + public static AoAction CreateForTokenTransaction(string recipient, string tokenId) + { + return new AoAction + { + Params = new List + { + new ActionParam { Key= "Target", ParamType = ActionParamType.Target, Value= tokenId }, + new ActionParam { Key= "Action", ParamType = ActionParamType.Filled, Value= "Transfer" }, + new ActionParam { Key= "Recipient", ParamType = ActionParamType.Filled, Value = recipient }, + new ActionParam { Key= "Quantity", ParamType = ActionParamType.Balance, Args = new List { tokenId } } + } + + }; + } + + public static AoAction CreateForTokenTransaction(string tokenId) + { + return new AoAction + { + Params = new List + { + new ActionParam { Key= "Target", ParamType = ActionParamType.Target, Value= tokenId }, + new ActionParam { Key= "Action", ParamType = ActionParamType.Filled, Value= "Transfer" }, + new ActionParam { Key= "Recipient", ParamType = ActionParamType.Process }, + new ActionParam { Key= "Quantity", ParamType = ActionParamType.Balance, Args = new List { tokenId } } + } + + }; + } + } +} diff --git a/src/aoww.ProcesModels/aoww.ProcesModels.csproj b/src/aoww.ProcesModels/aoww.ProcesModels.csproj new file mode 100644 index 0000000..4d24086 --- /dev/null +++ b/src/aoww.ProcesModels/aoww.ProcesModels.csproj @@ -0,0 +1,10 @@ + + + + net8.0 + enable + enable + nullable + + + diff --git a/src/aoww.Services/aoww.Services.csproj b/src/aoww.Services/aoww.Services.csproj index cc6a561..3db74c7 100644 --- a/src/aoww.Services/aoww.Services.csproj +++ b/src/aoww.Services/aoww.Services.csproj @@ -1,13 +1,14 @@  - - net8.0 - enable - enable - + + net8.0 + enable + enable + nullable + - - - + + + From a93d8c7dbd995ad0e2c9ba1b6a9c1abe130f6677 Mon Sep 17 00:00:00 2001 From: Michiel Post Date: Wed, 19 Jun 2024 13:41:52 +0200 Subject: [PATCH 3/9] Refactored selecting current active wallet --- src/aoWebWallet/Pages/ActionPage.razor | 66 ++++--------------- src/aoWebWallet/Pages/ActionPage.razor.cs | 11 ++-- src/aoWebWallet/Pages/MemeFrames.razor | 14 ++-- src/aoWebWallet/Pages/MvvmComponentBase.cs | 26 ++++++-- src/aoWebWallet/Services/StorageService.cs | 30 +++++++-- .../SelectActiveWalletComponent.razor | 58 ++++++++++++++++ src/aoWebWallet/ViewModels/MainViewModel.cs | 4 +- .../ViewModels/WalletDetailViewModel.cs | 4 +- 8 files changed, 135 insertions(+), 78 deletions(-) create mode 100644 src/aoWebWallet/Shared/Components/SelectActiveWalletComponent.razor diff --git a/src/aoWebWallet/Pages/ActionPage.razor b/src/aoWebWallet/Pages/ActionPage.razor index 97b0169..718a8d6 100644 --- a/src/aoWebWallet/Pages/ActionPage.razor +++ b/src/aoWebWallet/Pages/ActionPage.razor @@ -14,55 +14,21 @@ - - @if (BindingContext.WalletList.Data != null) - { - var sendWallets = BindingContext.WalletList.Data.Where(x => !x.IsReadOnly).ToList(); - if (!sendWallets.Any()) - { - Add Wallet - } - else - { - - @foreach (var wallet in sendWallets ?? new()) - { - - - @* *@ - -
- - @wallet.Address - -
-
- @wallet.Name -
-
-
- -
- } -
- } - } - -
+ @if(readOnly) { Please review your transaction: } - + - @if (!readOnly && !string.IsNullOrEmpty(selectedWallet)) + @if (!readOnly && !string.IsNullOrEmpty(BindingContext.ActiveWalletAddress)) { Preview @validation } - else if (!started && !string.IsNullOrEmpty(selectedWallet) && string.IsNullOrEmpty(transactionService.LastTransaction.Data?.Id)) + else if (!started && !string.IsNullOrEmpty(BindingContext.ActiveWalletAddress) && string.IsNullOrEmpty(transactionService.LastTransaction.Data?.Id)) { if (transactionService.DryRunResult.Data != null) @@ -114,8 +80,7 @@ @code { private string? validation; - private string? selectedWallet; - private Wallet? selectedWalletObj; + private bool readOnly = false; private bool started = false; @@ -136,12 +101,12 @@ if (BindingContext.WalletList.Data == null) return; - var wallet = BindingContext.WalletList.Data.Where(x => x.Address == selectedWallet).FirstOrDefault(); + var wallet = BindingContext.WalletList.Data.Where(x => x.Address == BindingContext.ActiveWallet?.Address).FirstOrDefault(); if (wallet == null) { - if (selectedWalletObj?.Address == selectedWallet) + if (BindingContext.ActiveWallet?.Address == BindingContext.ActiveWalletAddress) { - wallet = selectedWalletObj; + wallet = BindingContext.ActiveWallet; } } @@ -161,7 +126,7 @@ private void ReturnToWallet() { - NavigationManager.NavigateTo($"/wallet/{selectedWallet}"); + NavigationManager.NavigateTo($"/wallet/{BindingContext.ActiveWallet?.Address}"); } private void ViewTransaction() @@ -178,12 +143,12 @@ if (BindingContext.WalletList.Data == null) return; - var wallet = BindingContext.WalletList.Data.Where(x => x.Address == selectedWallet).FirstOrDefault(); + var wallet = BindingContext.WalletList.Data.Where(x => x.Address == BindingContext.ActiveWallet?.Address).FirstOrDefault(); if(wallet == null) { - if(selectedWalletObj?.Address == selectedWallet) + if (BindingContext.ActiveWallet?.Address == BindingContext.ActiveWalletAddress) { - wallet = selectedWalletObj; + wallet = BindingContext.ActiveWallet; } } @@ -197,11 +162,6 @@ await transactionService.SendAction(wallet, ownerWallet, AoAction); } - private void OpenDialog() - { - NavigationManager.NavigateTo("/start"); - // var options = new DialogOptions { CloseOnEscapeKey = true }; - // DialogService.Show("Add Wallet", options); - } + } diff --git a/src/aoWebWallet/Pages/ActionPage.razor.cs b/src/aoWebWallet/Pages/ActionPage.razor.cs index 15a74b7..b7d8c3a 100644 --- a/src/aoWebWallet/Pages/ActionPage.razor.cs +++ b/src/aoWebWallet/Pages/ActionPage.razor.cs @@ -15,17 +15,18 @@ protected override void OnInitialized() GetQueryStringValues(); //WatchDataLoaderVM(BindingContext.TokenList); + WatchProp(nameof(BindingContext.ActiveWalletAddress)); WatchDataLoaderVM(BindingContext.WalletList); WatchDataLoaderVM(transactionService.LastTransaction); WatchDataLoaderVM(transactionService.DryRunResult); //Auto select wallet - if (!string.IsNullOrEmpty(WalletDetailViewModel.SelectedWallet?.Wallet.Address)) - { - selectedWalletObj = WalletDetailViewModel.SelectedWallet?.Wallet; - selectedWallet = selectedWalletObj?.Address; + //if (!string.IsNullOrEmpty(WalletDetailViewModel.SelectedWallet?.Wallet.Address)) + //{ + // selectedWalletObj = WalletDetailViewModel.SelectedWallet?.Wallet; + // selectedWallet = selectedWalletObj?.Address; - } + //} NavigationManager.LocationChanged += NavigationManager_LocationChanged; diff --git a/src/aoWebWallet/Pages/MemeFrames.razor b/src/aoWebWallet/Pages/MemeFrames.razor index 39b2fe7..da1c2c2 100644 --- a/src/aoWebWallet/Pages/MemeFrames.razor +++ b/src/aoWebWallet/Pages/MemeFrames.razor @@ -15,11 +15,12 @@ Meme Frames + + - @foreach (var meme in memeList) + @foreach (var memeProcess in memeList) { - var memeProcess = new MemeFrameProcess(meme); var readActions = memeProcess.GetActionMetadata().Where(x => x.ActionType == aoww.ProcesModels.Metadata.ActionType.DryRun).ToList(); var messageActions = memeProcess.GetActionMetadata().Where(x => x.ActionType == aoww.ProcesModels.Metadata.ActionType.Message).ToList(); @@ -30,7 +31,7 @@ I - Id: @meme + Id: @memeProcess.ProcessId Name: MEME Creator: Andy Tudhope Mint cap: 1,000,000 CRED @@ -85,7 +86,7 @@ @code { - private List memeList = new(); + private List memeList = new(); protected override void OnInitialized() { @@ -108,7 +109,10 @@ private async Task DryRun(AoAction aoAction) { - var testWallet = new Wallet() { Address = "OT9qTE2467gcozb2g8R6D6N3nQS94ENcaAIJfUzHCww" }; + if (BindingContext.ActiveWalletAddress == null) + return; + + var testWallet = new Wallet() { Address = BindingContext.ActiveWalletAddress }; var result = await TransactionService.DryRunAction(testWallet, aoAction); Console.WriteLine(result?.Messages.FirstOrDefault()?.Data); } diff --git a/src/aoWebWallet/Pages/MvvmComponentBase.cs b/src/aoWebWallet/Pages/MvvmComponentBase.cs index 68f0c45..eb74fc5 100644 --- a/src/aoWebWallet/Pages/MvvmComponentBase.cs +++ b/src/aoWebWallet/Pages/MvvmComponentBase.cs @@ -10,12 +10,13 @@ public abstract class MvvmComponentBase : ComponentBase, IDisposable where T [Inject] public T BindingContext { get; set; } = default!; + public List PropWatch { get; set; } = new(); public List ObjWatch { get; set; } = new(); public List CollectionWatch { get; set; } = new(); protected override void OnInitialized() { - //BindingContext.PropertyChanged += BindingContext_PropertyChanged; + BindingContext.PropertyChanged += BindingContext_PropertyChanged; foreach (var obj in ObjWatch) { @@ -30,11 +31,17 @@ protected override void OnInitialized() base.OnInitialized(); } - //private void BindingContext_PropertyChanged(object? sender, PropertyChangedEventArgs e) - //{ - // Console.WriteLine("Changed! " + e.PropertyName); - // this.StateHasChanged(); - //} + private void BindingContext_PropertyChanged(object? sender, PropertyChangedEventArgs e) + { + if (e.PropertyName == null) + return; + + if (PropWatch.Contains(e.PropertyName)) + { + Console.WriteLine("Changed! " + e.PropertyName); + this.StateHasChanged(); + } + } protected override async Task OnInitializedAsync() { @@ -81,9 +88,14 @@ protected void WatchDataLoaderVM(DataLoaderViewModel vm) where D : class ObjWatch.Add(vm.DataLoader); } + protected void WatchProp(string propName) + { + PropWatch.Add(propName); + } + public virtual void Dispose() { - //BindingContext.PropertyChanged -= BindingContext_PropertyChanged; + BindingContext.PropertyChanged -= BindingContext_PropertyChanged; foreach (var obj in ObjWatch) { diff --git a/src/aoWebWallet/Services/StorageService.cs b/src/aoWebWallet/Services/StorageService.cs index e60d40c..06a7b84 100644 --- a/src/aoWebWallet/Services/StorageService.cs +++ b/src/aoWebWallet/Services/StorageService.cs @@ -1,4 +1,5 @@ using aoWebWallet.Models; +using aoww.ProcesModels; using ArweaveAO.Models.Token; using Blazored.LocalStorage; @@ -8,6 +9,7 @@ public class StorageService { private readonly ILocalStorageService localStorage; + private const string MEMFRAME_LIST_KEY = "MEMFRAME_LIST"; private const string TOKEN_LIST_KEY = "TOKEN_LIST"; private const string WALLET_LIST_KEY = "WALLET_LIST"; private const string USER_SETTINGS_KEY = "USER_SETTINGS"; @@ -16,16 +18,32 @@ public StorageService(ILocalStorageService localStorage) this.localStorage = localStorage; } - public async ValueTask> GetMemeFrames() + public async ValueTask> GetMemeFrames() { - var result = new List(); + var result = await localStorage.GetItemAsync>(MEMFRAME_LIST_KEY); + result = result ?? new(); - result.Add("OT9qTE2467gcozb2g8R6D6N3nQS94ENcaAIJfUzHCww"); //TRUNK - result.Add("2gM9n9QO6JG1_bZhCWr3fuEKJtzRgx1xvYUB92nVFAs"); //AORTA - result.Add("-a4T7XLMDGTcu8_preKXdUT6__4sJkMhYLEJZkXUYd0"); //MEME - result.Add("rik3eCayInKVNzSMdoxeSEfpxNd5U7tx1H8NAveg4o8"); //FINCH-MEME + AddSystemMemeFrames(result,"OT9qTE2467gcozb2g8R6D6N3nQS94ENcaAIJfUzHCww"); //TRUNK + AddSystemMemeFrames(result,"2gM9n9QO6JG1_bZhCWr3fuEKJtzRgx1xvYUB92nVFAs"); //AORTA + AddSystemMemeFrames(result,"-a4T7XLMDGTcu8_preKXdUT6__4sJkMhYLEJZkXUYd0"); //MEME + AddSystemMemeFrames(result,"rik3eCayInKVNzSMdoxeSEfpxNd5U7tx1H8NAveg4o8"); //FINCH-MEME return result; + + } + + private static void AddSystemMemeFrames(List list, string processId) + { + var existing = list.Where(x => x.ProcessId == processId).FirstOrDefault(); + if (existing == null) + list.Add(new MemeFrameProcess(processId)); + } + + public ValueTask SaveMemeFrames(List list) + { + var uniqueItems = list.GroupBy(i => i.ProcessId).Select(g => g.First()); + + return localStorage.SetItemAsync(MEMFRAME_LIST_KEY, uniqueItems); } public async ValueTask> GetTokenIds() diff --git a/src/aoWebWallet/Shared/Components/SelectActiveWalletComponent.razor b/src/aoWebWallet/Shared/Components/SelectActiveWalletComponent.razor new file mode 100644 index 0000000..2b7b813 --- /dev/null +++ b/src/aoWebWallet/Shared/Components/SelectActiveWalletComponent.razor @@ -0,0 +1,58 @@ +@inherits MvvmComponentBase +@inject NavigationManager NavigationManager + + + @if (BindingContext.WalletList.Data != null) + { + var sendWallets = BindingContext.WalletList.Data.Where(x => !x.IsReadOnly).ToList(); + if (!sendWallets.Any()) + { + Add Wallet + } + else + { + + @foreach (var wallet in sendWallets ?? new()) + { + + + @* *@ + +
+ + @wallet.Address + +
+
+ @wallet.Name +
+
+
+ +
+ } +
+ } + } + +
+ +@code { + + [Parameter] + public bool ReadOnly { get; set; } + + protected override void OnInitialized() + { + WatchDataLoaderVM(BindingContext.WalletList); + + base.OnInitialized(); + } + + private void OpenDialog() + { + NavigationManager.NavigateTo("/start"); + // var options = new DialogOptions { CloseOnEscapeKey = true }; + // DialogService.Show("Add Wallet", options); + } +} diff --git a/src/aoWebWallet/ViewModels/MainViewModel.cs b/src/aoWebWallet/ViewModels/MainViewModel.cs index b4d238c..cf28bd6 100644 --- a/src/aoWebWallet/ViewModels/MainViewModel.cs +++ b/src/aoWebWallet/ViewModels/MainViewModel.cs @@ -42,7 +42,9 @@ public partial class MainViewModel : ObservableRecipient [ObservableProperty] private UserSettings userSettings = new(); - + [ObservableProperty] + private string? activeWalletAddress; + public Wallet? ActiveWallet { get; set; } public DataLoaderViewModel LastTransactionId { get; set; } = new(); public DataLoaderViewModel> WalletList { get; set; } = new(); public DataLoaderViewModel>> ProcessesDataList { get; set; } = new(); diff --git a/src/aoWebWallet/ViewModels/WalletDetailViewModel.cs b/src/aoWebWallet/ViewModels/WalletDetailViewModel.cs index 6dea6da..a6afdaf 100644 --- a/src/aoWebWallet/ViewModels/WalletDetailViewModel.cs +++ b/src/aoWebWallet/ViewModels/WalletDetailViewModel.cs @@ -49,7 +49,7 @@ public partial class WalletDetailViewModel : ObservableObject [ObservableProperty] public bool? hasArConnectExtension; - + public WalletDetailsViewModel? SelectedWallet { get; set; } @@ -190,6 +190,8 @@ private async Task SelectWallet(string? address) var current = all.Where(x => x.Address == address).FirstOrDefault(); if (current != null) { + mainViewModel.ActiveWallet = current; + mainViewModel.ActiveWalletAddress = address; SelectedWallet = new WalletDetailsViewModel(current); } else From ba3fbb85564d5701f97bc8241955021f2c04c4d0 Mon Sep 17 00:00:00 2001 From: Michiel Post Date: Wed, 19 Jun 2024 16:35:42 +0200 Subject: [PATCH 4/9] Show name and logo for MemeFrame --- src/aoWebWallet/Pages/MemeFrames.razor | 56 +++++++++++++------ src/aoWebWallet/aoWebWallet.csproj | 2 +- src/aoww.ProcesModels/MemeFrameProcess.cs | 18 +++++- .../Metadata/ActionMetadata.cs | 4 +- .../Metadata/ProcessMetadata.cs | 13 ----- src/aoww.ProcesModels/Process.cs | 22 ++++++++ .../aoww.ProcesModels.csproj | 4 ++ 7 files changed, 86 insertions(+), 33 deletions(-) delete mode 100644 src/aoww.ProcesModels/Metadata/ProcessMetadata.cs diff --git a/src/aoWebWallet/Pages/MemeFrames.razor b/src/aoWebWallet/Pages/MemeFrames.razor index da1c2c2..72af68f 100644 --- a/src/aoWebWallet/Pages/MemeFrames.razor +++ b/src/aoWebWallet/Pages/MemeFrames.razor @@ -1,12 +1,14 @@ @page "/meme-frames" @using aoWebWallet.Models @using aoww.ProcesModels +@using aoww.ProcesModels.Metadata @inherits MvvmComponentBase @inject IDialogService DialogService @inject ISnackbar Snackbar @inject NavigationManager NavigationManager @inject StorageService StorageService @inject TransactionService TransactionService +@inject GatewayUrlHelper UrlHelper @Program.PageTitlePostFix @@ -21,32 +23,37 @@ @foreach (var memeProcess in memeList) { - var readActions = memeProcess.GetActionMetadata().Where(x => x.ActionType == aoww.ProcesModels.Metadata.ActionType.DryRun).ToList(); - var messageActions = memeProcess.GetActionMetadata().Where(x => x.ActionType == aoww.ProcesModels.Metadata.ActionType.Message).ToList(); + var readActions = memeProcess.GetDryRunActions(); + var messageActions = memeProcess.GetMessageActions(); - I + @if (!string.IsNullOrEmpty(memeProcess.Logo)) + { + + } + else + { + @memeProcess.ProcessId + } Id: @memeProcess.ProcessId - Name: MEME - Creator: Andy Tudhope - Mint cap: 1,000,000 CRED + Name: @memeProcess.Name - + @* 25% - - + *@ + @* Theme: The zeroth memecoin minted on ao: winner of hackathon prizes, poet of iframes, informer of votes, verifier of processes, pilgrim of the hyper parallel spaces between, believer in dreams, drafter of the dankest memes. - + *@ @if (readActions.Any()) @@ -55,7 +62,7 @@ @foreach (var action in readActions) { - @action.Name + @action.Name } @@ -101,20 +108,37 @@ if (firstRender) { memeList = await StorageService.GetMemeFrames(); + + foreach(var meme in memeList) + { + var initActions = meme.GetAutoRunActions(); + + foreach(var initAction in initActions) + { + DryRun(initAction); + } + } + StateHasChanged(); } await base.OnAfterRenderAsync(firstRender); } - private async Task DryRun(AoAction aoAction) + private async Task DryRun(ActionMetadata actionMetadata) { - if (BindingContext.ActiveWalletAddress == null) - return; + AoAction aoAction = actionMetadata.AoAction; - var testWallet = new Wallet() { Address = BindingContext.ActiveWalletAddress }; + var senderAddress = BindingContext.ActiveWalletAddress; + if (senderAddress == null) + senderAddress = aoAction.Target?.Value ?? string.Empty; + + var testWallet = new Wallet() { Address = senderAddress }; var result = await TransactionService.DryRunAction(testWallet, aoAction); - Console.WriteLine(result?.Messages.FirstOrDefault()?.Data); + + actionMetadata?.ProcessResult?.Invoke(result); + + StateHasChanged(); } private void GoToSend(AoAction aoAction) diff --git a/src/aoWebWallet/aoWebWallet.csproj b/src/aoWebWallet/aoWebWallet.csproj index 24dc484..9679102 100644 --- a/src/aoWebWallet/aoWebWallet.csproj +++ b/src/aoWebWallet/aoWebWallet.csproj @@ -12,7 +12,7 @@ - + diff --git a/src/aoww.ProcesModels/MemeFrameProcess.cs b/src/aoww.ProcesModels/MemeFrameProcess.cs index bda8574..17fbc46 100644 --- a/src/aoww.ProcesModels/MemeFrameProcess.cs +++ b/src/aoww.ProcesModels/MemeFrameProcess.cs @@ -1,5 +1,7 @@ using aoww.ProcesModels.Action; using aoww.ProcesModels.Metadata; +using ArweaveAO.Extensions; +using ArweaveAO.Responses; using System; using System.Collections.Generic; using System.Linq; @@ -12,7 +14,8 @@ public class MemeFrameProcess : Process { public string? MintTokenId { get; set; } - public Dictionary? InfoResult { get; set; } + public string? Name { get; set; } + public string? Logo { get; set; } public MemeFrameProcess(string processId) : base(processId) { } @@ -25,7 +28,8 @@ public override List GetActionMetadata() Name = "Info", AutoRun = true, ActionType = ActionType.DryRun, - AoAction = CreateAoActionGetInfo() + AoAction = CreateAoActionGetInfo(), + ProcessResult = ProcessInfoResult }, new ActionMetadata { @@ -82,6 +86,16 @@ public override List GetActionMetadata() return actions; } + private void ProcessInfoResult(MessageResult? result) + { + if (result == null) + return; + + //Get name and logo + this.Name = result.GetFirstTagValue("Name"); + this.Logo = result.GetFirstTagValue("Logo"); + } + private AoAction CreateAoActionStake() { return new AoAction diff --git a/src/aoww.ProcesModels/Metadata/ActionMetadata.cs b/src/aoww.ProcesModels/Metadata/ActionMetadata.cs index 56271f6..1ac1f53 100644 --- a/src/aoww.ProcesModels/Metadata/ActionMetadata.cs +++ b/src/aoww.ProcesModels/Metadata/ActionMetadata.cs @@ -1,4 +1,5 @@ using aoww.ProcesModels.Action; +using ArweaveAO.Responses; using System; using System.Collections.Generic; using System.Linq; @@ -16,7 +17,8 @@ public class ActionMetadata public required AoAction AoAction { get; set; } - public Action? IsEnabled { get; set; } + public Action? ProcessResult { get; set; } + public Func? IsEnabled { get; set; } public string? LastResult { get; set; } diff --git a/src/aoww.ProcesModels/Metadata/ProcessMetadata.cs b/src/aoww.ProcesModels/Metadata/ProcessMetadata.cs deleted file mode 100644 index ed69b28..0000000 --- a/src/aoww.ProcesModels/Metadata/ProcessMetadata.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace aoww.ProcesModels.Metadata -{ - public class ProcessMetadata - { - - } -} diff --git a/src/aoww.ProcesModels/Process.cs b/src/aoww.ProcesModels/Process.cs index 4bc24f9..8085096 100644 --- a/src/aoww.ProcesModels/Process.cs +++ b/src/aoww.ProcesModels/Process.cs @@ -10,5 +10,27 @@ public abstract class Process : IProcessMetadata public Process(string processId) => ProcessId = processId; public abstract List GetActionMetadata(); + + public IEnumerable GetDryRunActions() + { + var all = GetActionMetadata(); + + return all.Where(x => x.ActionType == ActionType.DryRun); + } + + public IEnumerable GetMessageActions() + { + var all = GetActionMetadata(); + + return all.Where(x => x.ActionType == ActionType.Message); + } + + public IEnumerable GetAutoRunActions() + { + var all = GetDryRunActions(); + + return all.Where(x => x.AutoRun); + } + } } diff --git a/src/aoww.ProcesModels/aoww.ProcesModels.csproj b/src/aoww.ProcesModels/aoww.ProcesModels.csproj index 4d24086..19ed23c 100644 --- a/src/aoww.ProcesModels/aoww.ProcesModels.csproj +++ b/src/aoww.ProcesModels/aoww.ProcesModels.csproj @@ -7,4 +7,8 @@ nullable + + + + From 116ce83ef93ccf3920332b22252f1cf3b47fa1c8 Mon Sep 17 00:00:00 2001 From: Michiel Post Date: Wed, 19 Jun 2024 17:32:03 +0200 Subject: [PATCH 5/9] Show description and current memeframe --- src/aoWebWallet/Constants.cs | 1 + src/aoWebWallet/Pages/MemeFrames.razor | 43 +++++--- src/aoWebWallet/Services/StorageService.cs | 18 ++-- .../ViewModels/WalletDetailViewModel.cs | 2 +- src/aoww.ProcesModels/MemeFrameProcess.cs | 100 ++++++++++++++---- .../Metadata/ActionMetadata.cs | 1 + src/aoww.ProcesModels/Process.cs | 12 +-- 7 files changed, 128 insertions(+), 49 deletions(-) diff --git a/src/aoWebWallet/Constants.cs b/src/aoWebWallet/Constants.cs index fc3ccc1..21153d5 100644 --- a/src/aoWebWallet/Constants.cs +++ b/src/aoWebWallet/Constants.cs @@ -3,5 +3,6 @@ public static class Constants { public static string AoTokenId => "m3PaWzK4PTG9lAaqYQPaPdOcXdO8hYqi5Fe9NWqXd0w"; + public static string CredTokenId => "Sa0iBLPNyJQrwpTTG-tWLQU-1QeUAJA73DdxGGiKoJc"; } } diff --git a/src/aoWebWallet/Pages/MemeFrames.razor b/src/aoWebWallet/Pages/MemeFrames.razor index 72af68f..41f47a8 100644 --- a/src/aoWebWallet/Pages/MemeFrames.razor +++ b/src/aoWebWallet/Pages/MemeFrames.razor @@ -23,8 +23,8 @@ @foreach (var memeProcess in memeList) { - var readActions = memeProcess.GetDryRunActions(); - var messageActions = memeProcess.GetMessageActions(); + var readActions = memeProcess.GetVisibleDryRunActions(); + var messageActions = memeProcess.GetVisibleMessageActions(); @@ -45,15 +45,15 @@
- @* - - 25% - - *@ - @* - Theme: The zeroth memecoin minted on ao: winner of hackathon prizes, poet of iframes, informer of votes, verifier of processes, pilgrim of the hyper parallel spaces between, believer in dreams, drafter of the dankest memes. + @* + + 25% + + *@ + + @memeProcess.Description - *@ + @* *@ @if (readActions.Any()) @@ -64,7 +64,7 @@ { @action.Name } - + } @@ -81,13 +81,24 @@ } - + @if (memeProcess.FrameId != null) + { + + + View Current MemeFrame + + } + } - +
@@ -109,11 +120,11 @@ { memeList = await StorageService.GetMemeFrames(); - foreach(var meme in memeList) + foreach (var meme in memeList) { var initActions = meme.GetAutoRunActions(); - foreach(var initAction in initActions) + foreach (var initAction in initActions) { DryRun(initAction); } @@ -138,6 +149,8 @@ actionMetadata?.ProcessResult?.Invoke(result); + await StorageService.SaveMemeFrames(memeList); + StateHasChanged(); } diff --git a/src/aoWebWallet/Services/StorageService.cs b/src/aoWebWallet/Services/StorageService.cs index 6ebeef7..bf74475 100644 --- a/src/aoWebWallet/Services/StorageService.cs +++ b/src/aoWebWallet/Services/StorageService.cs @@ -23,20 +23,20 @@ public async ValueTask> GetMemeFrames() var result = await localStorage.GetItemAsync>(MEMFRAME_LIST_KEY); result = result ?? new(); - AddSystemMemeFrames(result,"OT9qTE2467gcozb2g8R6D6N3nQS94ENcaAIJfUzHCww"); //TRUNK - AddSystemMemeFrames(result,"2gM9n9QO6JG1_bZhCWr3fuEKJtzRgx1xvYUB92nVFAs"); //AORTA - AddSystemMemeFrames(result,"-a4T7XLMDGTcu8_preKXdUT6__4sJkMhYLEJZkXUYd0"); //MEME - AddSystemMemeFrames(result,"rik3eCayInKVNzSMdoxeSEfpxNd5U7tx1H8NAveg4o8"); //FINCH-MEME + AddSystemMemeFrames(result,"OT9qTE2467gcozb2g8R6D6N3nQS94ENcaAIJfUzHCww", Constants.CredTokenId); //TRUNK + AddSystemMemeFrames(result,"2gM9n9QO6JG1_bZhCWr3fuEKJtzRgx1xvYUB92nVFAs", Constants.CredTokenId); //AORTA + AddSystemMemeFrames(result,"-a4T7XLMDGTcu8_preKXdUT6__4sJkMhYLEJZkXUYd0", Constants.CredTokenId); //MEME + AddSystemMemeFrames(result,"rik3eCayInKVNzSMdoxeSEfpxNd5U7tx1H8NAveg4o8", Constants.CredTokenId); //FINCH-MEME return result; } - private static void AddSystemMemeFrames(List list, string processId) + private static void AddSystemMemeFrames(List list, string processId, string mintTokenId) { var existing = list.Where(x => x.ProcessId == processId).FirstOrDefault(); if (existing == null) - list.Add(new MemeFrameProcess(processId)); + list.Add(new MemeFrameProcess(processId) { MintTokenId = mintTokenId }); } public ValueTask SaveMemeFrames(List list) @@ -68,10 +68,10 @@ public static void AddSystemTokens(List result) Ticker = "AO" }); //AO - AddSystemToken(result, "Sa0iBLPNyJQrwpTTG-tWLQU-1QeUAJA73DdxGGiKoJc", + AddSystemToken(result, Constants.CredTokenId, new TokenData { - TokenId = "Sa0iBLPNyJQrwpTTG-tWLQU-1QeUAJA73DdxGGiKoJc", + TokenId = Constants.CredTokenId, Denomination = 3, Logo = "eIOOJiqtJucxvB4k8a-sEKcKpKTh9qQgOV3Au7jlGYc", Name = "AOCRED", @@ -114,7 +114,7 @@ public static void AddSystemTokens(List result) { TokenId = "BUhZLMwQ6yZHguLtJYA5lLUa9LQzLXMXRfaq9FVcPJc", Denomination = 12, - Logo = "nvx7DgTR8ws_k6VNCSe8vhwbZLx5jNbfNLJS0IKTTHA", + Logo = "quMiswyIjELM0FZtjVSiUtg9_-pvQ8K25yfxrp1TgnQ", Name = "0rbit Points", Ticker = "0RBT" }); //0rbit diff --git a/src/aoWebWallet/ViewModels/WalletDetailViewModel.cs b/src/aoWebWallet/ViewModels/WalletDetailViewModel.cs index ea379db..e8c8292 100644 --- a/src/aoWebWallet/ViewModels/WalletDetailViewModel.cs +++ b/src/aoWebWallet/ViewModels/WalletDetailViewModel.cs @@ -84,7 +84,7 @@ public async Task Initialize(string address) { VisibleTokenList = new(); VisibleTokenList.Add(Constants.AoTokenId); //AO - VisibleTokenList.Add("Sa0iBLPNyJQrwpTTG-tWLQU-1QeUAJA73DdxGGiKoJc"); //TESTNET-CRED + VisibleTokenList.Add(Constants.CredTokenId); //TESTNET-CRED ResetTokenTransferlist(); diff --git a/src/aoww.ProcesModels/MemeFrameProcess.cs b/src/aoww.ProcesModels/MemeFrameProcess.cs index 17fbc46..16e91b6 100644 --- a/src/aoww.ProcesModels/MemeFrameProcess.cs +++ b/src/aoww.ProcesModels/MemeFrameProcess.cs @@ -10,12 +10,17 @@ namespace aoww.ProcesModels { + /// + /// https://github.com/permaweb/memeframes + /// public class MemeFrameProcess : Process { public string? MintTokenId { get; set; } public string? Name { get; set; } public string? Logo { get; set; } + public string? Description { get; set; } + public string? FrameId { get; set; } public MemeFrameProcess(string processId) : base(processId) { } @@ -27,9 +32,19 @@ public override List GetActionMetadata() { Name = "Info", AutoRun = true, + IsHidden = true, ActionType = ActionType.DryRun, - AoAction = CreateAoActionGetInfo(), - ProcessResult = ProcessInfoResult + AoAction = CreateAoActionGetInfoBasic(), + ProcessResult = ProcessInfoBasicResult + }, + new ActionMetadata + { + Name = "Get Description", + AutoRun = true, + IsHidden = true, + ActionType = ActionType.DryRun, + AoAction = CreateAoActionGetInfoDescription(), + ProcessResult = ProcessInfoDescriptionResult }, new ActionMetadata { @@ -37,13 +52,6 @@ public override List GetActionMetadata() ActionType = ActionType.DryRun, AoAction = CreateAoActionViewStakers() }, - //new ActionMetadata - //{ - // Name = "Get Frame", - // ActionType = ActionType.DryRun, - // AoAction = TokenProcess.CreateForTokenTransaction(this.ProcessId) - //}, - new ActionMetadata { Name = "Stake", @@ -61,14 +69,25 @@ public override List GetActionMetadata() Name = "Vote nay", ActionType = ActionType.Message, AoAction = CreateAoActionVote("nay") + }, + new ActionMetadata + { + Name = "Get Votes", + ActionType = ActionType.DryRun, + AoAction = CreateAoActionGetVotes() + }, + new ActionMetadata + { + Name = "Get Frame", + AutoRun = true, + IsHidden = true, + ActionType = ActionType.DryRun, + AoAction = CreateAoActionGetFrame(), + ProcessResult = (x) => + { + this.FrameId = x?.Messages?.FirstOrDefault()?.Data; + } } - , - //new ActionMetadata - //{ - // Name = "Get Votes", - // ActionType = ActionType.DryRun, - // AoAction = TokenProcess.CreateForTokenTransaction(this.ProcessId) - //} }; if (MintTokenId != null) @@ -86,7 +105,7 @@ public override List GetActionMetadata() return actions; } - private void ProcessInfoResult(MessageResult? result) + private void ProcessInfoBasicResult(MessageResult? result) { if (result == null) return; @@ -96,6 +115,15 @@ private void ProcessInfoResult(MessageResult? result) this.Logo = result.GetFirstTagValue("Logo"); } + private void ProcessInfoDescriptionResult(MessageResult? result) + { + if (result == null) + return; + + //Get name and logo + this.Description = result.Messages.FirstOrDefault()?.Data; + } + private AoAction CreateAoActionStake() { return new AoAction @@ -124,7 +152,7 @@ private AoAction CreateAoActionVote(string vote) }; } - private AoAction CreateAoActionGetInfo() + private AoAction CreateAoActionGetInfoBasic() { return new AoAction { @@ -136,6 +164,18 @@ private AoAction CreateAoActionGetInfo() }; } + private AoAction CreateAoActionGetInfoDescription() + { + return new AoAction + { + Params = new List + { + new ActionParam { Key= "Target", ParamType = ActionParamType.Target, Value= this.ProcessId }, + new ActionParam { Key= "Action", ParamType = ActionParamType.Filled, Value= "Get-Info" }, + } + }; + } + private AoAction CreateAoActionViewStakers() { return new AoAction @@ -147,5 +187,29 @@ private AoAction CreateAoActionViewStakers() } }; } + + private AoAction CreateAoActionGetVotes() + { + return new AoAction + { + Params = new List + { + new ActionParam { Key= "Target", ParamType = ActionParamType.Target, Value= this.ProcessId }, + new ActionParam { Key= "Action", ParamType = ActionParamType.Filled, Value= "Votes" }, + } + }; + } + + private AoAction CreateAoActionGetFrame() + { + return new AoAction + { + Params = new List + { + new ActionParam { Key= "Target", ParamType = ActionParamType.Target, Value= this.ProcessId }, + new ActionParam { Key= "Action", ParamType = ActionParamType.Filled, Value= "Get-Frame" }, + } + }; + } } } diff --git a/src/aoww.ProcesModels/Metadata/ActionMetadata.cs b/src/aoww.ProcesModels/Metadata/ActionMetadata.cs index 1ac1f53..535d7b7 100644 --- a/src/aoww.ProcesModels/Metadata/ActionMetadata.cs +++ b/src/aoww.ProcesModels/Metadata/ActionMetadata.cs @@ -24,6 +24,7 @@ public class ActionMetadata //Run on initialization public bool AutoRun { get; set; } + public bool IsHidden { get; set; } } diff --git a/src/aoww.ProcesModels/Process.cs b/src/aoww.ProcesModels/Process.cs index 8085096..b289b40 100644 --- a/src/aoww.ProcesModels/Process.cs +++ b/src/aoww.ProcesModels/Process.cs @@ -11,25 +11,25 @@ public abstract class Process : IProcessMetadata public abstract List GetActionMetadata(); - public IEnumerable GetDryRunActions() + public IEnumerable GetVisibleDryRunActions() { var all = GetActionMetadata(); - return all.Where(x => x.ActionType == ActionType.DryRun); + return all.Where(x => !x.IsHidden).Where(x => x.ActionType == ActionType.DryRun); } - public IEnumerable GetMessageActions() + public IEnumerable GetVisibleMessageActions() { var all = GetActionMetadata(); - return all.Where(x => x.ActionType == ActionType.Message); + return all.Where(x => !x.IsHidden).Where(x => x.ActionType == ActionType.Message); } public IEnumerable GetAutoRunActions() { - var all = GetDryRunActions(); + var all = GetActionMetadata(); - return all.Where(x => x.AutoRun); + return all.Where(x => x.ActionType == ActionType.DryRun).Where(x => x.AutoRun); } } From 847e61b359165916809d840d40127fc73f52d05a Mon Sep 17 00:00:00 2001 From: Nuno Lopes Date: Thu, 20 Jun 2024 18:05:36 +0100 Subject: [PATCH 6/9] improve readability --- src/aoWebWallet/Pages/MemeFrames.razor | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/aoWebWallet/Pages/MemeFrames.razor b/src/aoWebWallet/Pages/MemeFrames.razor index 41f47a8..93c9fd2 100644 --- a/src/aoWebWallet/Pages/MemeFrames.razor +++ b/src/aoWebWallet/Pages/MemeFrames.razor @@ -26,7 +26,7 @@ var readActions = memeProcess.GetVisibleDryRunActions(); var messageActions = memeProcess.GetVisibleMessageActions(); - + From 6728e8c899f6a00d9aa249c0d9e56984d5b7ace2 Mon Sep 17 00:00:00 2001 From: Michiel Post Date: Fri, 21 Jun 2024 17:14:15 +0200 Subject: [PATCH 7/9] MemeFrame improvements, using TokenProcess and StakingProcess --- src/aoWebWallet/Pages/MemeFrames.razor | 46 +++++-- src/aoww.ProcesModels/MemeFrameProcess.cs | 129 ++++++------------ .../Metadata/ActionMetadata.cs | 1 + src/aoww.ProcesModels/StakingProcess.cs | 101 ++++++++++++++ src/aoww.ProcesModels/TokenProcess.cs | 112 +++++++++++++++ 5 files changed, 285 insertions(+), 104 deletions(-) create mode 100644 src/aoww.ProcesModels/StakingProcess.cs diff --git a/src/aoWebWallet/Pages/MemeFrames.razor b/src/aoWebWallet/Pages/MemeFrames.razor index 93c9fd2..e897e0c 100644 --- a/src/aoWebWallet/Pages/MemeFrames.razor +++ b/src/aoWebWallet/Pages/MemeFrames.razor @@ -15,7 +15,7 @@ - Meme Frames + @@ -30,9 +30,9 @@ - @if (!string.IsNullOrEmpty(memeProcess.Logo)) + @if (!string.IsNullOrEmpty(memeProcess.TokenProcess.Logo)) { - + } else { @@ -41,15 +41,16 @@ Id: @memeProcess.ProcessId - Name: @memeProcess.Name + Name: @memeProcess.TokenProcess.Name - @* - - 25% - - *@ + @if (memeProcess.TokenProcess.balance.HasValue) + { + + Balance: @memeProcess.TokenProcess.balance + + } @memeProcess.Description @@ -59,12 +60,19 @@ @if (readActions.Any()) { - - @foreach (var action in readActions) - { - @action.Name - } - + @if (BindingContext.ActiveWalletAddress != null) + { + + @foreach (var action in readActions) + { + @action.Name + } + + } + else + { + Please select a wallet to enable more actions. + } } @@ -104,6 +112,12 @@ @code { + private List _items = new List + { + new BreadcrumbItem("Home", href: "/"), + new BreadcrumbItem("Meme Frames", href: null, disabled: true) + }; + private List memeList = new(); protected override void OnInitialized() @@ -111,6 +125,8 @@ //WatchCollection(dataService.TokenList); //WatchObject(dataService.TokenDataLoader); + WatchProp(nameof(BindingContext.ActiveWalletAddress)); + base.OnInitialized(); } diff --git a/src/aoww.ProcesModels/MemeFrameProcess.cs b/src/aoww.ProcesModels/MemeFrameProcess.cs index 16e91b6..d227d27 100644 --- a/src/aoww.ProcesModels/MemeFrameProcess.cs +++ b/src/aoww.ProcesModels/MemeFrameProcess.cs @@ -17,47 +17,49 @@ public class MemeFrameProcess : Process { public string? MintTokenId { get; set; } - public string? Name { get; set; } - public string? Logo { get; set; } public string? Description { get; set; } public string? FrameId { get; set; } - public MemeFrameProcess(string processId) : base(processId) { } + public TokenProcess TokenProcess { get; set; } + public StakingProcess StakingProcess { get; set; } + + public MemeFrameProcess(string processId) : base(processId) { + + TokenProcess = new TokenProcess(processId); + StakingProcess = new StakingProcess(processId); + } public override List GetActionMetadata() { - var actions = new List() + var actions = new List(); + + if (MintTokenId != null) + { + actions.Add( + new ActionMetadata + { + Name = "Mint", + ActionType = ActionType.Message, + AoAction = TokenProcess.CreateForTokenTransaction(this.ProcessId, this.MintTokenId) + } + ); + } + + actions.AddRange(TokenProcess.GetActionMetadata()); + actions.AddRange(StakingProcess.GetActionMetadata()); + + actions.AddRange(new List() { - new ActionMetadata - { - Name = "Info", - AutoRun = true, - IsHidden = true, - ActionType = ActionType.DryRun, - AoAction = CreateAoActionGetInfoBasic(), - ProcessResult = ProcessInfoBasicResult - }, new ActionMetadata { Name = "Get Description", - AutoRun = true, + AutoRun = Description == null, IsHidden = true, ActionType = ActionType.DryRun, AoAction = CreateAoActionGetInfoDescription(), ProcessResult = ProcessInfoDescriptionResult }, - new ActionMetadata - { - Name = "View Stakers", - ActionType = ActionType.DryRun, - AoAction = CreateAoActionViewStakers() - }, - new ActionMetadata - { - Name = "Stake", - ActionType = ActionType.Message, - AoAction = CreateAoActionStake() - }, + new ActionMetadata { Name = "Vote yay", @@ -70,12 +72,12 @@ public override List GetActionMetadata() ActionType = ActionType.Message, AoAction = CreateAoActionVote("nay") }, - new ActionMetadata - { - Name = "Get Votes", - ActionType = ActionType.DryRun, - AoAction = CreateAoActionGetVotes() - }, + //new ActionMetadata + //{ + // Name = "Get Votes", + // ActionType = ActionType.DryRun, + // AoAction = CreateAoActionGetVotes() + //}, new ActionMetadata { Name = "Get Frame", @@ -88,32 +90,14 @@ public override List GetActionMetadata() this.FrameId = x?.Messages?.FirstOrDefault()?.Data; } } - }; + }); - if (MintTokenId != null) - { - actions.Add( - new ActionMetadata - { - Name = "Mint", - ActionType = ActionType.Message, - AoAction = TokenProcess.CreateForTokenTransaction(this.ProcessId, this.MintTokenId) - } - ); - } + return actions; } - private void ProcessInfoBasicResult(MessageResult? result) - { - if (result == null) - return; - - //Get name and logo - this.Name = result.GetFirstTagValue("Name"); - this.Logo = result.GetFirstTagValue("Logo"); - } + private void ProcessInfoDescriptionResult(MessageResult? result) { @@ -124,19 +108,7 @@ private void ProcessInfoDescriptionResult(MessageResult? result) this.Description = result.Messages.FirstOrDefault()?.Data; } - private AoAction CreateAoActionStake() - { - return new AoAction - { - Params = new List - { - new ActionParam { Key= "Target", ParamType = ActionParamType.Target, Value= this.ProcessId }, - new ActionParam { Key= "Action", ParamType = ActionParamType.Filled, Value= "Stake" }, - new ActionParam { Key= "Quantity", ParamType = ActionParamType.Balance, Args = new List { this.ProcessId } }, - new ActionParam { Key= "UnstakeDelay", ParamType = ActionParamType.Integer }, - } - }; - } + private AoAction CreateAoActionVote(string vote) { @@ -152,17 +124,7 @@ private AoAction CreateAoActionVote(string vote) }; } - private AoAction CreateAoActionGetInfoBasic() - { - return new AoAction - { - Params = new List - { - new ActionParam { Key= "Target", ParamType = ActionParamType.Target, Value= this.ProcessId }, - new ActionParam { Key= "Action", ParamType = ActionParamType.Filled, Value= "Info" }, - } - }; - } + private AoAction CreateAoActionGetInfoDescription() { @@ -175,18 +137,7 @@ private AoAction CreateAoActionGetInfoDescription() } }; } - - private AoAction CreateAoActionViewStakers() - { - return new AoAction - { - Params = new List - { - new ActionParam { Key= "Target", ParamType = ActionParamType.Target, Value= this.ProcessId }, - new ActionParam { Key= "Action", ParamType = ActionParamType.Filled, Value= "Stakers" }, - } - }; - } + private AoAction CreateAoActionGetVotes() { diff --git a/src/aoww.ProcesModels/Metadata/ActionMetadata.cs b/src/aoww.ProcesModels/Metadata/ActionMetadata.cs index 535d7b7..3776f5d 100644 --- a/src/aoww.ProcesModels/Metadata/ActionMetadata.cs +++ b/src/aoww.ProcesModels/Metadata/ActionMetadata.cs @@ -25,6 +25,7 @@ public class ActionMetadata //Run on initialization public bool AutoRun { get; set; } public bool IsHidden { get; set; } + public bool IsOwnerOnly { get; set; } } diff --git a/src/aoww.ProcesModels/StakingProcess.cs b/src/aoww.ProcesModels/StakingProcess.cs new file mode 100644 index 0000000..486012a --- /dev/null +++ b/src/aoww.ProcesModels/StakingProcess.cs @@ -0,0 +1,101 @@ +using aoww.ProcesModels.Action; +using aoww.ProcesModels.Metadata; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace aoww.ProcesModels +{ + public class StakingProcess : Process + { + public StakingProcess(string processId) : base(processId) + { + } + + public override List GetActionMetadata() + { + return new List() + { + new ActionMetadata + { + Name = "View Stakers", + ActionType = ActionType.DryRun, + AoAction = CreateAoActionViewStakers() + }, + new ActionMetadata + { + Name = "Stake", + ActionType = ActionType.Message, + AoAction = CreateAoActionStake() + }, + new ActionMetadata + { + Name = "Unstake", + ActionType = ActionType.Message, + AoAction = CreateAoActionUnStake() + }, + // new ActionMetadata + //{ + // Name = "Finalize", + // ActionType = ActionType.Message, + // AoAction = CreateAoActionFinalize() + //}, + }; + } + + private AoAction CreateAoActionViewStakers() + { + return new AoAction + { + Params = new List + { + new ActionParam { Key= "Target", ParamType = ActionParamType.Target, Value= this.ProcessId }, + new ActionParam { Key= "Action", ParamType = ActionParamType.Filled, Value= "Stakers" }, + } + }; + } + + private AoAction CreateAoActionStake() + { + return new AoAction + { + Params = new List + { + new ActionParam { Key= "Target", ParamType = ActionParamType.Target, Value= this.ProcessId }, + new ActionParam { Key= "Action", ParamType = ActionParamType.Filled, Value= "Stake" }, + new ActionParam { Key= "Quantity", ParamType = ActionParamType.Balance, Args = new List { this.ProcessId } }, + new ActionParam { Key= "UnstakeDelay", ParamType = ActionParamType.Integer }, + } + }; + } + + private AoAction CreateAoActionUnStake() + { + return new AoAction + { + Params = new List + { + new ActionParam { Key= "Target", ParamType = ActionParamType.Target, Value= this.ProcessId }, + new ActionParam { Key= "Action", ParamType = ActionParamType.Filled, Value= "Unstake" }, + new ActionParam { Key= "Quantity", ParamType = ActionParamType.Balance, Args = new List { this.ProcessId } }, + } + }; + } + + private AoAction CreateAoActionFinalize() + { + return new AoAction + { + Params = new List + { + new ActionParam { Key= "Target", ParamType = ActionParamType.Target, Value= this.ProcessId }, + new ActionParam { Key= "Action", ParamType = ActionParamType.Filled, Value= "Finalize" }, + new ActionParam { Key= "Quantity", ParamType = ActionParamType.Balance, Args = new List { this.ProcessId } }, + } + }; + } + + } +} diff --git a/src/aoww.ProcesModels/TokenProcess.cs b/src/aoww.ProcesModels/TokenProcess.cs index 550bc43..6fe5696 100644 --- a/src/aoww.ProcesModels/TokenProcess.cs +++ b/src/aoww.ProcesModels/TokenProcess.cs @@ -1,5 +1,8 @@ using aoww.ProcesModels.Action; using aoww.ProcesModels.Metadata; +using ArweaveAO.Extensions; +using ArweaveAO.Models.Token; +using ArweaveAO.Responses; using System; using System.Collections.Generic; using System.Linq; @@ -10,6 +13,14 @@ namespace aoww.ProcesModels { public class TokenProcess : Process { + public string? Name { get; set; } + public string? Ticker { get; set; } + public string? Logo { get; set; } + public int? Denomination { get; set; } + + //Temp properties + public long? balance; + public TokenProcess(string processId) : base(processId) { } @@ -18,11 +29,43 @@ public override List GetActionMetadata() { return new List() { + new ActionMetadata + { + Name = "Info", + AutoRun = Name == null, + IsHidden = true, + ActionType = ActionType.DryRun, + AoAction = CreateAoActionGetInfoBasic(), + ProcessResult = ProcessInfoBasicResult + }, + new ActionMetadata + { + Name = "Balance", + ActionType = ActionType.DryRun, + AoAction = CreateAoActionBalance(), + ProcessResult = ProcessBalanceResult + }, + new ActionMetadata + { + Name = "Balances", + IsHidden = true, + ActionType = ActionType.DryRun, + AoAction = CreateAoActionBalances(), + }, new ActionMetadata { Name = "Send", + IsHidden = !balance.HasValue || balance <= 0, ActionType = ActionType.Message, AoAction = TokenProcess.CreateForTokenTransaction(this.ProcessId) + }, + new ActionMetadata + { + Name = "Mint", + IsHidden= true, + IsOwnerOnly = true, + ActionType = ActionType.Message, + AoAction = CreateAoActionMint() } }; } @@ -58,5 +101,74 @@ public static AoAction CreateForTokenTransaction(string tokenId) }; } + + private AoAction CreateAoActionGetInfoBasic() + { + return new AoAction + { + Params = new List + { + new ActionParam { Key= "Target", ParamType = ActionParamType.Target, Value= this.ProcessId }, + new ActionParam { Key= "Action", ParamType = ActionParamType.Filled, Value= "Info" }, + } + }; + } + + private AoAction CreateAoActionBalance() + { + return new AoAction + { + Params = new List + { + new ActionParam { Key= "Target", ParamType = ActionParamType.Target, Value= this.ProcessId }, + new ActionParam { Key= "Action", ParamType = ActionParamType.Filled, Value= "Balance" }, + } + }; + } + + private AoAction CreateAoActionBalances() + { + return new AoAction + { + Params = new List + { + new ActionParam { Key= "Target", ParamType = ActionParamType.Target, Value= this.ProcessId }, + new ActionParam { Key= "Action", ParamType = ActionParamType.Filled, Value= "Balances" }, + } + }; + } + + private AoAction CreateAoActionMint() + { + return new AoAction + { + Params = new List + { + new ActionParam { Key= "Target", ParamType = ActionParamType.Target, Value= this.ProcessId }, + new ActionParam { Key= "Action", ParamType = ActionParamType.Filled, Value= "Mint" }, + new ActionParam { Key= "Quantity", ParamType = ActionParamType.Quantity, Args = new List { this.ProcessId } } + } + }; + } + + private void ProcessInfoBasicResult(MessageResult? result) + { + if (result == null) + return; + + //Get name and logo + this.Name = result.GetFirstTagValue("Name"); + this.Logo = result.GetFirstTagValue("Logo"); + } + + private void ProcessBalanceResult(MessageResult? result) + { + if (result == null) + return; + + string? balance = result.GetFirstTagValue("Balance"); + if (!string.IsNullOrWhiteSpace(balance) && long.TryParse(balance, out long balanceLong)) + this.balance = balanceLong; + } } } From 438ea4e7215d89171df6b09904a6c3f2d37f5244 Mon Sep 17 00:00:00 2001 From: Michiel Post Date: Sun, 23 Jun 2024 11:35:40 +0200 Subject: [PATCH 8/9] Show list of stakers --- src/aoWebWallet/Pages/MemeFrames.razor | 72 ++++++++++++++++++++++++-- 1 file changed, 69 insertions(+), 3 deletions(-) diff --git a/src/aoWebWallet/Pages/MemeFrames.razor b/src/aoWebWallet/Pages/MemeFrames.razor index e897e0c..35242ea 100644 --- a/src/aoWebWallet/Pages/MemeFrames.razor +++ b/src/aoWebWallet/Pages/MemeFrames.razor @@ -1,4 +1,6 @@ @page "/meme-frames" +@using System.Text.Json +@using System.Text.Json.Serialization @using aoWebWallet.Models @using aoww.ProcesModels @using aoww.ProcesModels.Metadata @@ -19,6 +21,43 @@ + + + + + + Address + Amount + Unstake At + + + + @{ + var orderedItems = stakers?.Items.OrderByDescending(kvp => int.Parse(kvp.Value.GetProperty("amount").GetString() ?? "0")).ToDictionary(kvp => kvp.Key, kvp => kvp.Value); + } + + @foreach (var row in orderedItems ?? new()) + { + int? unstakeValue = row.Value.TryGetProperty("unstake_at", out JsonElement prop) ? prop.GetInt32() : null; + string detailUrl = $"/wallet/{row.Key}"; + + + + @row.Key + + + @row.Value.GetProperty("amount").GetString() + @unstakeValue + + } + + + + Close + + + + @foreach (var memeProcess in memeList) @@ -119,6 +158,17 @@ }; private List memeList = new(); + private StakeResult? stakers = null; + + public bool _isOpen; + + public void ToggleOpen() + { + if (_isOpen) + _isOpen = false; + else + _isOpen = true; + } protected override void OnInitialized() { @@ -160,14 +210,25 @@ if (senderAddress == null) senderAddress = aoAction.Target?.Value ?? string.Empty; - var testWallet = new Wallet() { Address = senderAddress }; - var result = await TransactionService.DryRunAction(testWallet, aoAction); + var dryRunWallet = new Wallet() { Address = senderAddress }; + var result = await TransactionService.DryRunAction(dryRunWallet, aoAction); - actionMetadata?.ProcessResult?.Invoke(result); + actionMetadata.ProcessResult?.Invoke(result); await StorageService.SaveMemeFrames(memeList); StateHasChanged(); + + if (actionMetadata.Name == "View Stakers" && result?.Messages.FirstOrDefault()?.Data != null) + { + var data = result.Messages.First().Data; + + stakers = JsonSerializer.Deserialize(data!); + + _isOpen = true; + + StateHasChanged(); + } } private void GoToSend(AoAction aoAction) @@ -175,4 +236,9 @@ NavigationManager.NavigateTo($"/action?{aoAction.ToQueryString()}"); } + public class StakeResult + { + [JsonExtensionData] + public Dictionary Items { get; set; } = new Dictionary(); + } } From 15511a57195b73c7b209d48d7b53298f40fd5bfb Mon Sep 17 00:00:00 2001 From: Michiel Post Date: Sun, 23 Jun 2024 14:08:21 +0200 Subject: [PATCH 9/9] Added navigate back option after send action --- src/aoWebWallet/Pages/ActionPage.razor | 39 +++++++++++++++++++++----- src/aoWebWallet/Program.cs | 9 +++++- src/aoWebWallet/aoWebWallet.csproj | 1 + 3 files changed, 41 insertions(+), 8 deletions(-) diff --git a/src/aoWebWallet/Pages/ActionPage.razor b/src/aoWebWallet/Pages/ActionPage.razor index 718a8d6..56cdfc4 100644 --- a/src/aoWebWallet/Pages/ActionPage.razor +++ b/src/aoWebWallet/Pages/ActionPage.razor @@ -7,6 +7,8 @@ @inject TokenDataService dataService @inject TransactionService transactionService; @inject WalletDetailViewModel WalletDetailViewModel +@using Soenneker.Blazor.Utils.Navigation.Abstract +@inject INavigationUtil NavigationUtil @Program.PageTitlePostFix @@ -16,7 +18,7 @@ - @if(readOnly) + @if (readOnly) { Please review your transaction: } @@ -25,6 +27,10 @@ @if (!readOnly && !string.IsNullOrEmpty(BindingContext.ActiveWalletAddress)) { + if (NavigationUtil.CanNavigateBack) + { + Back + } Preview @validation } @@ -47,14 +53,26 @@ } @* - Learn More - *@ + Learn More + *@ } + if (NavigationUtil.CanNavigateBack) + { + Back + } Cancel Submit } + else if (transactionService.LastTransaction.DataLoader.LoadingState == LoadingState.None && string.IsNullOrEmpty(transactionService.LastTransaction.Data?.Id)) + { + if (NavigationUtil.CanNavigateBack) + { + Back + } + } + @if (transactionService.LastTransaction.DataLoader != null) { @@ -69,7 +87,14 @@ - Return to wallet + if (NavigationUtil.CanNavigateBack) + { + Back + } + else + { + Return to wallet + } @* View Transaction *@ } } @@ -80,7 +105,7 @@ @code { private string? validation; - + private bool readOnly = false; private bool started = false; @@ -144,7 +169,7 @@ return; var wallet = BindingContext.WalletList.Data.Where(x => x.Address == BindingContext.ActiveWallet?.Address).FirstOrDefault(); - if(wallet == null) + if (wallet == null) { if (BindingContext.ActiveWallet?.Address == BindingContext.ActiveWalletAddress) { @@ -162,6 +187,6 @@ await transactionService.SendAction(wallet, ownerWallet, AoAction); } - + } diff --git a/src/aoWebWallet/Program.cs b/src/aoWebWallet/Program.cs index b2bf742..759fddc 100644 --- a/src/aoWebWallet/Program.cs +++ b/src/aoWebWallet/Program.cs @@ -16,6 +16,7 @@ using aoWebWallet.Models; using ArweaveAO.Models; using MudExtensions.Services; +using Soenneker.Blazor.Utils.Navigation.Registrars; namespace aoWebWallet { @@ -72,7 +73,11 @@ public static async Task Main(string[] args) ConfigureServices(builder.Services, builder.HostEnvironment.BaseAddress); - await builder.Build().RunAsync(); + WebAssemblyHost host = builder.Build(); + + host.Services.WarmupNavigation(); + + await host.RunAsync(); } private static void ConfigureServices(IServiceCollection services, string baseAddress) @@ -122,6 +127,8 @@ private static void ConfigureServices(IServiceCollection services, string baseAd services.AddClipboard(); + services.AddNavigationUtil(); + //Options services.AddSingleton(new GraphqlConfig()); services.AddSingleton(new GatewayConfig()); diff --git a/src/aoWebWallet/aoWebWallet.csproj b/src/aoWebWallet/aoWebWallet.csproj index 9679102..5399e2d 100644 --- a/src/aoWebWallet/aoWebWallet.csproj +++ b/src/aoWebWallet/aoWebWallet.csproj @@ -23,6 +23,7 @@ +