import { Fragment, useState } from 'react' import Button, { IconButton } from '../shared/Button' import { ArrowDownRightIcon, ArrowUpLeftIcon, DocumentDuplicateIcon, PencilIcon, SquaresPlusIcon, TrashIcon, UserPlusIcon, 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 { Popover, Transition } from '@headlessui/react' import ActionsLinkButton from './ActionsLinkButton' import useUnownedAccount from 'hooks/useUnownedAccount' import { useViewport } from 'hooks/useViewport' import { breakpoints } from 'utils/theme' import MangoAccountSizeModal from '@components/modals/MangoAccountSizeModal' export const handleCopyAddress = ( mangoAccount: MangoAccount, successMessage: string, ) => { copyToClipboard(mangoAccount.publicKey.toString()) notify({ title: successMessage, type: 'success', }) } const AccountActions = () => { const { t } = useTranslation(['common', 'close-account', 'settings']) const { mangoAccount, mangoAccountAddress } = 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 [showAccountSizeModal, setShowAccountSizeModal] = useState(false) const { connected } = useWallet() const { isDelegatedAccount, isUnownedAccount } = useUnownedAccount() const { width } = useViewport() const isMobile = width ? width < breakpoints.sm : false const handleBorrowModal = () => { if (mangoAccountAddress || !connected) { setShowBorrowModal(true) } else { setShowCreateAccountModal(true) } } return ( <> {isUnownedAccount ? null : (