From b09761c4f7a8ce0c3eb9e7c7db4d79d98d9fd897 Mon Sep 17 00:00:00 2001 From: Aleksey Rudometov Date: Thu, 27 Feb 2020 23:21:27 +0500 Subject: [PATCH] add pageNumber to schema (#370) * add pageNumber to schema * file wasn't saved --- lib/resolvers.js | 4 ++-- lib/schema.js | 6 +++++- lib/source/cosmosV2-source.js | 12 +++++++++--- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/lib/resolvers.js b/lib/resolvers.js index d3f7475224..c0ce5c46a3 100644 --- a/lib/resolvers.js +++ b/lib/resolvers.js @@ -326,8 +326,8 @@ const resolvers = { logOverview(overview, fingerprint) return overview }, - transactions: (_, { networkId, address }, { dataSources }) => - remoteFetch(dataSources, networkId).getTransactions(address), + transactions: (_, { networkId, address, pageNumber }, { dataSources }) => + remoteFetch(dataSources, networkId).getTransactions(address, pageNumber), transactionsV2: (_, { networkId, address }, { dataSources }) => remoteFetch(dataSources, networkId).getTransactionsV2(address) }, diff --git a/lib/schema.js b/lib/schema.js index b4e656b2c1..aa148297e2 100644 --- a/lib/schema.js +++ b/lib/schema.js @@ -327,7 +327,11 @@ const typeDefs = gql` delegatorAddress: String! operatorAddress: String ): [Reward] - transactions(networkId: String!, address: String!): [Transaction] + transactions( + networkId: String! + address: String! + pageNumber: Int + ): [Transaction] transactionsV2(networkId: String!, address: String!): [TransactionV2] } ` diff --git a/lib/source/cosmosV2-source.js b/lib/source/cosmosV2-source.js index 4c355a05bf..c2c3e7ef73 100644 --- a/lib/source/cosmosV2-source.js +++ b/lib/source/cosmosV2-source.js @@ -54,7 +54,7 @@ class CosmosV2API extends CosmosV0API { return pages[1] } - async getTransactions(address) { + async getTransactions(address, pageNumber = 0) { this.checkAddress(address) // getting page count @@ -64,8 +64,14 @@ class CosmosV2API extends CosmosV0API { ) const txs = await Promise.all([ - this.loadPaginatedTxs(`/txs?message.sender=${address}`, senderPage), - this.loadPaginatedTxs(`/txs?transfer.recipient=${address}`, recipientPage) + this.loadPaginatedTxs( + `/txs?message.sender=${address}`, + senderPage - pageNumber * 2 + ), + this.loadPaginatedTxs( + `/txs?transfer.recipient=${address}`, + recipientPage - pageNumber * 2 + ) ]).then(([senderTxs, recipientTxs]) => [].concat(senderTxs, recipientTxs)) return this.reducers.formatTransactionsReducer(txs, this.reducers)