Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

feature(walletkit-ui): move website and wallet store #32

Merged
merged 4 commits into from
Dec 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/walletkit-core/src/api/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from "./environment";
export * from "./network";
export * from "./paginatedAPI";
export * from "./whale";
22 changes: 22 additions & 0 deletions packages/walletkit-core/src/api/paginatedAPI.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { ApiPagedResponse } from "@defichain/whale-api-client";

export async function getPaginatedResponse<T>(
api: (limit: number, next?: string) => Promise<ApiPagedResponse<T>>
): Promise<T[]> {
const current = [];
let hasNext = false;
let next;

try {
do {
// eslint-disable-next-line no-await-in-loop
const data: ApiPagedResponse<T> = await api(200, next);
current.push(...data);
hasNext = data.hasNext;
next = data.nextToken;
} while (hasNext);
} catch (e) {
return current;
}
return current;
}
12 changes: 12 additions & 0 deletions packages/walletkit-core/src/api/paginatedAPI.unit.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { getPaginatedResponse } from "./paginatedAPI";

describe("Paginated API", () => {
it("should receive correct value", async () => {
const sampleData = [{ name: "John" }];
const mockAPI = jest.fn().mockResolvedValue(sampleData);
const response = await getPaginatedResponse((limit, next) =>
mockAPI(limit, next)
);
expect(response).toEqual(sampleData);
});
});
2 changes: 2 additions & 0 deletions packages/walletkit-ui/src/store/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export * from "./block";
export * from "./ocean";
export * from "./transaction_queue";
export * from "./wallet";
export * from "./website";
Loading