Skip to content

Commit

Permalink
feat: activity page pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
afterburn committed Jul 13, 2022
1 parent 1da66fc commit 79e85b9
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 16 deletions.
38 changes: 30 additions & 8 deletions packages/sdk-ts/src/client/exchange/grpc/ExchangeGrpcAccountApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,20 +121,30 @@ export class ExchangeGrpcAccountApi extends BaseConsumer {
}
}

async fetchSubaccountHistory({
subaccountId,
denom,
transferTypes = [],
pagination,
}: {
async fetchSubaccountHistory(params?: {
subaccountId: string
denom?: string
transferTypes?: string[]
pagination?: PaginationOption
pagination?: PaginationOption,
skip?: number
limit?: number
endTime?: number
}) {
const {
subaccountId,
denom,
transferTypes = [],
pagination,
skip,
limit,
endTime
} = params || {}

const request = new SubaccountHistoryRequest()

request.setSubaccountId(subaccountId)
if (subaccountId) {
request.setSubaccountId(subaccountId)
}

if (denom) {
request.setDenom(denom)
Expand All @@ -154,6 +164,18 @@ export class ExchangeGrpcAccountApi extends BaseConsumer {
}
}

if (skip !== undefined) {
request.setSkip(skip)
}

if (limit !== undefined) {
request.setLimit(limit)
}

if (endTime !== undefined) {
request.setEndTime(endTime)
}

try {
const response = await this.request<
SubaccountHistoryRequest,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ export class ExchangeGrpcSpotApi extends BaseConsumer {
limit,
endTime,
} = params || {}

const request = new TradesRequest()

if (marketId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
TradingReward,
GrpcTradingReward,
} from '../types/account'
import { grpcPagingToPaging } from '../../../utils/pagination'

export class ExchangeGrpcAccountTransformer {
static accountPortfolioResponseToAccountPortfolio(
Expand Down Expand Up @@ -173,14 +174,14 @@ export class ExchangeGrpcAccountTransformer {

static transferHistoryResponseToTransferHistory(
response: SubaccountHistoryResponse,
): SubaccountTransfer[] {
return response
.getTransfersList()
.map((transfer) =>
ExchangeGrpcAccountTransformer.grpcTransferHistoryEntryToTransferHistoryEntry(
transfer,
),
)
) {
const transfers = response.getTransfersList()
const paging = response.getPaging()

return {
transfers: transfers.map((transfer) => ExchangeGrpcAccountTransformer.grpcTransferHistoryEntryToTransferHistoryEntry(transfer)),
paging: grpcPagingToPaging(paging)
}
}

static grpcTransferHistoryToTransferHistory(
Expand Down

0 comments on commit 79e85b9

Please sign in to comment.