mango-v4-ui/components/account/AccountActions.tsx

78 lines
2.4 KiB
TypeScript
Raw Normal View History

2022-06-21 03:58:57 -07:00
import { useWallet } from '@solana/wallet-adapter-react'
2022-07-15 04:09:23 -07:00
import { Fragment, useState } from 'react'
import Button, { LinkButton } from '../shared/Button'
2022-07-14 22:20:20 -07:00
import DepositModal from '../modals/DepositModal'
import WithdrawModal from '../modals/WithdrawModal'
import mangoStore from '../../store/state'
2022-07-15 04:09:23 -07:00
import { Popover, Transition } from '@headlessui/react'
import { DotsHorizontalIcon, TrashIcon, XIcon } from '@heroicons/react/solid'
import { useTranslation } from 'next-i18next'
2022-07-24 04:48:55 -07:00
import IconDropMenu from '../shared/IconDropMenu'
2022-06-21 03:58:57 -07:00
const AccountActions = () => {
2022-07-15 04:09:23 -07:00
const { t } = useTranslation(['common', 'close-account'])
2022-06-21 03:58:57 -07:00
const { connected } = useWallet()
const [showDepositModal, setShowDepositModal] = useState(false)
const [showWithdrawModal, setShowWithdrawModal] = useState(false)
2022-07-05 20:37:49 -07:00
const handleCloseMangoAccount = async () => {
const client = mangoStore.getState().client
2022-07-27 23:35:18 -07:00
const mangoAccount = mangoStore.getState().mangoAccount.current
2022-07-06 06:46:16 -07:00
const group = mangoStore.getState().group
if (!mangoAccount || !group) return
2022-07-05 20:37:49 -07:00
try {
2022-07-06 06:46:16 -07:00
const tx = await client.closeMangoAccount(group, mangoAccount)
2022-07-05 20:37:49 -07:00
console.log('success:', tx)
} catch (e) {
console.log(e)
}
}
2022-06-21 03:58:57 -07:00
return (
2022-07-12 19:02:36 -07:00
<>
2022-07-15 04:09:23 -07:00
<div className="flex space-x-3">
2022-07-20 21:50:56 -07:00
<Button
disabled={!connected}
onClick={() => setShowDepositModal(true)}
size="large"
>
2022-07-15 04:09:23 -07:00
{t('deposit')}
2022-07-12 20:58:13 -07:00
</Button>
<Button
disabled={!connected}
onClick={() => setShowWithdrawModal(true)}
2022-07-15 04:09:23 -07:00
secondary
2022-07-20 21:50:56 -07:00
size="large"
2022-07-12 20:58:13 -07:00
>
2022-07-15 04:09:23 -07:00
{t('withdraw')}
2022-07-12 20:58:13 -07:00
</Button>
2022-07-24 04:48:55 -07:00
<IconDropMenu icon={<DotsHorizontalIcon className="h-5 w-5" />} large>
<LinkButton
className="flex items-center whitespace-nowrap"
disabled={!connected}
onClick={handleCloseMangoAccount}
>
<TrashIcon className="mr-2 h-5 w-5" />
{t('close-account')}
</LinkButton>
</IconDropMenu>
2022-06-21 03:58:57 -07:00
</div>
{showDepositModal ? (
<DepositModal
isOpen={showDepositModal}
onClose={() => setShowDepositModal(false)}
/>
) : null}
{showWithdrawModal ? (
<WithdrawModal
isOpen={showWithdrawModal}
onClose={() => setShowWithdrawModal(false)}
/>
) : null}
2022-07-12 19:02:36 -07:00
</>
2022-06-21 03:58:57 -07:00
)
}
export default AccountActions