Skip to content

Commit

Permalink
MemeFrame improvements, using TokenProcess and StakingProcess
Browse files Browse the repository at this point in the history
  • Loading branch information
michielpost committed Jun 21, 2024
1 parent 847e61b commit 6728e8c
Show file tree
Hide file tree
Showing 5 changed files with 285 additions and 104 deletions.
46 changes: 31 additions & 15 deletions src/aoWebWallet/Pages/MemeFrames.razor
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@


<MudContainer Class="mt-16 px-8" MaxWidth="MaxWidth.False">
<MudText Class="mb-4" Typo="Typo.h5">Meme Frames</MudText>
<MudBreadcrumbs Class="breadcrumbs-aoww" Items="_items"></MudBreadcrumbs>

<SelectActiveWalletComponent />

Expand All @@ -30,9 +30,9 @@
<MudCard>
<MudCardHeader>
<CardHeaderAvatar>
@if (!string.IsNullOrEmpty(memeProcess.Logo))
@if (!string.IsNullOrEmpty(memeProcess.TokenProcess.Logo))
{
<MudAvatar Class="mr-3" Image="@UrlHelper.GetArweaveUrl(memeProcess.Logo)" Size="Size.Large" />
<MudAvatar Class="mr-3" Image="@UrlHelper.GetArweaveUrl(memeProcess.TokenProcess.Logo)" Size="Size.Large" />
}
else
{
Expand All @@ -41,15 +41,16 @@
</CardHeaderAvatar>
<CardHeaderContent>
<MudText Typo="Typo.body1">Id: @memeProcess.ProcessId</MudText>
<MudText Typo="Typo.body1">Name: @memeProcess.Name</MudText>
<MudText Typo="Typo.body1">Name: @memeProcess.TokenProcess.Name</MudText>
</CardHeaderContent>
</MudCardHeader>
<MudCardContent Class="pb-0">
@* <MudProgressLinear Color="Color.Info" Size="Size.Large" Value="25" Class="mb-2">
<MudText Typo="Typo.subtitle1" Color="Color.Secondary">
<b>25%</b>
</MudText>
</MudProgressLinear> *@
@if (memeProcess.TokenProcess.balance.HasValue)
{
<MudText Typo="Typo.subtitle1" Color="Color.Secondary">
<b>Balance: @memeProcess.TokenProcess.balance</b>
</MudText>
}
<MudText Class="mb-2" Typo="Typo.body2">
@memeProcess.Description
</MudText>
Expand All @@ -59,12 +60,19 @@
@if (readActions.Any())
{
<MudCardActions>
<MudButtonGroup Color="Color.Primary" Variant="Variant.Filled">
@foreach (var action in readActions)
{
<MudButton OnClick="() => DryRun(action)">@action.Name</MudButton>
}
</MudButtonGroup>
@if (BindingContext.ActiveWalletAddress != null)
{
<MudButtonGroup Color="Color.Primary" Variant="Variant.Filled">
@foreach (var action in readActions)
{
<MudButton OnClick="() => DryRun(action)">@action.Name</MudButton>
}
</MudButtonGroup>
}
else
{
<MudText>Please select a wallet to enable more actions.</MudText>
}
</MudCardActions>
}

Expand Down Expand Up @@ -104,13 +112,21 @@

@code
{
private List<BreadcrumbItem> _items = new List<BreadcrumbItem>
{
new BreadcrumbItem("Home", href: "/"),
new BreadcrumbItem("Meme Frames", href: null, disabled: true)
};

private List<MemeFrameProcess> memeList = new();

protected override void OnInitialized()
{
//WatchCollection(dataService.TokenList);
//WatchObject(dataService.TokenDataLoader);
WatchProp(nameof(BindingContext.ActiveWalletAddress));

base.OnInitialized();
}

Expand Down
129 changes: 40 additions & 89 deletions src/aoww.ProcesModels/MemeFrameProcess.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ActionMetadata> GetActionMetadata()
{
var actions = new List<ActionMetadata>()
var actions = new List<ActionMetadata>();

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<ActionMetadata>()
{
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",
Expand All @@ -70,12 +72,12 @@ public override List<ActionMetadata> 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",
Expand All @@ -88,32 +90,14 @@ public override List<ActionMetadata> 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)
{
Expand All @@ -124,19 +108,7 @@ private void ProcessInfoDescriptionResult(MessageResult? result)
this.Description = result.Messages.FirstOrDefault()?.Data;
}

private AoAction CreateAoActionStake()
{
return new AoAction
{
Params = new List<ActionParam>
{
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<string> { this.ProcessId } },
new ActionParam { Key= "UnstakeDelay", ParamType = ActionParamType.Integer },
}
};
}


private AoAction CreateAoActionVote(string vote)
{
Expand All @@ -152,17 +124,7 @@ private AoAction CreateAoActionVote(string vote)
};
}

private AoAction CreateAoActionGetInfoBasic()
{
return new AoAction
{
Params = new List<ActionParam>
{
new ActionParam { Key= "Target", ParamType = ActionParamType.Target, Value= this.ProcessId },
new ActionParam { Key= "Action", ParamType = ActionParamType.Filled, Value= "Info" },
}
};
}


private AoAction CreateAoActionGetInfoDescription()
{
Expand All @@ -175,18 +137,7 @@ private AoAction CreateAoActionGetInfoDescription()
}
};
}

private AoAction CreateAoActionViewStakers()
{
return new AoAction
{
Params = new List<ActionParam>
{
new ActionParam { Key= "Target", ParamType = ActionParamType.Target, Value= this.ProcessId },
new ActionParam { Key= "Action", ParamType = ActionParamType.Filled, Value= "Stakers" },
}
};
}


private AoAction CreateAoActionGetVotes()
{
Expand Down
1 change: 1 addition & 0 deletions src/aoww.ProcesModels/Metadata/ActionMetadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
}


Expand Down
101 changes: 101 additions & 0 deletions src/aoww.ProcesModels/StakingProcess.cs
Original file line number Diff line number Diff line change
@@ -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<ActionMetadata> GetActionMetadata()
{
return new List<ActionMetadata>()
{
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<ActionParam>
{
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<ActionParam>
{
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<string> { this.ProcessId } },
new ActionParam { Key= "UnstakeDelay", ParamType = ActionParamType.Integer },
}
};
}

private AoAction CreateAoActionUnStake()
{
return new AoAction
{
Params = new List<ActionParam>
{
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<string> { this.ProcessId } },
}
};
}

private AoAction CreateAoActionFinalize()
{
return new AoAction
{
Params = new List<ActionParam>
{
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<string> { this.ProcessId } },
}
};
}

}
}
Loading

0 comments on commit 6728e8c

Please sign in to comment.