/* eslint-disable eslint-comments/disable-enable-pair */ /* eslint-disable jsx-a11y/img-redundant-alt */ import { MagnifyingGlassIcon } from '@heroicons/react/24/outline' import Input from 'components/Input' import useSearch from 'hooks/useSearch' import { useMemo, useState } from 'react' import { useDebounce } from 'utils/debounce' import { truncateAddress } from 'utils/wallet' interface ClickableCollection { contractAddress: string name: string media: string onClick: () => void } export default function SelectCollection({ title, setCollection, }: { title?: string setCollection: (collectionAddress: string) => void }) { const [search, setSearch] = useState('') const debouncedQuery = useDebounce(search, 200) const collectionsQuery = useSearch(debouncedQuery, ['collections'], 10) const collectionsResults = useMemo(() => { return collectionsQuery.data?.find((searchResult) => searchResult.indexUid === 'collections') }, [collectionsQuery.data]) const clickableCollections = useMemo(() => { return ( collectionsResults?.hits.map((hit) => ({ contractAddress: hit.id, name: hit.name, media: hit.thumbnail_url || hit.image_url, onClick: () => { setCollection(hit.id) }, })) ?? [] ) }, [collectionsResults?.hits, setCollection]) return (

{title ?? 'Select the NFT collection to trade'}

} id="collection-search" onChange={(e: any) => setSearch(e.target.value)} placeholder="Search Collections..." value={search} />
) } const CollectionsTable = ({ collections }: { collections: ClickableCollection[] }) => { return ( {collections.map((collection) => ( ))}
Name Address
Collection Image
{collection.name}
{truncateAddress(collection.contractAddress)}
{truncateAddress(collection.contractAddress, 8, 6)}
) }