import _ from 'lodash' import { memo, useEffect, useMemo, useState } from 'react' import Link from 'next/link' import { useAccount } from 'wagmi' import { Address } from 'viem' import { useTranslations } from 'next-intl' import { getPoolUrl } from '@urls' import { CHAINS_BY_ID } from '@/constants/chains' import { usePortfolioState } from '@/slices/portfolio/hooks' import { RightArrow } from '@/components/icons/RightArrow' import { Token } from '@/utils/types' export const PoolHeader = memo( ({ pool, address }: { pool: Token; address: Address }) => { const [mounted, setMounted] = useState(false) const { chain: connectedChain } = useAccount() const chain = CHAINS_BY_ID[pool.chainId] const { balances } = usePortfolioState() const t = useTranslations('Pools') useEffect(() => { setMounted(true) }, []) const canDeposit = useMemo(() => { const balancesForChain = _(balances[pool.chainId]) .pickBy((value, _key) => value.balance > 0n) .value() if (Object.keys(balancesForChain).length === 0) return false if (!address) { return null } return _.some(pool.nativeTokens, (poolToken) => { const poolAddress = _.get(poolToken, `addresses.${pool.chainId}`) return _.some(balancesForChain, (balance) => { return ( poolAddress === _.get(balance, `token.addresses.${pool.chainId}`) ) }) }) }, [pool, balances, address]) return (
{chain?.name}
{pool.symbol}
{mounted && connectedChain && connectedChain.id === pool.chainId && ( )}
{canDeposit && pool.incentivized ? (
{t('Deposit')}
) : (
)}
) } ) const ConnectedIndicator = () => { const t = useTranslations('Wallet') return (
{t('Connected')}
) }