import { WarningRounded } from '@mui/icons-material' import Fuse from 'fuse.js' import { ComponentType } from 'react' import { useTranslation } from 'react-i18next' import { ContractVersion, LazyDaoCardProps } from '@dao-dao/types' import { getChainGovernanceDaoDescription, getConfiguredChains, getDisplayNameForChainId, getImageUrlForChainId, getRpcForChainId, } from '@dao-dao/utils' import { GridCardContainer, NoContent, SearchBar } from '../components' import { useSearchFilter } from '../hooks' export type ChainGovernanceListProps = { LazyDaoCard: ComponentType } export const ChainGovernanceList = ({ LazyDaoCard, }: ChainGovernanceListProps) => { const { t } = useTranslation() const chains = getConfiguredChains() .filter(({ chainId, noGov }) => { // Ensure RPC exists for this chain. If not it will error. try { getRpcForChainId(chainId) } catch { return false } return !noGov }) .map( ({ chainId, name }): LazyDaoCardProps => ({ info: { chainId, coreAddress: name, coreVersion: ContractVersion.Gov, description: getChainGovernanceDaoDescription(chainId), imageUrl: getImageUrlForChainId(chainId), name: getDisplayNameForChainId(chainId), }, }) ) const { searchBarProps, filteredData: filteredChains } = useSearchFilter({ data: chains, filterableKeys: FILTERABLE_KEYS, }) return ( <> {filteredChains.length > 0 ? ( {filteredChains.map(({ item }) => ( ))} ) : ( )} ) } const FILTERABLE_KEYS: Fuse.FuseOptionKey[] = [ 'info.name', 'info.chainId', ]