Skip to content

Commit

Permalink
add pageNumber to schema (#370)
Browse files Browse the repository at this point in the history
* add pageNumber to schema

* file wasn't saved
  • Loading branch information
iambeone authored Feb 27, 2020
1 parent d11de4e commit b09761c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
4 changes: 2 additions & 2 deletions lib/resolvers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
},
Expand Down
6 changes: 5 additions & 1 deletion lib/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]
}
`
Expand Down
12 changes: 9 additions & 3 deletions lib/source/cosmosV2-source.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit b09761c

Please sign in to comment.