Skip to content

Commit

Permalink
working on dry run preview
Browse files Browse the repository at this point in the history
  • Loading branch information
michielpost committed Apr 28, 2024
1 parent be545f6 commit 0a94a51
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 6 deletions.
24 changes: 22 additions & 2 deletions src/aoWebWallet/Pages/ActionPage.razor
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,33 @@
private bool readOnly = false;
private bool started = false;

private void Preview()
private async void Preview()

Check warning on line 98 in src/aoWebWallet/Pages/ActionPage.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 98 in src/aoWebWallet/Pages/ActionPage.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.
{
//transactionService.LastTransaction.Data = new Transaction() { Id = "test" };
validation = AoAction.IsValid();
readOnly = string.IsNullOrEmpty(validation);

if (BindingContext.WalletList.Data == null)
return;

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

if (wallet == null)
return;

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

//await transactionService.DryRunAction(wallet, ownerWallet, AoAction);
}
private void Cancel()
{
Expand Down Expand Up @@ -133,7 +154,6 @@
Wallet? ownerWallet = BindingContext.WalletList.Data.Where(x => x.Address == wallet.OwnerAddress).FirstOrDefault();

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

Expand Down
1 change: 1 addition & 0 deletions src/aoWebWallet/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ private static void ConfigureServices(IServiceCollection services, string baseAd
services.AddScoped<GraphqlClient>();

services.AddArweaveBlazor();
services.AddScoped<AODataClient>();


//Register ViewModels
Expand Down
7 changes: 5 additions & 2 deletions src/aoWebWallet/Services/TransactionService.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using aoWebWallet.Extensions;
using aoWebWallet.Models;
using ArweaveAO.Requests;
using ArweaveAO.Responses;
using ArweaveBlazor;
using CommunityToolkit.Mvvm.ComponentModel;
using webvNext.DataLoader;
Expand Down Expand Up @@ -30,17 +31,19 @@ public void Reset()
return null;
}

public async Task DryRunAction(Wallet wallet, Wallet? ownerWallet, AoAction action)
public async Task<MessageResult?> DryRunAction(Wallet wallet, Wallet? ownerWallet, AoAction action)
{
var target = action.Target?.Value ?? string.Empty;
var druRunRequest = new DryRunRequest()
{
Target = target,
Owner = ownerWallet?.Address ?? wallet.Address,
Tags = action.ToDryRunTags()
};

var result = aODataClient.DryRun(target, druRunRequest);
var result = await aODataClient.DryRun(target, druRunRequest);

return result;
}

public async Task SendAction(Wallet wallet, Wallet? ownerWallet, AoAction action)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<MudText>Please select a wallet...</MudText>
return;
}
@if (ActionParam.ParamType == ActionParamType.Balance && BalanceData == null)
@if (ActionParam.ParamType == ActionParamType.Balance && BalanceData == null && !ReadOnly)
{
<MudText>Loading balance...</MudText>
<MudProgressLinear Color="Color.Primary" Indeterminate="true" />
Expand Down Expand Up @@ -86,7 +86,9 @@
if (token.TokenData?.Denomination != null)
Token = token;

if (ActionParam.ParamType == ActionParamType.Balance && !string.IsNullOrEmpty(Address))
if (ActionParam.ParamType == ActionParamType.Balance
&& !string.IsNullOrEmpty(Address)
&& !ReadOnly)
{
BalanceData = await tokenClient.GetBalance(token.TokenId, Address);
}
Expand Down

0 comments on commit 0a94a51

Please sign in to comment.