import classNames from 'classnames' import { 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 { DEFAULT_SETTINGS } from 'constants/defaultSettings' import { DISPLAY_CURRENCY_KEY } from 'constants/localStore' import { BN_ZERO } from 'constants/math' import useAutoLendEnabledAccountIds from 'hooks/useAutoLendEnabledAccountIds' import useLocalStorage from 'hooks/useLocalStorage' import usePrices from 'hooks/usePrices' import useStore from 'store' import { calculateAccountBalanceValue, calculateAccountDepositsValue } from 'utils/accounts' import { hardcodedFee } from 'utils/constants' 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', ) export default function AccountList(props: Props) { const navigate = useNavigate() const { pathname } = useLocation() const { accountId, address } = useParams() const { data: prices } = usePrices() const { autoLendEnabledAccountIds, toggleAutoLend } = useAutoLendEnabledAccountIds() const deleteAccount = useStore((s) => s.deleteAccount) const accountSelected = !!accountId && !isNaN(Number(accountId)) const selectedAccountDetails = props.accounts.find((account) => account.id === accountId) const selectedAccountBalance = selectedAccountDetails ? calculateAccountBalanceValue(selectedAccountDetails, prices) : BN_ZERO async function deleteAccountHandler() { if (!accountSelected) return const isSuccess = await deleteAccount({ fee: hardcodedFee, accountId: accountId }) if (isSuccess) { navigate(getRoute(getPage(pathname), address)) } } useEffect(() => { const element = document.getElementById(`account-${accountId}`) if (element) { element.scrollIntoView({ behavior: 'smooth' }) } }, [accountId]) if (!props.accounts?.length) return null return (