import React, { useContext } from 'react'; import PropTypes from 'prop-types'; import { AvatarNetwork, AvatarNetworkSize, Box, Text, } from '../../component-library'; import { AlignItems, BackgroundColor, BlockSize, Display, FlexDirection, JustifyContent, TextColor, TextVariant, } from '../../../helpers/constants/design-system'; import Tooltip from '../../ui/tooltip'; import ToggleButton from '../../ui/toggle-button'; import { I18nContext } from '../../../contexts/i18n'; const MAXIMUM_CHARACTERS_WITHOUT_TOOLTIP = 20; interface NetworkPreferences { isShowIncomingTransactions: boolean; label: string; imageUrl: string; } interface NetworkToggleProps { networkPreferences: NetworkPreferences; toggleSingleNetwork: (chainId: string, value: boolean) => void; chainId: string; } const NetworkToggle = ({ networkPreferences, toggleSingleNetwork, chainId, }: NetworkToggleProps) => { const t = useContext(I18nContext); const { isShowIncomingTransactions } = networkPreferences; const networkName = networkPreferences.label; return ( {networkName.length > MAXIMUM_CHARACTERS_WITHOUT_TOOLTIP ? ( {networkName} ) : ( networkName )} toggleSingleNetwork(chainId, !value)} offLabel={t('off')} onLabel={t('on')} /> ); }; export default NetworkToggle; NetworkToggle.propTypes = { chainId: PropTypes.string.isRequired, networkPreferences: PropTypes.object.isRequired, toggleSingleNetwork: PropTypes.func.isRequired, };