import { useState } from 'react' import { useTranslation } from 'next-i18next' import { copyToClipboard } from 'utils' import { notify } from 'utils/notifications' 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 useUnownedAccount from 'hooks/useUnownedAccount' import DepositWithdrawModal from '@components/modals/DepositWithdrawModal' import { ArrowDownRightIcon, ArrowDownTrayIcon, ArrowUpLeftIcon, ArrowUpTrayIcon, } from '@heroicons/react/20/solid' export const handleCopyAddress = ( mangoAccountAddress: string, successMessage: string, ) => { copyToClipboard(mangoAccountAddress) notify({ title: successMessage, type: 'success', }) } type ActionType = 'deposit' | 'withdraw' | 'borrow' | 'repay' const ACTION_BUTTON_CLASSES = 'flex h-10 items-center justify-center space-x-1 sm:space-x-2 font-bold focus:outline-none md:hover:bg-th-bkg-2 text-xs sm:text-sm' const ACTION_BUTTON_ICON_CLASSES = 'h-3.5 w-3.5 sm:h-5 sm:w-5' const AccountActions = () => { const { t } = useTranslation(['common', 'close-account', 'settings']) const { mangoAccountAddress } = useMangoAccount() const [modalToShow, setModalToShow] = useState('') const [showCreateAccountModal, setShowCreateAccountModal] = useState(false) const { connected } = useWallet() const { isUnownedAccount } = useUnownedAccount() const handleActionModal = (type: ActionType) => { if (mangoAccountAddress || !connected) { setModalToShow(type) } else { setShowCreateAccountModal(true) } } return ( <> {isUnownedAccount ? null : (
)} {modalToShow === 'deposit' ? ( setModalToShow('')} /> ) : null} {modalToShow === 'withdraw' ? ( setModalToShow('')} /> ) : null} {modalToShow === 'borrow' ? ( setModalToShow('')} /> ) : null} {modalToShow === 'repay' ? ( setModalToShow('')} /> ) : null} {showCreateAccountModal ? ( setShowCreateAccountModal(false)} /> ) : null} ) } export default AccountActions