From f2276e819c1f0eeac6c1ef0d2f94a28828389420 Mon Sep 17 00:00:00 2001 From: Michiel Post Date: Tue, 27 Aug 2024 10:55:52 +0200 Subject: [PATCH] Reverted GraphQL queries so that transactions are visible again --- .../ViewModels/ReceiveViewModel.cs | 2 +- .../ViewModels/WalletDetailViewModel.cs | 25 +++-- src/aoww.Services/GraphqlClient.cs | 103 ++++++++++++++++++ 3 files changed, 119 insertions(+), 11 deletions(-) diff --git a/src/aoWebWallet/ViewModels/ReceiveViewModel.cs b/src/aoWebWallet/ViewModels/ReceiveViewModel.cs index 651974a..b8e3789 100644 --- a/src/aoWebWallet/ViewModels/ReceiveViewModel.cs +++ b/src/aoWebWallet/ViewModels/ReceiveViewModel.cs @@ -70,7 +70,7 @@ public Task LoadTokenTransferList() => TokenTransferList.DataLoader.LoadAsync(as { var address = Address; - var incoming = await graphqlClient.GetTokenTransfers(address); + var incoming = await graphqlClient.GetTokenTransfersIn(address); incoming = incoming.Where(x => x.Timestamp > StartTime).OrderByDescending(x => x.Timestamp).ToList(); diff --git a/src/aoWebWallet/ViewModels/WalletDetailViewModel.cs b/src/aoWebWallet/ViewModels/WalletDetailViewModel.cs index 3f42a60..d52bf19 100644 --- a/src/aoWebWallet/ViewModels/WalletDetailViewModel.cs +++ b/src/aoWebWallet/ViewModels/WalletDetailViewModel.cs @@ -23,7 +23,9 @@ public partial class WalletDetailViewModel : ObservableObject private readonly ISnackbar snackbar; private readonly MemoryDataCache memoryDataCache; - private List allTransactions = new(); + private List incoming = new(); + private List outgoing = new(); + private List outgoingProcess = new(); [ObservableProperty] @@ -47,7 +49,7 @@ public partial class WalletDetailViewModel : ObservableObject [ObservableProperty] public bool? hasArConnectExtension; - + public WalletDetailsViewModel? SelectedWallet { get; set; } @@ -58,8 +60,8 @@ public partial class WalletDetailViewModel : ObservableObject public DataLoaderViewModel> TokenTransferList { get; set; } = new(); - public WalletDetailViewModel(MainViewModel mainViewModel, - GraphqlClient graphqlClient, + public WalletDetailViewModel(MainViewModel mainViewModel, + GraphqlClient graphqlClient, TokenDataService dataService, TokenClient tokenClient, StorageService storageService, @@ -83,7 +85,6 @@ public async Task Initialize(string address) VisibleTokenList = new(); VisibleTokenList.Add(Constants.AoTokenId); //AO VisibleTokenList.Add(Constants.CredTokenId); //TESTNET-CRED - VisibleTokenList.Add(Constants.LlamaTokenId); //Llama Coin ResetTokenTransferlist(); @@ -132,7 +133,9 @@ public async Task RefreshTokenTransferList() private void ResetTokenTransferlist() { - allTransactions = new(); + incoming = new(); + outgoing = new(); + outgoingProcess = new(); TokenTransferList.Data = new(); } @@ -222,9 +225,11 @@ private async Task SelectWallet(string? address) public Task LoadTokenTransferList(string address) => TokenTransferList.DataLoader.LoadAsync(async () => { - allTransactions = await graphqlClient.GetTokenTransfers(address, GetCursor(allTransactions)); + incoming = await graphqlClient.GetTokenTransfersIn(address, GetCursor(incoming)); + outgoing = await graphqlClient.GetTransactionsOut(address, GetCursor(outgoing)); + outgoingProcess = await graphqlClient.GetTransactionsOutFromProcess(address, GetCursor(outgoingProcess)); - var allNew = allTransactions.OrderByDescending(x => x.Timestamp).ToList(); + var allNew = incoming.Concat(outgoing).Concat(outgoingProcess).OrderByDescending(x => x.Timestamp).ToList(); CanLoadMoreTransactions = allNew.Any(); var existing = TokenTransferList.Data ?? new(); @@ -369,7 +374,7 @@ public async Task SaveExplorerWallet() } } - + public async Task SetClaims() @@ -453,6 +458,6 @@ public async Task Claim3() } } - + } } diff --git a/src/aoww.Services/GraphqlClient.cs b/src/aoww.Services/GraphqlClient.cs index 2f20d7f..64b2b5d 100644 --- a/src/aoww.Services/GraphqlClient.cs +++ b/src/aoww.Services/GraphqlClient.cs @@ -69,6 +69,56 @@ public async Task> GetTransactionsIn(string address, string? return result; } + public async Task> GetTransactionsOut(string address, string? cursor = null) + { + string query = $$""" + query { + transactions( + first: 50 + after: "{{cursor}}" + sort: HEIGHT_DESC + owners: ["{{address}}"] + tags: [ + { name: "Data-Protocol", values: ["ao"] } + { name: "Action", values: ["Transfer"] } + ] + ) { + edges { + cursor + node { + id + recipient + owner { + address + } + block { + timestamp + height + } + tags { + name + value + } + } + } + } + } + """; + var queryResult = await PostQueryAsync(query); + + var result = new List(); + + foreach (var edge in queryResult?.Data?.Transactions?.Edges ?? new()) + { + TokenTransfer? transaction = GetTokenTransfer(edge); + + if (transaction != null) + result.Add(transaction); + } + + return result; + } + public async Task> GetTokenTransfers(string address, string? cursor = null) { @@ -121,6 +171,59 @@ public async Task> GetTokenTransfers(string address, string? return result; } + public async Task> GetTokenTransfersIn(string address, string? cursor = null) + { + string query = $$""" + query { + transactions( + first: 50 + after: "{{cursor}}" + sort: HEIGHT_DESC + tags: [ + { name: "Data-Protocol", values: ["ao"] } + { name: "Action", values: ["Transfer", "Mint-Token", "Mint"] } + { name: "Recipient", values: ["{{address}}"] } + ] + ) { + edges { + cursor + node { + id + recipient + owner { + address + } + block { + timestamp + height + } + tags { + name + value + } + } + } + } + } + + """; + var queryResult = await PostQueryAsync(query); + + var result = new List(); + + foreach (var edge in queryResult?.Data?.Transactions?.Edges ?? new()) + { + TokenTransfer? transaction = GetTokenTransfer(edge); + + if (transaction != null) + result.Add(transaction); + } + + return result; + } + + + private static AoTransaction? GetAoTransaction(Edge edge) { if (edge == null || edge.Node == null)