|
1 | 1 | "use client";
|
2 | 2 | import { SingleNetworkSelector } from "@/components/blocks/NetworkSelectors";
|
3 | 3 | import { UnderlineLink } from "@/components/ui/UnderlineLink";
|
| 4 | +import { Button } from "@/components/ui/button"; |
4 | 5 | import { TrackedUnderlineLink } from "@/components/ui/tracked-link";
|
5 | 6 | import {
|
6 | 7 | type EngineInstance,
|
7 | 8 | useEngineBackendWallets,
|
8 | 9 | useEngineWalletConfig,
|
9 | 10 | } from "@3rdweb-sdk/react/hooks/useEngine";
|
| 11 | +import { ArrowLeftIcon, ArrowRightIcon } from "lucide-react"; |
10 | 12 | import { useState } from "react";
|
11 | 13 | import type { ThirdwebClient } from "thirdweb";
|
12 | 14 | import { useActiveWalletChain } from "thirdweb/react";
|
@@ -62,16 +64,25 @@ function BackendWalletsSection(props: {
|
62 | 64 | const activeWalletChain = useActiveWalletChain();
|
63 | 65 | const [_chainId, setChainId] = useState<number>();
|
64 | 66 | const chainId = _chainId || activeWalletChain?.id || 1;
|
| 67 | + const pageSize = 10; |
| 68 | + const [page, setPage] = useState(1); |
65 | 69 |
|
66 | 70 | const backendWallets = useEngineBackendWallets({
|
67 | 71 | instanceUrl: instance.url,
|
68 | 72 | authToken,
|
| 73 | + limit: pageSize, |
| 74 | + page, |
69 | 75 | });
|
| 76 | + |
70 | 77 | const { data: walletConfig } = useEngineWalletConfig({
|
71 | 78 | instanceUrl: instance.url,
|
72 | 79 | authToken,
|
73 | 80 | });
|
74 | 81 |
|
| 82 | + const disableNextButton = (backendWallets.data?.length || 0) < pageSize; |
| 83 | + const disablePreviousButton = page === 1; |
| 84 | + const showPagination = !disableNextButton || !disablePreviousButton; |
| 85 | + |
75 | 86 | return (
|
76 | 87 | <section className="rounded-lg border border-border bg-card">
|
77 | 88 | <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: {
|
151 | 162 | chainId={chainId}
|
152 | 163 | client={props.client}
|
153 | 164 | />
|
| 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 | + )} |
154 | 189 | </section>
|
155 | 190 | );
|
156 | 191 | }
|
0 commit comments