import { Grid, chakra } from '@chakra-ui/react'; import type { UseQueryResult } from '@tanstack/react-query'; import React from 'react'; import type { ClustersByAddressResponse } from 'types/api/clusters'; import { route } from 'nextjs-routes'; import type { ResourceError } from 'lib/api/resources'; import { filterOwnedClusters, getTotalRecordsDisplay, getClusterLabel, getClustersToShow, getGridRows, hasMoreClusters, } from 'lib/clusters/clustersUtils'; import { Button } from 'toolkit/chakra/button'; import { Link } from 'toolkit/chakra/link'; import { PopoverBody, PopoverContent, PopoverRoot, PopoverTrigger } from 'toolkit/chakra/popover'; import { Skeleton } from 'toolkit/chakra/skeleton'; import { Tooltip } from 'toolkit/chakra/tooltip'; import { useDisclosure } from 'toolkit/hooks/useDisclosure'; import ClustersEntity from 'ui/shared/entities/clusters/ClustersEntity'; import IconSvg from 'ui/shared/IconSvg'; interface Props { query: UseQueryResult>; addressHash: string; } interface ClustersGridProps { data: ClustersByAddressResponse['result']['data']; } const ClustersGrid = ({ data }: ClustersGridProps) => { const itemsToShow = getClustersToShow(data, 10); const numberOfRows = getGridRows(itemsToShow.length, 5); return ( { itemsToShow.map((cluster) => ( )) } ); }; const AddressClusters = ({ query, addressHash }: Props) => { const { data, isPending, isError } = query; const popover = useDisclosure(); if (isError) { return null; } if (isPending) { return ; } if (!data?.result?.data || data.result.data.length === 0) { return null; } const ownedClusters = filterOwnedClusters(data.result.data, addressHash); if (ownedClusters.length === 0) { return null; } const totalRecords = getTotalRecordsDisplay(ownedClusters.length); const clusterLabel = getClusterLabel(ownedClusters.length); const showMoreLink = hasMoreClusters(ownedClusters.length, 10); return (
Attached to this address
{ showMoreLink && ( More results ({ totalRecords }) ) }
); }; export default AddressClusters;