import classNames from 'classnames' import { useCallback, useEffect } from 'react' import { useLocation, useNavigate, useParams } from 'react-router-dom' import AccountFundFirst from 'components/Account/AccountFund' import AccountStats from 'components/Account/AccountStats' import Button from 'components/Button' import Card from 'components/Card' import { ArrowCircledTopRight, ArrowDownLine, ArrowUpLine, TrashBin } from 'components/Icons' import Radio from 'components/Radio' import SwitchWithLabel from 'components/SwitchWithLabel' import Text from 'components/Text' import useAutoLendEnabledAccountIds from 'hooks/useAutoLendEnabledAccountIds' import useCurrentAccount from 'hooks/useCurrentAccount' import usePrices from 'hooks/usePrices' import useStore from 'store' import { calculateAccountValue } from 'utils/accounts' import { getPage, getRoute } from 'utils/route' interface Props { accounts: Account[] } const accountCardHeaderClasses = classNames( 'flex w-full items-center justify-between bg-white/20 px-4 py-2.5 text-white/70', 'border border-transparent border-b-white/20', 'group-hover/account:bg-white/30', ) export default function AccountList(props: Props) { const navigate = useNavigate() const { pathname } = useLocation() const { address } = useParams() const { data: prices } = usePrices() const { autoLendEnabledAccountIds, toggleAutoLend } = useAutoLendEnabledAccountIds() const account = useCurrentAccount() const accountId = account?.id const deleteAccountHandler = useCallback(() => { if (!account) return useStore.setState({ accountDeleteModal: account }) }, [account]) useEffect(() => { if (!accountId) return const element = document.getElementById(`account-${accountId}`) if (element) { element.scrollIntoView({ behavior: 'smooth' }) } }, [accountId]) if (!props.accounts?.length) return null return (
{props.accounts.map((account) => { const positionBalance = calculateAccountValue('deposits', account, prices) const isActive = accountId === account.id const isAutoLendEnabled = autoLendEnabledAccountIds.includes(account.id) return (
{ if (isActive) return useStore.setState({ accountDeleteModal: null }) navigate(getRoute(getPage(pathname), address, account.id)) }} title={
Credit Account {account.id}
} > {isActive ? ( <>
) : (
)}
) })}
) }