import React, { useEffect, useRef } from 'react'; import classnames from 'classnames'; import PropTypes from 'prop-types'; import { AlignItems, IconColor, BorderRadius, Color, Size, JustifyContent, TextColor, BackgroundColor, BlockSize, Display, } from '../../../helpers/constants/design-system'; import { AvatarNetwork, ButtonIcon, Text, IconName, Box, } from '../../component-library'; import { useI18nContext } from '../../../hooks/useI18nContext'; import Tooltip from '../../ui/tooltip/tooltip'; import { GOERLI_DISPLAY_NAME, LINEA_GOERLI_DISPLAY_NAME, SEPOLIA_DISPLAY_NAME, } from '../../../../shared/constants/network'; const MAXIMUM_CHARACTERS_WITHOUT_TOOLTIP = 20; function getAvatarNetworkColor(name) { switch (name) { case GOERLI_DISPLAY_NAME: return BackgroundColor.goerli; case LINEA_GOERLI_DISPLAY_NAME: return BackgroundColor.lineaGoerli; case SEPOLIA_DISPLAY_NAME: return BackgroundColor.sepolia; default: return undefined; } } export const NetworkListItem = ({ name, iconSrc, selected = false, onClick, onDeleteClick, }) => { const t = useI18nContext(); const networkRef = useRef(); useEffect(() => { if (networkRef.current && selected) { networkRef.current.focus(); } }, [networkRef, selected]); return ( {selected && ( )} { e.stopPropagation(); onClick(); }} color={TextColor.textDefault} backgroundColor={BackgroundColor.transparent} ellipsis > {name.length > MAXIMUM_CHARACTERS_WITHOUT_TOOLTIP ? ( {name} ) : ( name )} {onDeleteClick ? ( { e.stopPropagation(); onDeleteClick(); }} /> ) : null} ); }; NetworkListItem.propTypes = { /** * The name of the network */ name: PropTypes.string.isRequired, /** * Path to the Icon image */ iconSrc: PropTypes.string, /** * Represents if the network item is selected */ selected: PropTypes.bool, /** * Executes when the item is clicked */ onClick: PropTypes.func.isRequired, /** * Executes when the delete icon is clicked */ onDeleteClick: PropTypes.func, };