import _ from 'lodash' import Link from 'next/link' import { useEffect, useMemo, useState, memo } from 'react' import { useAccount } from 'wagmi' import { type Address } from 'viem' import { LoaderIcon, toast } from 'react-hot-toast' import { useTranslations } from 'next-intl' import { useAppSelector } from '@/store/hooks' import { usePortfolioState } from '@/slices/portfolio/hooks' import { getSinglePoolData } from '@utils/actions/getPoolData' import { getPoolApyData } from '@utils/actions/getPoolApyData' import { getStakedBalance } from '@/utils/actions/getStakedBalance' import { formatBigIntToString } from '@/utils/bigint/format' import { PoolActionOptions } from '../../components/Pools/PoolActionOptions' import { PoolHeader } from '../../components/Pools/PoolHeader' import { PoolCardBody } from '../../components/Pools/PoolCardBody' import { STAKE_PATH, getPoolUrl } from '@urls' import { Token } from '@types' const PoolCard = memo(({ pool, address }: { pool: Token; address: string }) => { const [isClient, setIsClient] = useState(false) const [poolData, setPoolData] = useState(undefined) const [poolApyData, setPoolApyData] = useState(undefined) const [stakedBalance, setStakedBalance] = useState({ amount: 0n, reward: 0n, }) const { isDisconnected } = useAccount() const { synPrices, ethPrice, avaxPrice, metisPrice } = useAppSelector( (state) => state.priceData ) const prices = { synPrices, ethPrice, avaxPrice, metisPrice } let popup: string useEffect(() => { setIsClient(true) }, []) useEffect(() => { if (pool && isClient) { // TODO - separate the apy and tvl so they load async. getSinglePoolData(pool.chainId, pool, prices) .then((res) => { setPoolData(res) }) .catch((err) => { console.log('Could not get Pool Data: ', err) }) getPoolApyData(pool.chainId, pool, prices) .then((res) => { setPoolApyData(res) }) .catch((err) => { console.log('Could not get Pool APY Data: ', err) }) } }, [pool, isClient]) useEffect(() => { if (address && isClient) { getStakedBalance( address as Address, pool.chainId, pool.poolId[pool.chainId], pool ) .then((res) => { setStakedBalance(res) }) .catch((err) => { console.log('Could not get staked balances: ', err) }) } else { setStakedBalance({ amount: 0n, reward: 0n }) } }, [address, isClient]) /* useEffect triggers: address, isDisconnected, popup - will dismiss toast asking user to connect wallet once wallet has been connected */ useEffect(() => { if (address && !isDisconnected && popup) { toast.dismiss(popup) } }, [address, isDisconnected, popup]) return (