Skip to content

Commit

Permalink
Reverted GraphQL queries so that transactions are visible again
Browse files Browse the repository at this point in the history
  • Loading branch information
michielpost committed Aug 27, 2024
1 parent 456ed78 commit f2276e8
Show file tree
Hide file tree
Showing 3 changed files with 119 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/aoWebWallet/ViewModels/ReceiveViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
25 changes: 15 additions & 10 deletions src/aoWebWallet/ViewModels/WalletDetailViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ public partial class WalletDetailViewModel : ObservableObject
private readonly ISnackbar snackbar;
private readonly MemoryDataCache memoryDataCache;

private List<TokenTransfer> allTransactions = new();
private List<TokenTransfer> incoming = new();
private List<TokenTransfer> outgoing = new();
private List<TokenTransfer> outgoingProcess = new();


[ObservableProperty]
Expand All @@ -47,7 +49,7 @@ public partial class WalletDetailViewModel : ObservableObject

[ObservableProperty]
public bool? hasArConnectExtension;

public WalletDetailsViewModel? SelectedWallet { get; set; }


Expand All @@ -58,8 +60,8 @@ public partial class WalletDetailViewModel : ObservableObject
public DataLoaderViewModel<List<TokenTransfer>> TokenTransferList { get; set; } = new();


public WalletDetailViewModel(MainViewModel mainViewModel,
GraphqlClient graphqlClient,
public WalletDetailViewModel(MainViewModel mainViewModel,
GraphqlClient graphqlClient,
TokenDataService dataService,
TokenClient tokenClient,
StorageService storageService,
Expand All @@ -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();

Expand Down Expand Up @@ -132,7 +133,9 @@ public async Task RefreshTokenTransferList()

private void ResetTokenTransferlist()
{
allTransactions = new();
incoming = new();
outgoing = new();
outgoingProcess = new();
TokenTransferList.Data = new();
}

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -369,7 +374,7 @@ public async Task SaveExplorerWallet()
}
}




public async Task SetClaims()
Expand Down Expand Up @@ -453,6 +458,6 @@ public async Task Claim3()
}
}


}
}
103 changes: 103 additions & 0 deletions src/aoww.Services/GraphqlClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,56 @@ public async Task<List<AoTransaction>> GetTransactionsIn(string address, string?
return result;
}

public async Task<List<TokenTransfer>> 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<TokenTransfer>();

foreach (var edge in queryResult?.Data?.Transactions?.Edges ?? new())
{
TokenTransfer? transaction = GetTokenTransfer(edge);

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

return result;
}


public async Task<List<TokenTransfer>> GetTokenTransfers(string address, string? cursor = null)
{
Expand Down Expand Up @@ -121,6 +171,59 @@ public async Task<List<TokenTransfer>> GetTokenTransfers(string address, string?
return result;
}

public async Task<List<TokenTransfer>> 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<TokenTransfer>();

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)
Expand Down

0 comments on commit f2276e8

Please sign in to comment.