Skip to content

Commit

Permalink
First setup for Action Page
Browse files Browse the repository at this point in the history
  • Loading branch information
michielpost committed Apr 17, 2024
1 parent 913220d commit 6270463
Show file tree
Hide file tree
Showing 5 changed files with 274 additions and 1 deletion.
44 changes: 44 additions & 0 deletions src/aoWebWallet/Models/ActionParam.cs
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
}
}
61 changes: 61 additions & 0 deletions src/aoWebWallet/Pages/ActionPage.razor
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();
}


}
97 changes: 97 additions & 0 deletions src/aoWebWallet/Pages/ActionPage.razor.cs
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

View workflow job for this annotation

GitHub Actions / build

'ActionPage.Dispose()' hides inherited member 'MvvmComponentBase<MainViewModel>.Dispose()'. To make the current member override that implementation, add the override keyword. Otherwise add the new keyword.

Check warning on line 83 in src/aoWebWallet/Pages/ActionPage.razor.cs

View workflow job for this annotation

GitHub Actions / build

'ActionPage.Dispose()' hides inherited member 'MvvmComponentBase<MainViewModel>.Dispose()'. To make the current member override that implementation, add the override keyword. Otherwise add the new keyword.
{
NavigationManager.LocationChanged -= NavigationManager_LocationChanged;
}

protected override async Task LoadDataAsync()
{
await BindingContext.LoadTokenList();

await base.LoadDataAsync();

}

}
}
71 changes: 71 additions & 0 deletions src/aoWebWallet/Shared/Components/ActionInputComponent.razor
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();
}

}
2 changes: 1 addition & 1 deletion src/aoWebWallet/Shared/SendTokenDialog.razor
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@

public MudButton? confButtonRef;

public int Denomination => BindingContext.SelectedBalanceDataVM?.Token?.TokenData?.Denomination ?? 0;
//public int Denomination => BindingContext.SelectedBalanceDataVM?.Token?.TokenData?.Denomination ?? 0;
public string DenominationFormat => "F" + (BindingContext.SelectedBalanceDataVM?.Token?.TokenData?.Denomination ?? 1).ToString();

public async Task Submit()

Check warning on line 96 in src/aoWebWallet/Shared/SendTokenDialog.razor

View workflow job for this annotation

GitHub Actions / build

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

Check warning on line 96 in src/aoWebWallet/Shared/SendTokenDialog.razor

View workflow job for this annotation

GitHub Actions / build

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.
Expand Down

0 comments on commit 6270463

Please sign in to comment.