Skip to content

Commit 3f74760

Browse files
committed
[TOOL-4819] Dashboard: Load all engine backend wallets, add pagination in table (#7347)
<!-- ## title your PR with this format: "[SDK/Dashboard/Portal] Feature/Fix: Concise title for the changes" If you did not copy the branch name from Linear, paste the issue tag here (format is TEAM-0000): ## Notes for the reviewer Anything important to call out? Be sure to also clarify these in your comments. ## How to test Unit tests, playground, etc. --> <!-- start pr-codex --> --- ## PR-Codex overview This PR enhances the `useEngine` hook and the `BackendWalletsSection` component by adding pagination functionality for backend wallets retrieval, allowing users to navigate through pages of wallet data. ### Detailed summary - Added optional `limit` and `page` parameters to the `useEngine` hook. - Updated the fetch URL in the hook to accommodate pagination. - Introduced pagination controls in `BackendWalletsSection` using `Button` components. - Managed pagination state with `useState` for current page tracking. > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` <!-- end pr-codex -->
1 parent 9253c54 commit 3f74760

File tree

2 files changed

+50
-5
lines changed
  • apps/dashboard/src
    • @3rdweb-sdk/react/hooks
    • app/(app)/team/[team_slug]/[project_slug]/(sidebar)/engine/dedicated/(instance)/[engineId]/overview/components

2 files changed

+50
-5
lines changed

apps/dashboard/src/@3rdweb-sdk/react/hooks/useEngine.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,25 @@ export type BackendWallet = {
7070
export function useEngineBackendWallets(params: {
7171
instanceUrl: string;
7272
authToken: string;
73+
limit?: number;
74+
page?: number;
7375
}) {
7476
const { instanceUrl, authToken } = params;
7577
return useQuery({
76-
queryKey: [...engineKeys.backendWallets(instanceUrl), authToken],
78+
queryKey: [
79+
...engineKeys.backendWallets(instanceUrl),
80+
authToken,
81+
params.limit,
82+
params.page,
83+
],
7784
queryFn: async () => {
78-
const res = await fetch(`${instanceUrl}backend-wallet/get-all?limit=50`, {
79-
method: "GET",
80-
headers: getEngineRequestHeaders(authToken),
81-
});
85+
const res = await fetch(
86+
`${instanceUrl}backend-wallet/get-all?limit=${params.limit ?? 1000}&page=${params.page ?? 1}`,
87+
{
88+
method: "GET",
89+
headers: getEngineRequestHeaders(authToken),
90+
},
91+
);
8292

8393
const json = await res.json();
8494

apps/dashboard/src/app/(app)/team/[team_slug]/[project_slug]/(sidebar)/engine/dedicated/(instance)/[engineId]/overview/components/engine-overview.tsx

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
"use client";
22
import { SingleNetworkSelector } from "@/components/blocks/NetworkSelectors";
33
import { UnderlineLink } from "@/components/ui/UnderlineLink";
4+
import { Button } from "@/components/ui/button";
45
import { TrackedUnderlineLink } from "@/components/ui/tracked-link";
56
import {
67
type EngineInstance,
78
useEngineBackendWallets,
89
useEngineWalletConfig,
910
} from "@3rdweb-sdk/react/hooks/useEngine";
11+
import { ArrowLeftIcon, ArrowRightIcon } from "lucide-react";
1012
import { useState } from "react";
1113
import type { ThirdwebClient } from "thirdweb";
1214
import { useActiveWalletChain } from "thirdweb/react";
@@ -62,16 +64,25 @@ function BackendWalletsSection(props: {
6264
const activeWalletChain = useActiveWalletChain();
6365
const [_chainId, setChainId] = useState<number>();
6466
const chainId = _chainId || activeWalletChain?.id || 1;
67+
const pageSize = 10;
68+
const [page, setPage] = useState(1);
6569

6670
const backendWallets = useEngineBackendWallets({
6771
instanceUrl: instance.url,
6872
authToken,
73+
limit: pageSize,
74+
page,
6975
});
76+
7077
const { data: walletConfig } = useEngineWalletConfig({
7178
instanceUrl: instance.url,
7279
authToken,
7380
});
7481

82+
const disableNextButton = (backendWallets.data?.length || 0) < pageSize;
83+
const disablePreviousButton = page === 1;
84+
const showPagination = !disableNextButton || !disablePreviousButton;
85+
7586
return (
7687
<section className="rounded-lg border border-border bg-card">
7788
<div className="flex flex-col gap-5 p-6 lg:flex-row lg:items-center lg:justify-between">
@@ -151,6 +162,30 @@ function BackendWalletsSection(props: {
151162
chainId={chainId}
152163
client={props.client}
153164
/>
165+
166+
{showPagination && (
167+
<div className="flex justify-end gap-3 border-t px-4 py-5">
168+
<Button
169+
variant="outline"
170+
disabled={disablePreviousButton || backendWallets.isPending}
171+
className="gap-2"
172+
onClick={() => setPage(page - 1)}
173+
>
174+
<ArrowLeftIcon className="h-4 w-4" />
175+
Previous
176+
</Button>
177+
178+
<Button
179+
variant="outline"
180+
disabled={disableNextButton || backendWallets.isPending}
181+
className="gap-2"
182+
onClick={() => setPage(page + 1)}
183+
>
184+
Next
185+
<ArrowRightIcon className="h-4 w-4" />
186+
</Button>
187+
</div>
188+
)}
154189
</section>
155190
);
156191
}

0 commit comments

Comments
 (0)