/* eslint-disable react/no-array-index-key */ import type { EVMChain } from '@lifi/sdk'; import { Avatar, Box, Skeleton, Tooltip, Typography } from '@mui/material'; import { useEffect } from 'react'; import { useNavigate } from 'react-router-dom'; import type { FormTypeProps } from '../../stores'; import { FormKeyHelper, maxChainToOrder, useFieldValues } from '../../stores'; import { navigationRoutes } from '../../utils'; import { ChainCard, ChainContainer } from './ChainSelect.style'; import { useChainSelect } from './useChainSelect'; export const ChainSelect = ({ formType }: FormTypeProps) => { const navigate = useNavigate(); const { chainOrder, chains, getChains, isLoading, setChainOrder, setCurrentChain, } = useChainSelect(formType); const [chainId] = useFieldValues(FormKeyHelper.getChainKey(formType)); useEffect(() => { if (chainId) { const hasChainInOrderedList = chainOrder.includes(chainId); // If we don't have a chain in the ordered chain list we should add it. if (!hasChainInOrderedList) { setChainOrder(chainId, formType); } } }, [chainId, chainOrder, formType, setChainOrder]); const showAllChains = () => { navigate(navigationRoutes[`${formType}Chain`]); }; const chainsToHide = (chains?.length ?? 0) - maxChainToOrder; return ( {isLoading ? Array.from({ length: maxChainToOrder + 1 }).map((_, index) => ( )) : getChains().map((chain: EVMChain) => ( setCurrentChain(chain.id)} variant={chainId === chain.id ? 'selected' : 'default'} > {chain.name[0]} ))} {chainsToHide > 0 ? ( +{chainsToHide} ) : null} ); };