Skip to content

Commit

Permalink
Sending transaction progress
Browse files Browse the repository at this point in the history
  • Loading branch information
michielpost committed Apr 26, 2024
1 parent 5e409b0 commit 1c03932
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 44 deletions.
2 changes: 0 additions & 2 deletions src/aoWebWallet/Models/ActionParam.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,6 @@ public static AoAction CreateFromQueryString(string qstring)
actionValue = null;
}

Console.WriteLine($"Val: {actionValue} args: {args.Count()}");

action.Params.Add(new ActionParam
{
Key = actionKey,
Expand Down
30 changes: 28 additions & 2 deletions src/aoWebWallet/Pages/ActionPage.razor
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,29 @@
<MudButton OnClick="Preview">Preview</MudButton>
<MudText Color="Color.Error">@validation</MudText>
}
else
else if (!started && string.IsNullOrEmpty(transactionService.LastTransaction.Data?.Id))
{
<MudButton OnClick="Cancel">Cancel</MudButton>
<MudButton OnClick="Submit">Submit</MudButton>
}


@if (transactionService.LastTransaction.DataLoader != null)
{
<SendTransactionProgress DataLoader="transactionService.LastTransaction.DataLoader" Title="Sending transaction..." />
if (!string.IsNullOrEmpty(transactionService.LastTransaction.Data?.Id))
{
<MudStack>
<MudText Typo="Typo.h5">Transfer success!</MudText>
<MudText>TransactionId</MudText>
<MudText Class="KodeMono" Typo="Typo.caption">
@transactionService.LastTransaction.Data?.Id
</MudText>
</MudStack>

<MudButton OnClick="ReturnToWallet">Return to wallet</MudButton>
}
}


</MudContainer>

Expand All @@ -75,9 +92,12 @@
private string? validation;
private string? selectedWallet;
private bool readOnly = false;
private bool started = false;

private void Preview()
{
//transactionService.LastTransaction.Data = new Transaction() { Id = "test" };
validation = AoAction.IsValid();
readOnly = string.IsNullOrEmpty(validation);
}
Expand All @@ -86,6 +106,11 @@
readOnly = false;
}

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

private async Task Submit()
{
if (BindingContext.WalletList.Data == null)
Expand All @@ -99,6 +124,7 @@
//Do we need the owner wallet?
Wallet? ownerWallet = BindingContext.WalletList.Data.Where(x => x.Address == wallet.OwnerAddress).FirstOrDefault();

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

Expand Down
3 changes: 3 additions & 0 deletions src/aoWebWallet/Pages/ActionPage.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@ public partial class ActionPage : MvvmComponentBase<MainViewModel>

protected override void OnInitialized()
{
transactionService.Reset();

GetQueryStringValues();
//WatchDataLoaderVM(BindingContext.TokenList);
WatchDataLoaderVM(BindingContext.WalletList);
WatchDataLoaderVM(transactionService.LastTransaction);

//Auto select wallet
if(!string.IsNullOrEmpty(WalletDetailViewModel.SelectedWallet?.Wallet.Address))
Expand Down
2 changes: 1 addition & 1 deletion src/aoWebWallet/Pages/MvvmComponentBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ internal async void BindingContext_PropertyChanged(object? sender, System.Compon
internal void ObjWatch_PropertyChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e)
{
this.StateHasChanged();
Console.WriteLine("Obj State changed");
//Console.WriteLine("Obj State changed: " + sender?.ToString());
}
private void Obj_CollectionChanged(object? sender, NotifyCollectionChangedEventArgs e)
{
Expand Down
65 changes: 35 additions & 30 deletions src/aoWebWallet/Services/TransactionService.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
using aoWebWallet.Extensions;
using aoWebWallet.Models;
using ArweaveBlazor;
using CommunityToolkit.Mvvm.ComponentModel;
using webvNext.DataLoader;

namespace aoWebWallet.Services
{
public class TransactionService(ArweaveService arweaveService)
public class TransactionService(ArweaveService arweaveService) : ObservableObject
{
public DataLoaderViewModel<Transaction> LastTransactionId { get; set; } = new();
public void Reset()
{
LastTransaction.Data = null;
}
public DataLoaderViewModel<Transaction> LastTransaction { get; set; } = new();

public async Task<string?> GetActiveArConnectAddress()
{
Expand All @@ -24,48 +29,58 @@ public class TransactionService(ArweaveService arweaveService)
return null;
}

public async Task<Transaction?> SendAction(Wallet wallet, Wallet? ownerWallet, AoAction action)
public async Task SendAction(Wallet wallet, Wallet? ownerWallet, AoAction action)
{
if (wallet.Source == WalletTypes.ArConnect)
{
var activeAddress = await GetActiveArConnectAddress();
if(activeAddress == wallet.Address)
return await SendActionWithArConnect(action);
await SendActionWithArConnect(action);
}

if (ownerWallet?.Source == WalletTypes.ArConnect)
{
var activeAddress = await GetActiveArConnectAddress();
if (activeAddress == ownerWallet.Address)
return await SendActionWithEvalWithArConnect(wallet.Address, action);
await SendActionWithEvalWithArConnect(wallet.Address, action);
}

if (!string.IsNullOrEmpty(wallet.OwnerAddress) && ownerWallet?.Address == wallet.Address
&& !string.IsNullOrEmpty(ownerWallet?.Jwk))
{
return await SendActionWithEval(ownerWallet.Jwk, wallet.Address, action);
Console.WriteLine("eval");

await SendActionWithEval(ownerWallet.Jwk, wallet.Address, action);

}

if (!string.IsNullOrEmpty(wallet.Jwk))
return await SendActionWithJwk(wallet.Jwk, action);
await SendActionWithJwk(wallet.Jwk, action);

return null;
Console.WriteLine("nothing");
return;
}

private async Task SendActionWithEvalWithArConnect(string processId, AoAction action)
{
var activeAddress = await GetActiveArConnectAddress();
if (string.IsNullOrEmpty(activeAddress))
return;

await SendActionWithEval(null, processId, action);
}

private Task<Transaction?> SendActionWithEvalWithArConnect(string processId, AoAction action)
=> LastTransactionId.DataLoader.LoadAsync(async () =>
{
var activeAddress = await GetActiveArConnectAddress();
if (string.IsNullOrEmpty(activeAddress))
return null;
private async Task SendActionWithArConnect(AoAction action)
{
var activeAddress = await GetActiveArConnectAddress();
if (string.IsNullOrEmpty(activeAddress))
return;

return await SendActionWithEval(null, processId, action);
});
await SendActionWithJwk(null, action);
}

private Task<Transaction?> SendActionWithEval(string? jwk, string processId, AoAction action)
=> LastTransactionId.DataLoader.LoadAsync(async () =>
=> LastTransaction.DataLoader.LoadAsync(async () =>
{

var transferTags = action.ToEvalTags();
Expand All @@ -81,20 +96,10 @@ public class TransactionService(ArweaveService arweaveService)
var idResult = await arweaveService.SendAsync(jwk, processId, null, data, evalTags);

return new Transaction { Id = idResult };
});

private Task<Transaction?> SendActionWithArConnect(AoAction action)
=> LastTransactionId.DataLoader.LoadAsync(async () =>
{
var activeAddress = await GetActiveArConnectAddress();
if (string.IsNullOrEmpty(activeAddress))
return null;

return await SendActionWithJwk(null, action);
});
}, x => LastTransaction.Data = x);

private Task<Transaction?> SendActionWithJwk(string? jwk, AoAction action)
=> LastTransactionId.DataLoader.LoadAsync(async () =>
=> LastTransaction.DataLoader.LoadAsync(async () =>
{
if (action.Target?.Value == null)
return null;
Expand All @@ -105,7 +110,7 @@ public class TransactionService(ArweaveService arweaveService)
var idResult = await arweaveService.SendAsync(jwk, action.Target.Value, null, null, transferTags);

return new Transaction { Id = idResult };
});
}, x => LastTransaction.Data = x);



Expand Down
1 change: 0 additions & 1 deletion src/aoWebWallet/Shared/ReceiveTokenDialog.razor
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
@using aoWebWallet.Models
@using aoWebWallet.Shared
@inject ISnackbar Snackbar

<MudDialog>
<DialogContent>
Expand Down
6 changes: 1 addition & 5 deletions src/aoWebWallet/Shared/SendTokenDialog.razor
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
@using aoWebWallet.Models
@using aoWebWallet.Shared
@inject TokenClient TokenClient
@inject ISnackbar Snackbar
@inject MainViewModel MainViewModel
@inject WalletDetailViewModel WalletDetailViewModel

Expand Down Expand Up @@ -66,10 +65,7 @@
{
if (string.IsNullOrEmpty(TransactionId))
{
if (!MainViewModel.LastTransactionId.DataLoader.IsLoading)
{
<MudButton Color="Color.Primary" @ref="confButtonRef" OnClick="Confirm">Confirm</MudButton>
}
<MudButton Color="Color.Primary" @ref="confButtonRef" OnClick="Confirm">Confirm</MudButton>
}
else
{
Expand Down
3 changes: 0 additions & 3 deletions src/webvNext.DataLoader/DataLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@ public DataLoader(bool swallowExceptions = true)

private bool _swallowExceptions;

[ObservableProperty]
private bool isLoading;

[ObservableProperty]
private LoadingState loadingState;

Expand Down

0 comments on commit 1c03932

Please sign in to comment.