import { Fragment, useState } from 'react' import Button, { IconButton } from '../shared/Button' import { ArrowDownRightIcon, ArrowUpLeftIcon, DocumentDuplicateIcon, EyeIcon, EyeSlashIcon, 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 MangoAccountSizeModal from '@components/modals/MangoAccountSizeModal' import useMangoAccountAccounts from 'hooks/useMangoAccountAccounts' import useLocalStorageState from 'hooks/useLocalStorageState' import { PRIVACY_MODE } from 'utils/constants' 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 [privacyMode, setPrivacyMode] = useLocalStorageState(PRIVACY_MODE) const { connected } = useWallet() const { isDelegatedAccount, isUnownedAccount } = useUnownedAccount() const { isMobile } = useViewport() const { isAccountFull } = useMangoAccountAccounts() const handleBorrowModal = () => { if (mangoAccountAddress || !connected) { setShowBorrowModal(true) } else { setShowCreateAccountModal(true) } } return ( <> {isUnownedAccount ? null : (
{({ open }) => ( <> {!isMobile ? ( ) : ( )} handleCopyAddress( mangoAccount!, t('copy-address-success', { pk: abbreviateAddress(mangoAccount!.publicKey), }), ) } > {t('copy-address')} setShowEditAccountModal(true)} > {t('edit-account')} setShowDelegateModal(true)} > {t('delegate-account')} {!isAccountFull ? ( setShowAccountSizeModal(true)} > {t('settings:increase-account-slots')} ) : null} setShowCloseAccountModal(true)} > {t('close-account')} setPrivacyMode(!privacyMode)} > {privacyMode ? ( <> {t('settings:privacy-disable')} ) : ( <> {t('settings:privacy-enable')} )} )}
)} {showCloseAccountModal ? ( setShowCloseAccountModal(false)} /> ) : null} {showEditAccountModal ? ( setShowEditAccountModal(false)} /> ) : null} {showBorrowModal ? ( setShowBorrowModal(false)} /> ) : null} {showRepayModal ? ( setShowRepayModal(false)} /> ) : null} {showDelegateModal ? ( setShowDelegateModal(false)} /> ) : null} {showCreateAccountModal ? ( setShowCreateAccountModal(false)} /> ) : null} {showAccountSizeModal ? ( setShowAccountSizeModal(false)} /> ) : null} ) } export default AccountActions