diff --git a/Lexplorer/Pages/BlockDetails.razor b/Lexplorer/Pages/BlockDetails.razor index 4699619..e125e7e 100644 --- a/Lexplorer/Pages/BlockDetails.razor +++ b/Lexplorer/Pages/BlockDetails.razor @@ -153,7 +153,7 @@ isTransactionLoading = true; string transactionDatacacheKey = $"blockDetailTransactions-{blockId}-page{gotoPage}"; var transactionData = await AppCache.GetOrAddAsyncNonNull(transactionDatacacheKey, - async () => await LoopringGraphQLService.GetTransactions((gotoPage - 1) * pageSize, pageSize, blockNumber, cancellationToken: localCTS.Token), + async () => await LoopringGraphQLService.GetTransactions((gotoPage - 1) * pageSize, pageSize, blockId: blockNumber, cancellationToken: localCTS.Token), DateTimeOffset.UtcNow.AddMinutes(5)); transactions = transactionData?.data?.transactions ?? new List(); isTransactionLoading = false; diff --git a/Shared/Services/LoopringGraphQLService.cs b/Shared/Services/LoopringGraphQLService.cs index 20ae7e7..dbb9573 100644 --- a/Shared/Services/LoopringGraphQLService.cs +++ b/Shared/Services/LoopringGraphQLService.cs @@ -307,7 +307,7 @@ query transactions( $orderBy: Transaction_orderBy $orderDirection: OrderDirection $block: Block_height - $where: Transaction_filter + $whereFilter: Transaction_filter ) { proxy(id: 0) { transactionCount @@ -334,7 +334,7 @@ query transactions( orderBy: $orderBy orderDirection: $orderDirection block: $block - where: $where + where: $whereFilter ) { id internalID @@ -415,7 +415,7 @@ query transactions( orderBy = "internalID", orderDirection = "desc" , - where = new + whereFilter = new { block = blockId } @@ -432,9 +432,8 @@ query transactions( skip = skip, first = first, orderBy = "internalID", - orderDirection = "desc" - , - where = new + orderDirection = "desc", + whereFilter = new { typename = typeName } @@ -443,6 +442,11 @@ query transactions( } else { + //remove unused parameter to fix "Invalid query" error with non-hosted graph + //split and re-join all lines which don't contain the word "whereFilter" + transactionsQuery = String.Join(Environment.NewLine, + transactionsQuery.Split(Environment.NewLine).Where( + (a) => !(a.Contains("whereFilter")))); request.AddJsonBody(new { query = transactionsQuery, diff --git a/xUnitTests/LoopringGraphTests/TestTransaction.cs b/xUnitTests/LoopringGraphTests/TestTransaction.cs index 07f790d..7fc943f 100644 --- a/xUnitTests/LoopringGraphTests/TestTransaction.cs +++ b/xUnitTests/LoopringGraphTests/TestTransaction.cs @@ -25,6 +25,32 @@ public async void TestGetTransaction() Assert.NotNull(transaction); Assert.Equal(testID, transaction!.id); } + + [Theory] + [InlineData(null)] + [InlineData("Swap")] + public async void TestGetTransations(string? typeName) + { + var transactions = await service.GetTransactions(0, 5, typeName: typeName); + Assert.NotNull(transactions); + Assert.NotEmpty(transactions?.data?.transactions); + if (!String.IsNullOrEmpty(typeName)) + { + foreach (var transaction in transactions?.data?.transactions!) + { + Assert.Equal(typeName, transaction.typeName); + } + } + } + + [Theory] + [InlineData("19527")] + public async void TestGetBlockTransations(string? blockId) + { + var transactions = await service.GetTransactions(0, 5, blockId: blockId); + Assert.NotNull(transactions); + Assert.NotEmpty(transactions?.data?.transactions); + } } }