import { chakra, createListCollection, Flex } from '@chakra-ui/react'; import React from 'react'; import { route } from 'nextjs-routes'; import { Select } from 'toolkit/chakra/select'; import { Skeleton } from 'toolkit/chakra/skeleton'; import CopyToClipboard from 'ui/shared/CopyToClipboard'; import AddressEntity from 'ui/shared/entities/address/AddressEntity'; import LinkNewTab from 'ui/shared/links/LinkNewTab'; export interface Item { address_hash: string; name?: string | null | undefined; } interface Props { className?: string; label: string; selectedItem: Item; onItemSelect: (item: Item) => void; items: Array; isLoading?: boolean; } const ContractSourceAddressSelector = ({ className, selectedItem, onItemSelect, items, isLoading, label }: Props) => { const handleItemSelect = React.useCallback(({ value }: { value: Array }) => { const nextOption = items.find(({ address_hash: addressHash }) => addressHash === value[0]); if (nextOption) { onItemSelect(nextOption); } }, [ items, onItemSelect ]); const collection = React.useMemo(() => { const options = items.map(({ address_hash: addressHash, name }) => ({ label: name || addressHash, value: addressHash })); return createListCollection({ items: options }); }, [ items ]); if (isLoading) { return ; } if (items.length === 0) { return null; } if (items.length === 1) { return ( { label } ); } return ( { label }