-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
913220d
commit 6270463
Showing
5 changed files
with
274 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
namespace aoWebWallet.Models | ||
{ | ||
public class AoAction | ||
{ | ||
public List<ActionParam> Params { get; set; } = new(); | ||
|
||
public ActionParam? Target => Params.Where(x => x.ParamType == ActionParamType.Target).FirstOrDefault(); | ||
public IEnumerable<ActionParam> Filled => Params.Where(x => x.ParamType == ActionParamType.Filled); | ||
public IEnumerable<ActionParam> AllInputs => Params.Where(x => | ||
x.ParamType != ActionParamType.Filled | ||
&& x.ParamType != ActionParamType.Target); | ||
|
||
public string? IsValid() | ||
{ | ||
if (Target == null) | ||
return "No Target process specified."; | ||
|
||
return null; | ||
} | ||
} | ||
|
||
public class ActionParam | ||
{ | ||
public required string Key { get; set; } | ||
public string? Value { get; set; } | ||
|
||
public string? TokenId { get; set; } | ||
|
||
public ActionParamType ParamType { get; set; } | ||
|
||
} | ||
|
||
public enum ActionParamType | ||
{ | ||
None = 0, | ||
Target, | ||
Filled, | ||
Input, | ||
Integer, | ||
Process, | ||
Balance, //Must have balance | ||
Quantity, //Does not care about balance | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
@page "/action" | ||
@using aoWebWallet.Models | ||
@inherits MvvmComponentBase<MainViewModel> | ||
@inject IDialogService DialogService | ||
@inject ISnackbar Snackbar | ||
@inject NavigationManager NavigationManager; | ||
|
||
<PageTitle>@Program.PageTitlePostFix</PageTitle> | ||
|
||
|
||
<MudContainer Class="mt-16 px-8" MaxWidth="MaxWidth.False"> | ||
<MudText Typo="Typo.h5">Action Page</MudText> | ||
|
||
<MudStack> | ||
TODO: Select a wallet, or create a new wallet | ||
</MudStack> | ||
|
||
<MudStack> | ||
Target: @AoAction.Target?.Value | ||
</MudStack> | ||
|
||
<MudStack> | ||
@foreach(var value in AoAction.Filled) | ||
{ | ||
<p>@value.Key = @value.Value | @value.ParamType</p> | ||
} | ||
|
||
</MudStack> | ||
|
||
<MudStack> | ||
@foreach (var param in AoAction.AllInputs) | ||
{ | ||
if(param.ParamType == ActionParamType.Input | ||
|| param.ParamType == ActionParamType.Integer | ||
|| param.ParamType == ActionParamType.Process | ||
) | ||
{ | ||
<ActionInputComponent ActionParam="param" /> | ||
} | ||
else if (param.ParamType == ActionParamType.Quantity || param.ParamType == ActionParamType.Balance) | ||
{ | ||
//TODO: Quantity, with token and denomination and enough balance check | ||
} | ||
} | ||
|
||
</MudStack> | ||
|
||
|
||
</MudContainer> | ||
|
||
@code | ||
{ | ||
|
||
private void OnValidSubmit(EditContext context) | ||
{ | ||
//success = true; | ||
StateHasChanged(); | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
using aoWebWallet.Models; | ||
using aoWebWallet.ViewModels; | ||
using Microsoft.AspNetCore.Components.Routing; | ||
using System.Net; | ||
|
||
namespace aoWebWallet.Pages | ||
{ | ||
public partial class ActionPage : MvvmComponentBase<MainViewModel> | ||
{ | ||
public AoAction AoAction { get; set; } = new(); | ||
|
||
protected override void OnInitialized() | ||
{ | ||
GetQueryStringValues(); | ||
WatchDataLoaderVM(BindingContext.TokenList); | ||
NavigationManager.LocationChanged += NavigationManager_LocationChanged; | ||
} | ||
|
||
private void NavigationManager_LocationChanged(object? sender, LocationChangedEventArgs e) | ||
{ | ||
GetQueryStringValues(); | ||
StateHasChanged(); | ||
} | ||
|
||
void GetQueryStringValues() | ||
{ | ||
var uri = new Uri(NavigationManager.Uri); | ||
var query = uri.Query; | ||
|
||
// Parsing query string | ||
var queryStringValues = System.Web.HttpUtility.ParseQueryString(query); | ||
|
||
AoAction = new AoAction(); | ||
|
||
foreach (var key in queryStringValues.AllKeys) | ||
{ | ||
if (key == null) | ||
continue; | ||
|
||
var values = queryStringValues.GetValues(key); | ||
if (values == null || !values.Any()) | ||
continue; | ||
|
||
foreach(var val in values) | ||
{ | ||
string actionKey = key; | ||
string? actionValue = val.ToString(); | ||
ActionParamType actionParamType = ActionParamType.Filled; | ||
|
||
if (key.Equals("Target", StringComparison.InvariantCultureIgnoreCase)) | ||
actionParamType = ActionParamType.Target; | ||
if (key.Equals("X-Quantity", StringComparison.InvariantCultureIgnoreCase)) | ||
actionParamType = ActionParamType.Quantity; | ||
else if (key.Equals("X-Process", StringComparison.InvariantCultureIgnoreCase)) | ||
actionParamType = ActionParamType.Process; | ||
else if (key.Equals("X-Int", StringComparison.InvariantCultureIgnoreCase)) | ||
actionParamType = ActionParamType.Integer; | ||
else if (key.Equals("X-Input", StringComparison.InvariantCultureIgnoreCase)) | ||
actionParamType = ActionParamType.Input; | ||
|
||
if (actionParamType != ActionParamType.Filled | ||
&& actionParamType != ActionParamType.Target) | ||
{ | ||
actionKey = val; | ||
actionValue = null; | ||
} | ||
|
||
AoAction.Params.Add(new ActionParam | ||
{ | ||
Key = actionKey, | ||
Value = actionValue, | ||
ParamType = actionParamType | ||
}); | ||
|
||
} | ||
} | ||
|
||
StateHasChanged(); | ||
} | ||
|
||
|
||
|
||
public void Dispose() | ||
Check warning on line 83 in src/aoWebWallet/Pages/ActionPage.razor.cs GitHub Actions / build
Check warning on line 83 in src/aoWebWallet/Pages/ActionPage.razor.cs GitHub Actions / build
|
||
{ | ||
NavigationManager.LocationChanged -= NavigationManager_LocationChanged; | ||
} | ||
|
||
protected override async Task LoadDataAsync() | ||
{ | ||
await BindingContext.LoadTokenList(); | ||
|
||
await base.LoadDataAsync(); | ||
|
||
} | ||
|
||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
src/aoWebWallet/Shared/Components/ActionInputComponent.razor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
@using aoWebWallet.Models | ||
<p>@ActionParam.Key = @ActionParam.Value | @ActionParam.ParamType</p> | ||
|
||
@if (ActionParam.ParamType == ActionParamType.Input) | ||
{ | ||
<MudTextField @ref="mudTextField" T="string" Label="@ActionParam.Key" Variant="Variant.Text" ValueChanged="UpdateStringValue"></MudTextField> | ||
} | ||
else if (ActionParam.ParamType == ActionParamType.Process) | ||
{ | ||
<MudTextField @ref="mudProcessField" T="string" MaxLength=43 Label="@ActionParam.Key" Validation="@(new Func<string, IEnumerable<string>>(ValidateProcess))" Variant="Variant.Text" ValueChanged="UpdateStringValue" /> | ||
} | ||
else if (ActionParam.ParamType == ActionParamType.Integer) | ||
{ | ||
<MudTextField @ref="mudIntField" T="int" Label="@ActionParam.Key" Variant="Variant.Text" ValueChanged="UpdateIntValue"></MudTextField> | ||
} | ||
|
||
|
||
@code { | ||
|
||
[Parameter] | ||
public required ActionParam ActionParam { get; set; } | ||
|
||
MudTextField<string>? mudTextField; | ||
MudTextField<string>? mudProcessField; | ||
MudTextField<int>? mudIntField; | ||
|
||
public string? stringValue = null; | ||
public int? intValue = null; | ||
|
||
public async void UpdateStringValue(string e) | ||
{ | ||
if (mudTextField != null) | ||
await mudTextField.Validate(); | ||
if(mudProcessField != null) | ||
await mudProcessField.Validate(); | ||
|
||
if (!(mudTextField?.ValidationErrors.Any() ?? false) | ||
&& !(mudProcessField?.ValidationErrors.Any() ?? false)) | ||
{ | ||
ActionParam.Value = e; | ||
} | ||
else | ||
ActionParam.Value = null; | ||
|
||
StateHasChanged(); | ||
} | ||
|
||
public IEnumerable<string> ValidateProcess(string input) | ||
{ | ||
if (input.Length != 43) | ||
{ | ||
Console.WriteLine("Invalid"); | ||
|
||
yield return "Address must have length of 43 characters."; | ||
} | ||
} | ||
|
||
public async void UpdateIntValue(int e) | ||
{ | ||
if (mudIntField != null) | ||
await mudIntField.Validate(); | ||
|
||
if (!(mudIntField?.ValidationErrors.Any() ?? false)) | ||
ActionParam.Value = e.ToString(); | ||
else | ||
ActionParam.Value = null; | ||
|
||
StateHasChanged(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters