import { Fragment, ReactNode, useState } from 'react' import Button, { LinkButton } from '../shared/Button' import { ArrowDownRightIcon, ArrowUpLeftIcon, DocumentDuplicateIcon, PencilIcon, TrashIcon, UsersIcon, WrenchIcon, } from '@heroicons/react/20/solid' import { useTranslation } from 'next-i18next' import CloseAccountModal from '../modals/CloseAccountModal' import AccountNameModal from '../modals/AccountNameModal' import { copyToClipboard } from 'utils' import { notify } from 'utils/notifications' import { abbreviateAddress } from 'utils/formatting' import { MangoAccount } from '@blockworks-foundation/mango-v4' import DelegateModal from '@components/modals/DelegateModal' import useMangoAccount from 'hooks/useMangoAccount' import BorrowRepayModal from '@components/modals/BorrowRepayModal' import { useWallet } from '@solana/wallet-adapter-react' import CreateAccountModal from '@components/modals/CreateAccountModal' import { Menu, Transition } from '@headlessui/react' export const handleCopyAddress = ( mangoAccount: MangoAccount, successMessage: string ) => { copyToClipboard(mangoAccount.publicKey.toString()) notify({ title: successMessage, type: 'success', }) } const AccountActions = () => { const { t } = useTranslation(['common', 'close-account']) const { mangoAccount } = useMangoAccount() const [showCloseAccountModal, setShowCloseAccountModal] = useState(false) const [showEditAccountModal, setShowEditAccountModal] = useState(false) const [showBorrowModal, setShowBorrowModal] = useState(false) const [showRepayModal, setShowRepayModal] = useState(false) const [showDelegateModal, setShowDelegateModal] = useState(false) const [showCreateAccountModal, setShowCreateAccountModal] = useState(false) const { connected } = useWallet() // this doesn't work for detecting spot borrows as it includes perp liabs. was only using it to make the repay button have primary styles so could delete // const hasBorrows = useMemo(() => { // if (!mangoAccount || !group) return false // return ( // toUiDecimalsForQuote( // mangoAccount.getLiabsValue(group, HealthType.init).toNumber() // ) >= 1 // ) // }, [mangoAccount, group]) const handleBorrowModal = () => { if (!connected || mangoAccount) { setShowBorrowModal(true) } else { setShowCreateAccountModal(true) } } return ( <>