/* eslint-disable i18next/no-literal-string */ import { Check, CopyAllOutlined } from '@mui/icons-material' import clsx from 'clsx' import { useEffect, useState } from 'react' import { useTranslation } from 'react-i18next' import { EntityDisplayProps, EntityType } from '@dao-dao/types' import { abbreviateAddress, getFallbackImage, toAccessibleImageUrl, } from '@dao-dao/utils' import { useChainContext } from '../contexts' import { useDaoNavHelpers, useDetectTruncate } from '../hooks' import { ButtonLink } from './buttons' import { IconButton } from './icon_buttons' import { Tooltip } from './tooltip/Tooltip' export const EntityDisplay = ({ address, loadingEntity, imageSize, hideImage, size = 'default', className, textClassName, noCopy, noUnderline, showFullAddress, noLink, openInNewTab, }: EntityDisplayProps) => { const { t } = useTranslation() const { getDaoPath } = useDaoNavHelpers() const { config } = useChainContext() imageSize ??= size === 'lg' ? 28 : 24 const [copied, setCopied] = useState(false) // Unset copied after 2 seconds. useEffect(() => { const timeout = setTimeout(() => setCopied(false), 2000) // Cleanup on unmount. return () => clearTimeout(timeout) }, [copied]) const href = loadingEntity.loading ? undefined : loadingEntity.data.type === EntityType.Dao ? getDaoPath(loadingEntity.data.address) : loadingEntity.data.type === EntityType.Wallet ? config?.explorerUrlTemplates?.wallet?.replace( 'REPLACE', loadingEntity.data.address ) : undefined const { textRef, truncated } = useDetectTruncate() // If name exists, use it. Otherwise, fallback to address, potentially // truncated. const textDisplay = !loadingEntity.loading && loadingEntity.data.name ? loadingEntity.data.type === EntityType.Module && TRANSLATED_CHAIN_MODULES.includes(loadingEntity.data.name) ? t('title.chainModule.' + loadingEntity.data.name) : loadingEntity.data.name : showFullAddress ? address : abbreviateAddress(address, 3) return (
{textDisplay}