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