import { Fragment, useState } from 'react' import Button 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' import ActionsLinkButton from './ActionsLinkButton' 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() const handleBorrowModal = () => { if (!connected || mangoAccount) { setShowBorrowModal(true) } else { setShowCreateAccountModal(true) } } return ( <> {mangoAccount && !connected ? null : (
{({ open }) => (
handleCopyAddress( mangoAccount!, t('copy-address-success', { pk: abbreviateAddress(mangoAccount!.publicKey), }) ) } > {t('copy-address')} setShowEditAccountModal(true)} > {t('edit-account')} setShowDelegateModal(true)} > {t('delegate-account')} setShowCloseAccountModal(true)} > {t('close-account')}
)}
)} {showCloseAccountModal ? ( setShowCloseAccountModal(false)} /> ) : null} {showEditAccountModal ? ( setShowEditAccountModal(false)} /> ) : null} {showBorrowModal ? ( setShowBorrowModal(false)} /> ) : null} {showRepayModal ? ( setShowRepayModal(false)} /> ) : null} {showDelegateModal ? ( setShowDelegateModal(false)} /> ) : null} {showCreateAccountModal ? ( setShowCreateAccountModal(false)} /> ) : null} ) } export default AccountActions