Skip to content

Commit

Permalink
Merge pull request #11 from michielpost/feature/create-token
Browse files Browse the repository at this point in the history
Easy access to Handlers and Action Builder
  • Loading branch information
michielpost authored Sep 23, 2024
2 parents b25d8ea + 883c541 commit feb181c
Show file tree
Hide file tree
Showing 13 changed files with 397 additions and 162 deletions.
45 changes: 22 additions & 23 deletions src/aoWebWallet/Pages/ActionPage.razor
Original file line number Diff line number Diff line change
Expand Up @@ -123,27 +123,21 @@
validation = AoAction.IsValid();
readOnly = string.IsNullOrEmpty(validation);

if (BindingContext.WalletList.Data == null)
return;
var wallet = GetSelectedWallet();

var wallet = BindingContext.WalletList.Data.Where(x => x.Address == BindingContext.ActiveWallet?.Address).FirstOrDefault();
if (wallet == null)
{
if (BindingContext.ActiveWallet?.Address == BindingContext.ActiveWalletAddress)
{
wallet = BindingContext.ActiveWallet;
}
}

if (wallet == null)
Console.WriteLine("No wallet selected");
return;
}

//Do we need the owner wallet?
//Wallet? ownerWallet = BindingContext.WalletList.Data.Where(x => x.Address == wallet.OwnerAddress).FirstOrDefault();
transactionService.DryRunAction(wallet, AoAction);
await transactionService.DryRunAction(wallet, AoAction);

}

private void Cancel()
{
readOnly = false;
Expand All @@ -165,28 +159,33 @@

private async Task Submit()
{
if (BindingContext.WalletList.Data == null)
return;

var wallet = BindingContext.WalletList.Data.Where(x => x.Address == BindingContext.ActiveWallet?.Address).FirstOrDefault();
if (wallet == null)
{
if (BindingContext.ActiveWallet?.Address == BindingContext.ActiveWalletAddress)
{
wallet = BindingContext.ActiveWallet;
}
}
var wallet = GetSelectedWallet();

if (wallet == null)
return;

//Do we need the owner wallet?
Wallet? ownerWallet = BindingContext.WalletList.Data.Where(x => x.Address == wallet.OwnerAddress).FirstOrDefault();
Wallet? ownerWallet = BindingContext.WalletList.Data?.Where(x => x.Address == wallet.OwnerAddress).FirstOrDefault();

started = true;
await transactionService.SendAction(wallet, ownerWallet, AoAction);
}

private Wallet? GetSelectedWallet()
{
if (BindingContext.WalletList.Data == null)
return null;

var wallet = BindingContext.WalletList.Data.Where(x => x.Address == BindingContext.ActiveWalletAddress).FirstOrDefault();
if (wallet == null)
{
if (BindingContext.ActiveWallet?.Address == BindingContext.ActiveWalletAddress)
{
wallet = BindingContext.ActiveWallet;
}
}

return wallet;
}

}
68 changes: 57 additions & 11 deletions src/aoWebWallet/Pages/CreateTokenPage.razor
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,16 @@
<MudNumericField @bind-Value="tokenModel.Denomination" Label="Denomination" Required="true" />
<MudNumericField @bind-Value="tokenModel.TotalSupply" Format="@DenominationFormat" Label="Initial mint amount" Required="true" />

<MudButton Color="Color.Primary" Variant="Variant.Filled" Disabled="@IsDisabled" OnClick="Submit" Class="mt-8">Submit</MudButton>
@if (isPreview)
{
<br />
<MudTextField @bind-Value="data" Lines="15" Style="color:black;background-color:white;font-family:Consolas,Monaco,Lucida Console,Liberation Mono,DejaVu Sans Mono,Bitstream Vera Sans Mono,Courier New;" Label="Process Code" />
}

<MudStack Row="true">
<MudButton Color="Color.Secondary" Variant="Variant.Filled" Disabled="@IsDisabled" OnClick="Preview" Class="mt-8">Preview</MudButton>
<MudButton Color="Color.Primary" Variant="Variant.Filled" Disabled="@IsDisabled" OnClick="Submit" Class="mt-8">Submit</MudButton>
</MudStack>
</MudForm>
}
else
Expand All @@ -39,20 +48,30 @@
{
if (!string.IsNullOrEmpty(CreateTokenService.CreateTokenProgress.Data))
{

var walletUrl = $"/wallet/{CreateTokenService.CreateTokenProgress.Data}";

<br />
<MudText Class="mt-4">New tokenId: @CreateTokenService.CreateTokenProgress.Data</MudText>
<MudText Class="mt-4">New tokenId: <a href="@walletUrl">@CreateTokenService.CreateTokenProgress.Data</a></MudText>
<MudButton Color="Color.Primary" Variant="Variant.Filled" OnClick="GoToProcess" Class="mt-8">View Token</MudButton>

<br />
}
else
{
<MudText Class="mt-4">@CreateTokenService.CreateTokenProgress.DataLoader.ProgressMsg</MudText>
}


<MudButton Color="Color.Primary" Variant="Variant.Filled" OnClick="ReturnToWallet" Class="mt-8">Return to Wallet</MudButton>
<MudButton Color="Color.Secondary" Variant="Variant.Filled" OnClick="ReturnToWallet" Class="mt-8">Return to Wallet</MudButton>
}
}
</MudContainer>

@code {
private bool readOnly = false;
private bool isSubmitting = false;
private bool isPreview = false;
private string? data = null;
private CreateTokenModel tokenModel = new CreateTokenModel();
private List<BreadcrumbItem> _items = new List<BreadcrumbItem>
{
Expand All @@ -63,13 +82,40 @@
public string DenominationFormat => "F" + (tokenModel.Denomination).ToString();
public bool IsDisabled => string.IsNullOrWhiteSpace(tokenModel.Name) || string.IsNullOrWhiteSpace(tokenModel.Ticker);

private void Preview()
{
var wallet = GetSelectedWallet();

if (wallet == null)
return;

isPreview = true;
data = CreateTokenService.GetTokenProcessCode(wallet.Address, tokenModel);
}

private async Task Submit()
{
isSubmitting = true;

if (BindingContext.WalletList.Data == null)
var wallet = GetSelectedWallet();

if (wallet == null)
return;

//Run preview if not run yet
if (data == null)
data = CreateTokenService.GetTokenProcessCode(wallet.Address, tokenModel);

CreateTokenService.CreateToken(wallet, tokenModel, data);
//Snackbar.Add("Token created successfully!", Severity.Success);
}

private Wallet? GetSelectedWallet()
{
if (BindingContext.WalletList.Data == null)
return null;

var wallet = BindingContext.WalletList.Data.Where(x => x.Address == BindingContext.ActiveWalletAddress).FirstOrDefault();
if (wallet == null)
{
Expand All @@ -79,18 +125,18 @@
}
}

if (wallet == null)
return;

await CreateTokenService.CreateToken(wallet, tokenModel);
//Snackbar.Add("Token created successfully!", Severity.Success);
return wallet;
}

private void ReturnToWallet()
{
NavigationManager.NavigateTo($"/wallet/{BindingContext.ActiveWalletAddress}");
}

private void GoToProcess()
{
NavigationManager.NavigateTo($"/wallet/{CreateTokenService.CreateTokenProgress.Data}");
}


}
28 changes: 1 addition & 27 deletions src/aoWebWallet/Pages/ProcessPage.razor
Original file line number Diff line number Diff line change
Expand Up @@ -35,33 +35,7 @@


<MudItem xs="12" md="6">
<MudPaper Elevation="2" Class="pa-4">
<MudText>List of common actions for this process:</MudText>

@if(isLoading)
{
<MudText>Loading...</MudText>
}
else
{
if(actions.Any())
{
<MudList T="string">
@foreach (var action in actions)
{
<MudListItem OnClick="@(() => NavigateToActionBuilder(action.Name))">
@action.Name
</MudListItem>
}
</MudList>
}
else
{
<MudText>No previous calls to process found</MudText>
}
}

</MudPaper>
<ActionList ProcessId="@ProcessId" />
</MudItem>


Expand Down
15 changes: 13 additions & 2 deletions src/aoWebWallet/Pages/Settings.razor
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@
<MudTextField T="string" @bind-Value="BindingContext.UserSettings!.GatewayUrlConfig.ComputeUnitUrl" Label="Compute Unit" InputType="InputType.Url" />
<MudTextField T="string" @bind-Value="BindingContext.UserSettings!.GatewayUrlConfig.MessengerUnitUrl" Label="Messenger Unit" InputType="InputType.Url" />

<MudButton Class="pa-4" OnClick="Submit">Save</MudButton>
<MudStack Row="true">
<MudButton Class="pa-4" OnClick="Reset">Reset</MudButton>
<MudButton Class="pa-4" OnClick="Submit">Save</MudButton>
</MudStack>

</MudPaper>
</MudItem>
Expand All @@ -43,7 +46,7 @@

@code {

private List<BreadcrumbItem> _items = new List<BreadcrumbItem>
private List<BreadcrumbItem> _items = new List<BreadcrumbItem>
{
new BreadcrumbItem("Home", href: "/"),
new BreadcrumbItem("Settings", href: null, disabled: true)
Expand All @@ -56,6 +59,14 @@
Snackbar.Add("Settings saved, reloading data...", Severity.Info);
}

async void Reset()
{
BindingContext.UserSettings.GatewayUrlConfig = new();
await BindingContext.SaveUserSettings();

Snackbar.Add("Settings saved, reloading data...", Severity.Info);
}

async Task ClearUserData()
{
await BindingContext.ClearUserData();
Expand Down
Loading

0 comments on commit feb181c

Please sign in to comment.