Skip to content

Commit 6baeb51

Browse files
committed
Refactor server wallets table pagination logic
Replaces the old pagination component in ServerWalletsTable with a new PaginationButtons component and updates the pagination logic to use next/navigation for client-side routing. Also passes pageSize as a prop and improves the display of wallet record ranges. Updates the overview page to use loginRedirect for unauthenticated access.
1 parent 2b13c3f commit 6baeb51

File tree

2 files changed

+59
-70
lines changed

2 files changed

+59
-70
lines changed

apps/dashboard/src/app/(app)/team/[team_slug]/[project_slug]/(sidebar)/transactions/components/server-wallets-table.client.tsx

Lines changed: 56 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
XIcon,
1111
} from "lucide-react";
1212
import Link from "next/link";
13+
import { usePathname, useSearchParams } from "next/navigation";
1314
import { useState } from "react";
1415
import { toast } from "sonner";
1516
import type { ThirdwebClient } from "thirdweb";
@@ -21,6 +22,7 @@ import {
2122
import type { Project } from "@/api/project/projects";
2223
import { FundWalletModal } from "@/components/blocks/fund-wallets-modal";
2324
import { SingleNetworkSelector } from "@/components/blocks/NetworkSelectors";
25+
import { PaginationButtons } from "@/components/blocks/pagination-buttons";
2426
import { SolanaAddress } from "@/components/blocks/solana-address";
2527
import { WalletAddress } from "@/components/blocks/wallet-address";
2628
import { Badge } from "@/components/ui/badge";
@@ -32,14 +34,6 @@ import {
3234
DropdownMenuTrigger,
3335
} from "@/components/ui/dropdown-menu";
3436
import { Label } from "@/components/ui/label";
35-
import {
36-
Pagination,
37-
PaginationContent,
38-
PaginationItem,
39-
PaginationLink,
40-
PaginationNext,
41-
PaginationPrevious,
42-
} from "@/components/ui/pagination";
4337
import {
4438
Select,
4539
SelectContent,
@@ -88,6 +82,7 @@ interface ServerWalletsTableProps {
8882
client: ThirdwebClient;
8983
solanaPermissionError?: boolean;
9084
authToken: string;
85+
pageSize: number;
9186
}
9287

9388
export function ServerWalletsTable(props: ServerWalletsTableProps) {
@@ -105,6 +100,7 @@ export function ServerWalletsTable(props: ServerWalletsTableProps) {
105100
client,
106101
solanaPermissionError,
107102
authToken,
103+
pageSize,
108104
} = props;
109105

110106
const [activeChain, setActiveChain] = useState<WalletChain>("evm");
@@ -333,13 +329,13 @@ export function ServerWalletsTable(props: ServerWalletsTableProps) {
333329
</TableContainer>
334330

335331
{totalPages > 1 && (
336-
<WalletsPagination
332+
<ServerWalletsPagination
337333
activeChain={activeChain}
338334
currentPage={currentPage}
335+
currentCount={wallets.length}
336+
pageSize={pageSize}
339337
totalPages={totalPages}
340338
totalRecords={totalRecords}
341-
teamSlug={teamSlug}
342-
projectSlug={project.slug}
343339
/>
344340
)}
345341
</>
@@ -349,78 +345,69 @@ export function ServerWalletsTable(props: ServerWalletsTableProps) {
349345
);
350346
}
351347

352-
// Wallets Pagination Component
353-
function WalletsPagination({
348+
function ServerWalletsPagination({
354349
activeChain,
355350
currentPage,
351+
currentCount,
352+
pageSize,
356353
totalPages,
357354
totalRecords,
358-
teamSlug,
359-
projectSlug,
360355
}: {
361356
activeChain: WalletChain;
362357
currentPage: number;
358+
currentCount: number;
359+
pageSize: number;
363360
totalPages: number;
364361
totalRecords: number;
365-
teamSlug: string;
366-
projectSlug: string;
367362
}) {
363+
const router = useDashboardRouter();
364+
const pathname = usePathname();
365+
const searchParams = useSearchParams();
368366
const pageParam = activeChain === "evm" ? "page" : "solana_page";
369367

368+
const effectivePageSize = pageSize > 0 ? pageSize : currentCount;
369+
const rangeStart =
370+
totalRecords && effectivePageSize
371+
? Math.min((currentPage - 1) * effectivePageSize + 1, totalRecords)
372+
: 0;
373+
const computedCount = currentCount
374+
? currentCount
375+
: totalRecords && effectivePageSize
376+
? Math.min(effectivePageSize, totalRecords - rangeStart + 1)
377+
: 0;
378+
const rangeEnd = totalRecords
379+
? Math.min(rangeStart + Math.max(computedCount - 1, 0), totalRecords)
380+
: 0;
381+
382+
const handlePageChange = (page: number) => {
383+
const params = new URLSearchParams(searchParams?.toString() ?? "");
384+
if (page <= 1) {
385+
params.delete(pageParam);
386+
} else {
387+
params.set(pageParam, page.toString());
388+
}
389+
390+
const queryString = params.toString();
391+
router.push(queryString ? `${pathname}?${queryString}` : pathname);
392+
};
393+
370394
return (
371-
<div className="flex flex-col items-center border-t p-6">
372-
<div className="mb-4 text-muted-foreground text-sm">
373-
Found {totalRecords} {activeChain === "evm" ? "EVM" : "Solana"} wallets
395+
<div className="border-t px-6 py-6">
396+
<div className="flex flex-col gap-4 lg:flex-row lg:items-center lg:justify-between">
397+
<span className="text-sm text-muted-foreground">
398+
{totalRecords
399+
? `Showing ${rangeStart.toLocaleString()}-${rangeEnd.toLocaleString()} of ${totalRecords.toLocaleString()} ` +
400+
(activeChain === "evm" ? "EVM" : "Solana") +
401+
" wallets"
402+
: `No ${activeChain === "evm" ? "EVM" : "Solana"} wallets found`}
403+
</span>
404+
<PaginationButtons
405+
activePage={currentPage}
406+
className="justify-start lg:justify-end"
407+
onPageClick={handlePageChange}
408+
totalPages={totalPages}
409+
/>
374410
</div>
375-
<Pagination>
376-
<PaginationContent>
377-
<PaginationItem>
378-
<Link
379-
href={`/team/${teamSlug}/${projectSlug}/transactions?${pageParam}=${
380-
currentPage > 1 ? currentPage - 1 : 1
381-
}`}
382-
legacyBehavior
383-
passHref
384-
>
385-
<PaginationPrevious
386-
className={
387-
currentPage <= 1 ? "pointer-events-none opacity-50" : ""
388-
}
389-
/>
390-
</Link>
391-
</PaginationItem>
392-
{Array.from({ length: totalPages }, (_, i) => i + 1).map(
393-
(pageNumber) => (
394-
<PaginationItem key={`page-${pageNumber}`}>
395-
<Link
396-
href={`/team/${teamSlug}/${projectSlug}/transactions?${pageParam}=${pageNumber}`}
397-
passHref
398-
>
399-
<PaginationLink isActive={currentPage === pageNumber}>
400-
{pageNumber}
401-
</PaginationLink>
402-
</Link>
403-
</PaginationItem>
404-
),
405-
)}
406-
<PaginationItem>
407-
<Link
408-
href={`/team/${teamSlug}/${projectSlug}/transactions?${pageParam}=${
409-
currentPage < totalPages ? currentPage + 1 : totalPages
410-
}`}
411-
passHref
412-
>
413-
<PaginationNext
414-
className={
415-
currentPage >= totalPages
416-
? "pointer-events-none opacity-50"
417-
: ""
418-
}
419-
/>
420-
</Link>
421-
</PaginationItem>
422-
</PaginationContent>
423-
</Pagination>
424411
</div>
425412
);
426413
}

apps/dashboard/src/app/(app)/team/[team_slug]/[project_slug]/(sidebar)/wallets/server-wallets/overview/page.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { getAuthToken } from "@/api/auth-token";
44
import { getProject } from "@/api/project/projects";
55
import { NEXT_PUBLIC_THIRDWEB_VAULT_URL } from "@/constants/public-envs";
66
import { getClientThirdwebClient } from "@/constants/thirdweb-client.client";
7+
import { loginRedirect } from "@/utils/redirects";
78
import { TransactionsAnalyticsPageContent } from "../../../transactions/analytics/analytics-page";
89
import { EngineChecklist } from "../../../transactions/analytics/ftux.client";
910
import { TransactionAnalyticsSummary } from "../../../transactions/analytics/summary";
@@ -34,7 +35,7 @@ export default async function Page(props: {
3435
]);
3536

3637
if (!authToken) {
37-
redirect(
38+
loginRedirect(
3839
`/team/${params.team_slug}/${params.project_slug}/wallets/server-wallets/overview`,
3940
);
4041
}
@@ -168,6 +169,7 @@ export default async function Page(props: {
168169
evmTotalPages={Math.ceil(eoas.data.totalRecords / pageSize)}
169170
evmTotalRecords={eoas.data.totalRecords}
170171
evmWallets={eoas.data.items as Wallet[]}
172+
pageSize={pageSize}
171173
project={project}
172174
solanaCurrentPage={solanaCurrentPage}
173175
solanaTotalPages={Math.ceil(

0 commit comments

Comments
 (0)