Skip to content

Commit

Permalink
bug fix on paginated query pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
SebastienGllmt committed May 12, 2024
1 parent 2259824 commit 86ee8c1
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion webserver/client/src/paginated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -33,7 +34,8 @@ export async function paginateQuery<T extends Pagination, Response>(
...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;
}
Expand Down Expand Up @@ -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<EndpointTypes[Routes.projectedNftEventsRange]["response"]> {
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) {
Expand Down

0 comments on commit 86ee8c1

Please sign in to comment.