Skip to content

Commit

Permalink
Show aos processes
Browse files Browse the repository at this point in the history
  • Loading branch information
michielpost committed Mar 29, 2024
1 parent 548f58e commit 9df55b2
Show file tree
Hide file tree
Showing 7 changed files with 154 additions and 21 deletions.
9 changes: 9 additions & 0 deletions src/aoWebWallet/Models/AoProcessInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace aoWebWallet.Models
{
public class AoProcessInfo
{
public required string Id { get; set; }
public required string Name { get; set; }
public string? Version { get; set; }
}
}
75 changes: 54 additions & 21 deletions src/aoWebWallet/Pages/WalletDetail.razor
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
<MudTooltip Text="Refresh balances" Arrow="true" Placement="Placement.Left">
<MudIconButton Class="mt-1" Icon="@Icons.Material.Filled.Refresh" aria-label="refresh transactions" OnClick="RefreshBalances"></MudIconButton>
</MudTooltip>
@if(BindingContext.SelectedWallet?.Source == WalletTypes.Explorer)
@if (BindingContext.SelectedWallet?.Source == WalletTypes.Explorer)
{
<MudTooltip Text="Add as readonly wallet" Arrow="true" Placement="Placement.Left">
<MudIconButton Icon="@Icons.Material.Outlined.Grade" aria-label="add to wallets" OnClick="AddWalletAsReadonly"></MudIconButton>
Expand Down Expand Up @@ -69,7 +69,7 @@
<MudButton aria-label="claim token" OnClick="Claim1" Disabled="!BindingContext.CanClaim1 || BindingContext.UserSettings.Claimed1">Claim Reward (1/3)</MudButton>
}

if(BindingContext.UserSettings.Claimed2)
if (BindingContext.UserSettings.Claimed2)
{
<MudIcon Class="margin-rewards-button" Icon="@Icons.Material.Filled.Star" Title="Claim 2" />
}
Expand All @@ -88,8 +88,8 @@
}

<MudContainer style="max-width: 100%;" Width="100%" Class="d-flex justify-end mb-4 pr-2">
@* <MudTooltip Text="Refresh balances" Arrow="true" Placement="Placement.Left">
<MudIconButton Icon="@Icons.Material.Filled.Refresh" aria-label="refresh transactions" OnClick="RefreshBalances"></MudIconButton>
@* <MudTooltip Text="Refresh balances" Arrow="true" Placement="Placement.Left">
<MudIconButton Icon="@Icons.Material.Filled.Refresh" aria-label="refresh transactions" OnClick="RefreshBalances"></MudIconButton>
</MudTooltip> *@
<MudTooltip Text="Add token" Arrow="true" Placement="Placement.Left">
<MudIconButton Icon="@Icons.Material.Filled.AddCircle" aria-label="add token" Size="Size.Large" OnClick="OpenAddTokenDialog"></MudIconButton>
Expand Down Expand Up @@ -147,31 +147,64 @@

</MudStack>

<MudGrid Spacing="6">
<MudItem xs="12" sm="8">
<DataLoaderProgress DataLoader="BindingContext.TokenTransferList.DataLoader" Title="transactions" />

<MudContainer style="max-width: 100%;" Width="100%" Class="d-flex justify-end mb-4 pr-4">
<MudTooltip Text="Refresh transactions" Arrow="true" Placement="Placement.Left">
<MudIconButton Icon="@Icons.Material.Filled.Refresh" aria-label="refresh transactions" OnClick="RefreshTransactions"></MudIconButton>
</MudTooltip>
<MudStack>
@if (BindingContext.TokenTransferList.Data != null)
{
<MudStack Row="true">
<MudText Typo="Typo.h5">Transactions</MudText>
<MudSpacer />
<MudTooltip Text="Refresh transactions" Arrow="true" Placement="Placement.Left">
<MudIconButton Icon="@Icons.Material.Filled.Refresh" aria-label="refresh transactions" OnClick="RefreshTransactions"></MudIconButton>
</MudTooltip>
</MudStack>

</MudContainer>
<DataLoaderProgress DataLoader="BindingContext.TokenTransferList.DataLoader" Title="transactions" />
<MudTimeline TimelinePosition="TimelinePosition.Left">
@foreach (var transfer in BindingContext.TokenTransferList.Data)
{
<TransactionComponent transfer="transfer" SelectedAddress="@BindingContext.SelectedAddress" />
}
</MudTimeline>

}

</MudStack>
</MudItem>

<MudStack>
@if (BindingContext.TokenTransferList.Data != null)
@{
var processes = BindingContext.ProcessesDataList?.Data?.Where(x => x.Data?.Address == BindingContext.SelectedAddress).FirstOrDefault();
}
@if (processes?.Data?.Processes.Any() ?? false)
{
<MudText Typo="Typo.h5">Transactions</MudText>
<MudItem xs12 sm="4">
<MudStack>

<MudText Typo="Typo.h5">AOS</MudText>
<MudText Typo="Typo.subtitle1">List of owned AOS processes</MudText>

<MudTimeline TimelinePosition="TimelinePosition.Left">
@foreach (var transfer in BindingContext.TokenTransferList.Data)
{
<TransactionComponent transfer="transfer" SelectedAddress="@BindingContext.SelectedAddress" />
}
</MudTimeline>

<MudTimeline TimelinePosition="TimelinePosition.Left">
@foreach (var process in processes.Data.Processes)
{
var linkUrl = $"/wallet/{process.Id}";
<MudStack Row=true>
<MudText>@process.Name</MudText>
<MudSpacer />
<MudLink Href="@linkUrl">@process.Id.ToShortAddress()</MudLink>
</MudStack>
}
</MudTimeline>


</MudStack>
</MudItem>
}

</MudStack>
</MudGrid>

</MudContainer>


Expand Down Expand Up @@ -208,7 +241,7 @@

private async Task RefreshTransactions()
{
if(BindingContext.SelectedAddress != null)
if (BindingContext.SelectedAddress != null)
await BindingContext.LoadTokenTransferList(BindingContext.SelectedAddress);
}

Expand Down
4 changes: 4 additions & 0 deletions src/aoWebWallet/Pages/Wallets.razor
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@
</div>
</MudStack>
<MudSpacer />
@if(BindingContext.ProcessesDataList?.Data?.Where(x => x.Data?.Address == wallet.Address && (x.Data?.Processes?.Any() ?? false)).Any() ?? false)
{
<MudChip>AOS</MudChip>
}
@if(!string.IsNullOrEmpty(wallet.Jwk))
{
<MudIconButton Class="delete-address" Icon="@Icons.Material.Filled.Save" aria-label="backup" OnClick="() => { DownloadWallet(wallet); }"></MudIconButton>
Expand Down
1 change: 1 addition & 0 deletions src/aoWebWallet/Pages/Wallets.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ protected override void OnInitialized()
{
WatchDataLoaderVM(BindingContext.TokenList);
WatchDataLoaderVM(BindingContext.WalletList);
WatchDataLoaderVM(BindingContext.ProcessesDataList);

base.OnInitialized();
}
Expand Down
39 changes: 39 additions & 0 deletions src/aoWebWallet/Services/GraphqlClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,27 @@ public async Task<List<TokenTransfer>> GetTransactionsIn(string adddress, string
return transaction;
}

private static AoProcessInfo? GetAoProcessInfo(Edge edge)
{
if (edge == null || edge.Node == null)
return null;


var name = edge.Node.Tags.Where(x => x.Name == "Name").Select(x => x.Value).FirstOrDefault();
if (string.IsNullOrEmpty(name))
return null;

var processInfo = new AoProcessInfo()
{
Id = edge.Node.Id,
Name = name,
};

processInfo.Version = edge.Node.Tags.Where(x => x.Name == "Version").Select(x => x.Value).FirstOrDefault();

return processInfo;
}

public async Task<List<TokenTransfer>> GetTransactionsOut(string adddress, string? fromTxId = null)
{
string query = "query {\r\n transactions(\r\n first: 100\r\n sort: HEIGHT_DESC\r\n owners: [\"" + adddress + "\"]\r\n tags: [\r\n { name: \"Data-Protocol\", values: [\"ao\"] }\r\n { name: \"Action\", values: [\"Transfer\"] }\r\n ]\r\n ) {\r\n edges {\r\n node {\r\n id\r\n recipient\r\n owner {\r\n address\r\n }\r\n block {\r\n timestamp\r\n height\r\n }\r\n tags {\r\n name\r\n value\r\n }\r\n }\r\n }\r\n }\r\n}\r\n";
Expand Down Expand Up @@ -124,6 +145,24 @@ public async Task<List<TokenTransfer>> GetTransactionsForToken(string tokenId, s
return result;
}

public async Task<List<AoProcessInfo>> GetAoProcessesForAddress(string address)
{
string query = "query {\r\n transactions(\r\n first: 100,\r\n owners: [\"" + address + "\"],\r\n tags: [\r\n { name: \"Data-Protocol\", values: [\"ao\"] },\r\n { name: \"Type\", values: [\"Process\"]},\r\n { name: \"App-Name\", values: [\"aos\"]},\r\n \r\n ]\r\n ) {\r\n edges {\r\n node {\r\n id\r\n tags {\r\n name\r\n value\r\n }\r\n }\r\n }\r\n }\r\n }";
var queryResult = await PostQueryAsync(query);

var result = new List<AoProcessInfo>();

foreach (var edge in queryResult?.Data?.Transactions?.Edges ?? new())
{
AoProcessInfo? processInfo = GetAoProcessInfo(edge);

if (processInfo != null)
result.Add(processInfo);
}

return result;
}

//public async Task GetTransactionsForToken(string tokenId, string fromTxId)
//{

Expand Down
35 changes: 35 additions & 0 deletions src/aoWebWallet/ViewModels/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using MudBlazor;
using System.Net;
using webvNext.DataLoader;
using webvNext.DataLoader.Cache;

Expand Down Expand Up @@ -73,6 +74,8 @@ public partial class MainViewModel : ObservableRecipient
public DataLoaderViewModel<List<Wallet>> WalletList { get; set; } = new();
public DataLoaderViewModel<List<TokenTransfer>> TokenTransferList { get; set; } = new();
public DataLoaderViewModel<TokenTransfer> SelectedTransaction { get; set; } = new();
public DataLoaderViewModel<List<DataLoaderViewModel<WalletProcessDataViewModel>>> ProcessesDataList { get; set; } = new();


//TODO:
//Actions List (optional? address)
Expand Down Expand Up @@ -208,6 +211,36 @@ public Task LoadBalanceDataList(string address) => BalanceDataList.DataLoader.Lo
});

public Task LoadProcessesDataList() => ProcessesDataList.DataLoader.LoadAsync(async () =>
{
ProcessesDataList.Data = null;
var result = new List<DataLoaderViewModel<WalletProcessDataViewModel>>();
foreach (var wallet in WalletList.Data ?? new())
{
var address = wallet.Address;
var processData = new DataLoaderViewModel<WalletProcessDataViewModel>();
processData.Data = new WalletProcessDataViewModel { Address = address };
processData.DataLoader.LoadAsync(() =>
{
return memoryDataCache!.GetAsync($"{nameof(LoadProcessesDataList)}-{address}", async () =>
{
var data = await graphqlClient.GetAoProcessesForAddress(address);
return new WalletProcessDataViewModel() { Address = address, Processes = data };
}, TimeSpan.FromMinutes(1));
}, (x) => { processData.Data = x; ProcessesDataList.ForcePropertyChanged(); });
result.Add(processData);
}
ProcessesDataList.Data = result;
return result;
});


public async Task LoadWalletList(bool force = false)
Expand All @@ -216,6 +249,8 @@ public async Task LoadWalletList(bool force = false)
{
var list = await storageService.GetWallets();
WalletList.Data = list;

await LoadProcessesDataList();
}
}

Expand Down
12 changes: 12 additions & 0 deletions src/aoWebWallet/ViewModels/WalletProcessDataViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using aoWebWallet.Models;
using ArweaveAO.Models.Token;

namespace aoWebWallet.ViewModels
{
public class WalletProcessDataViewModel
{
public required string Address { get; set; }

public List<AoProcessInfo> Processes { get; set; } = new();
}
}

0 comments on commit 9df55b2

Please sign in to comment.