From 86ee8c1972c375e2753309624e01a3c3cc6366b2 Mon Sep 17 00:00:00 2001 From: Sebastien Guillemot Date: Mon, 13 May 2024 04:43:33 +0900 Subject: [PATCH] bug fix on paginated query pagination --- webserver/client/src/paginated.ts | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/webserver/client/src/paginated.ts b/webserver/client/src/paginated.ts index 3f076e45..a4391b3f 100644 --- a/webserver/client/src/paginated.ts +++ b/webserver/client/src/paginated.ts @@ -11,6 +11,7 @@ import chunk from "lodash/chunk"; import { ASSET_LIMIT } from "../../shared/constants"; import merge from "lodash/merge"; import type cml from "@dcspark/cardano-multiplatform-lib-nodejs"; +import type { ProjectedNftRangeResponse } from "../../shared/models/ProjectedNftRange"; /** * If you don't mind using axios, @@ -33,7 +34,8 @@ export async function paginateQuery( ...nextRequest, after: pageFromResponse(currentPage[currentPage.length - 1]), }; - } while (currentPage.length === 0); + // TODO: This could be more efficient if we know the max page size for each query + } while (currentPage.length !== 0); return result; } @@ -65,6 +67,33 @@ export async function paginatedTransactionHistory( return { transactions: result }; } +export async function paginatedProjectedNft( + urlBase: string, + initialRequest: Omit< + EndpointTypes[Routes.projectedNftEventsRange]["input"], + "after" + > +): Promise { + const result = await paginateQuery< + EndpointTypes[Routes.projectedNftEventsRange]["input"], + ProjectedNftRangeResponse[number] + >( + initialRequest, + async (request) => + ( + await query(urlBase, Routes.projectedNftEventsRange, request) + ), + (resp) => + resp != null + ? { + block: resp.block, + tx: resp.txId, + } + : undefined + ); + return result; +} + function pairsToAssetMap(pairs: NativeAsset[]): PolicyIdAssetMapType { const result: PolicyIdAssetMapType["assets"] = {}; for (const [policyId, assetName] of pairs) {