2021-06-17 11:03:47 -07:00
|
|
|
import { useCallback, useState } from 'react'
|
User account page (#22)
* layout, overview, start on assets, borrows and open orders
* trade history, sortable data hook for tables, borrow page
* handle deposit and withdraw buttons
* borrow modal ui and integration + settle borrow for individual assets
* in orders balance to asset table and totals, responsive css, new connected wallet button + small tweaks
* account switch/creation flow
* accounts modal, update to usebalances hook
* handle settle, deposit before settle, save last account
* disable borrow/withdraw button when no account
2021-06-05 07:11:44 -07:00
|
|
|
import Link from 'next/link'
|
|
|
|
import { Menu } from '@headlessui/react'
|
|
|
|
import { DotsHorizontalIcon } from '@heroicons/react/outline'
|
2021-04-09 07:27:49 -07:00
|
|
|
import FloatingElement from './FloatingElement'
|
2021-04-10 12:21:02 -07:00
|
|
|
import { ElementTitle } from './styles'
|
2021-04-09 07:27:49 -07:00
|
|
|
import useMangoStore from '../stores/useMangoStore'
|
2021-06-17 11:03:47 -07:00
|
|
|
import DepositModal from './DepositModal'
|
|
|
|
import WithdrawModal from './WithdrawModal'
|
2021-07-29 06:19:32 -07:00
|
|
|
import Button, { IconButton } from './Button'
|
2021-07-06 15:04:20 -07:00
|
|
|
import AccountsModal from './AccountsModal'
|
2021-04-09 07:27:49 -07:00
|
|
|
|
2021-04-14 23:16:36 -07:00
|
|
|
export default function MarginBalances() {
|
2021-07-29 12:05:16 -07:00
|
|
|
const mangoAccount = useMangoStore((s) => s.selectedMangoAccount.current)
|
2021-06-23 08:32:33 -07:00
|
|
|
const loadingMangoAccount = useMangoStore(
|
|
|
|
(s) => s.selectedMangoAccount.initialLoad
|
2021-06-17 11:03:47 -07:00
|
|
|
)
|
2021-04-10 12:21:02 -07:00
|
|
|
const connected = useMangoStore((s) => s.wallet.connected)
|
2021-06-17 11:03:47 -07:00
|
|
|
const [showDepositModal, setShowDepositModal] = useState(false)
|
|
|
|
const [showWithdrawModal, setShowWithdrawModal] = useState(false)
|
2021-07-06 15:04:20 -07:00
|
|
|
const [showAccountsModal, setShowAccountsModal] = useState(false)
|
2021-04-25 22:20:05 -07:00
|
|
|
|
2021-04-09 07:27:49 -07:00
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<FloatingElement>
|
2021-07-26 07:33:40 -07:00
|
|
|
<div className="flex justify-center">
|
2021-07-29 12:05:16 -07:00
|
|
|
<ElementTitle noMarignBottom>
|
2021-07-30 13:37:00 -07:00
|
|
|
{mangoAccount?.name || 'Mango Account'}
|
2021-07-29 12:05:16 -07:00
|
|
|
</ElementTitle>
|
2021-07-26 07:33:40 -07:00
|
|
|
<div className="absolute right-0 pr-4">
|
|
|
|
<Menu>
|
2021-07-29 06:19:32 -07:00
|
|
|
<Menu.Button disabled={!connected}>
|
2021-07-30 03:30:58 -07:00
|
|
|
<div className="bg-th-bkg-4 flex items-center justify-center rounded-full w-8 h-8 text-th-fgd-1 focus:outline-none hover:text-th-primary">
|
2021-07-29 06:19:32 -07:00
|
|
|
<DotsHorizontalIcon className="w-5 h-5" />
|
2021-07-30 03:30:58 -07:00
|
|
|
</div>
|
User account page (#22)
* layout, overview, start on assets, borrows and open orders
* trade history, sortable data hook for tables, borrow page
* handle deposit and withdraw buttons
* borrow modal ui and integration + settle borrow for individual assets
* in orders balance to asset table and totals, responsive css, new connected wallet button + small tweaks
* account switch/creation flow
* accounts modal, update to usebalances hook
* handle settle, deposit before settle, save last account
* disable borrow/withdraw button when no account
2021-06-05 07:11:44 -07:00
|
|
|
</Menu.Button>
|
2021-07-06 15:04:20 -07:00
|
|
|
<Menu.Items className="bg-th-bkg-1 mt-2 p-1 absolute right-0 shadow-lg outline-none rounded-md w-48 z-20">
|
User account page (#22)
* layout, overview, start on assets, borrows and open orders
* trade history, sortable data hook for tables, borrow page
* handle deposit and withdraw buttons
* borrow modal ui and integration + settle borrow for individual assets
* in orders balance to asset table and totals, responsive css, new connected wallet button + small tweaks
* account switch/creation flow
* accounts modal, update to usebalances hook
* handle settle, deposit before settle, save last account
* disable borrow/withdraw button when no account
2021-06-05 07:11:44 -07:00
|
|
|
<Menu.Item>
|
|
|
|
<button
|
|
|
|
className="flex flex-row font-normal items-center rounded-none w-full p-2 hover:bg-th-bkg-2 hover:cursor-pointer focus:outline-none"
|
|
|
|
onClick={() => setShowAccountsModal(true)}
|
|
|
|
>
|
|
|
|
<div className="pl-2 text-left">Change Account</div>
|
|
|
|
</button>
|
|
|
|
</Menu.Item>
|
2021-07-06 15:04:20 -07:00
|
|
|
</Menu.Items>
|
2021-07-26 07:33:40 -07:00
|
|
|
</Menu>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div className="flex justify-center mt-2">
|
2021-07-29 12:05:16 -07:00
|
|
|
{mangoAccount ? (
|
2021-07-26 07:33:40 -07:00
|
|
|
<Link href={'/account'}>
|
|
|
|
<a className="pt-1 text-th-fgd-3 text-xs underline hover:no-underline">
|
2021-07-29 12:05:16 -07:00
|
|
|
{mangoAccount?.publicKey.toString()}
|
2021-07-26 07:33:40 -07:00
|
|
|
</a>
|
|
|
|
</Link>
|
|
|
|
) : connected ? (
|
|
|
|
<div className="pt-1 text-th-fgd-3">
|
|
|
|
Deposit funds to get started
|
2021-04-16 11:16:31 -07:00
|
|
|
</div>
|
2021-07-26 07:33:40 -07:00
|
|
|
) : null}
|
2021-04-25 22:20:05 -07:00
|
|
|
</div>
|
2021-07-26 07:33:40 -07:00
|
|
|
<div className="flex justify-center items-center mt-2">
|
2021-06-17 11:03:47 -07:00
|
|
|
<Button
|
2021-06-05 09:14:34 -07:00
|
|
|
onClick={() => setShowDepositModal(true)}
|
|
|
|
className="w-1/2"
|
2021-06-23 08:32:33 -07:00
|
|
|
disabled={!connected || loadingMangoAccount}
|
2021-06-05 09:14:34 -07:00
|
|
|
>
|
|
|
|
<span>Deposit</span>
|
|
|
|
</Button>
|
|
|
|
<Button
|
|
|
|
onClick={() => setShowWithdrawModal(true)}
|
|
|
|
className="ml-4 w-1/2"
|
2021-07-29 12:05:16 -07:00
|
|
|
disabled={!connected || !mangoAccount || loadingMangoAccount}
|
2021-06-05 09:14:34 -07:00
|
|
|
>
|
|
|
|
<span>Withdraw</span>
|
2021-06-17 11:03:47 -07:00
|
|
|
</Button>
|
2021-06-05 09:14:34 -07:00
|
|
|
</div>
|
2021-04-09 07:27:49 -07:00
|
|
|
</FloatingElement>
|
2021-06-17 11:03:47 -07:00
|
|
|
{showDepositModal && (
|
2021-07-29 12:05:16 -07:00
|
|
|
<DepositModal
|
|
|
|
isOpen={showDepositModal}
|
|
|
|
onClose={() => setShowDepositModal(false)}
|
|
|
|
/>
|
2021-04-09 07:27:49 -07:00
|
|
|
)}
|
|
|
|
{showWithdrawModal && (
|
2021-04-10 14:12:15 -07:00
|
|
|
<WithdrawModal
|
2021-04-09 07:27:49 -07:00
|
|
|
isOpen={showWithdrawModal}
|
2021-07-29 12:05:16 -07:00
|
|
|
onClose={() => setShowWithdrawModal(false)}
|
2021-04-09 07:27:49 -07:00
|
|
|
/>
|
|
|
|
)}
|
User account page (#22)
* layout, overview, start on assets, borrows and open orders
* trade history, sortable data hook for tables, borrow page
* handle deposit and withdraw buttons
* borrow modal ui and integration + settle borrow for individual assets
* in orders balance to asset table and totals, responsive css, new connected wallet button + small tweaks
* account switch/creation flow
* accounts modal, update to usebalances hook
* handle settle, deposit before settle, save last account
* disable borrow/withdraw button when no account
2021-06-05 07:11:44 -07:00
|
|
|
{showAccountsModal ? (
|
|
|
|
<AccountsModal
|
2021-07-29 12:05:16 -07:00
|
|
|
onClose={() => setShowAccountsModal(false)}
|
User account page (#22)
* layout, overview, start on assets, borrows and open orders
* trade history, sortable data hook for tables, borrow page
* handle deposit and withdraw buttons
* borrow modal ui and integration + settle borrow for individual assets
* in orders balance to asset table and totals, responsive css, new connected wallet button + small tweaks
* account switch/creation flow
* accounts modal, update to usebalances hook
* handle settle, deposit before settle, save last account
* disable borrow/withdraw button when no account
2021-06-05 07:11:44 -07:00
|
|
|
isOpen={showAccountsModal}
|
|
|
|
/>
|
2021-07-06 15:04:20 -07:00
|
|
|
) : null}
|
2021-04-16 11:16:31 -07:00
|
|
|
</>
|
|
|
|
)
|
|
|
|
}
|