2021-05-17 22:33:04 -07:00
|
|
|
import { useState } from 'react'
|
|
|
|
import { MenuIcon, XIcon } from '@heroicons/react/outline'
|
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 { ChevronUpIcon, ChevronDownIcon } from '@heroicons/react/solid'
|
|
|
|
import { Menu } from '@headlessui/react'
|
|
|
|
import Link from 'next/link'
|
|
|
|
import { useRouter } from 'next/router'
|
2021-03-30 15:47:08 -07:00
|
|
|
import MenuItem from './MenuItem'
|
2021-04-12 06:32:01 -07:00
|
|
|
import ThemeSwitch from './ThemeSwitch'
|
2021-04-14 15:46:36 -07:00
|
|
|
import useMangoStore from '../stores/useMangoStore'
|
2021-04-18 18:58:16 -07:00
|
|
|
import ConnectWalletButton from './ConnectWalletButton'
|
2021-05-07 12:41:26 -07:00
|
|
|
import AlertsList from './AlertsList'
|
2021-03-30 15:47:08 -07:00
|
|
|
|
2021-04-05 07:32:11 -07:00
|
|
|
const TopBar = () => {
|
2021-04-14 15:46:36 -07:00
|
|
|
const connected = useMangoStore((s) => s.wallet.connected)
|
|
|
|
const wallet = useMangoStore((s) => s.wallet.current)
|
2021-03-30 15:47:08 -07:00
|
|
|
const [showMenu, setShowMenu] = useState(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
|
|
|
const { asPath } = useRouter()
|
2021-03-30 15:47:08 -07:00
|
|
|
|
|
|
|
return (
|
2021-05-17 22:33:04 -07:00
|
|
|
<>
|
2021-05-18 03:57:10 -07:00
|
|
|
<nav className={`bg-th-bkg-2 border-b border-th-bkg-2`}>
|
2021-05-17 22:33:04 -07:00
|
|
|
<div className={`px-6 md:px-9`}>
|
|
|
|
<div className={`flex justify-between h-14`}>
|
|
|
|
<div className={`flex`}>
|
|
|
|
<div className={`flex-shrink-0 flex items-center`}>
|
|
|
|
<img
|
|
|
|
className={`h-8 w-auto`}
|
|
|
|
src="/assets/icons/logo.svg"
|
|
|
|
alt="next"
|
|
|
|
/>
|
|
|
|
</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
|
|
|
<div
|
|
|
|
className={`hidden md:flex md:items-center md:space-x-6 md:ml-4 py-2`}
|
|
|
|
>
|
2021-05-17 22:33:04 -07:00
|
|
|
<MenuItem href="/">Trade</MenuItem>
|
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
|
|
|
<MenuItem href="/account">Account</MenuItem>
|
|
|
|
<MenuItem href="/borrow">Borrow</MenuItem>
|
2021-05-17 22:33:04 -07:00
|
|
|
<MenuItem href="/alerts">Alerts</MenuItem>
|
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>
|
|
|
|
{({ open }) => (
|
|
|
|
<div className="relative">
|
|
|
|
<Menu.Button className="flex items-center hover:text-th-primary focus:outline-none">
|
|
|
|
More
|
|
|
|
<div className="pl-1">
|
|
|
|
{open ? (
|
|
|
|
<ChevronUpIcon className="h-5 w-5" />
|
|
|
|
) : (
|
|
|
|
<ChevronDownIcon className="h-5 w-5" />
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
</Menu.Button>
|
|
|
|
<Menu.Items className="absolute z-10 mt-4 p-1 right-0 md:transform md:-translate-x-1/2 md:left-1/2 w-24 bg-th-bkg-1 divide-y divide-th-bkg-3 shadow-lg outline-none rounded-md">
|
|
|
|
<Menu.Item>
|
|
|
|
<Link href="/stats">
|
|
|
|
<a
|
|
|
|
className={`block text-th-fgd-1 font-bold items-center p-2 hover:text-th-primary hover:opacity-100
|
|
|
|
${
|
|
|
|
asPath === '/stats'
|
|
|
|
? `text-th-primary`
|
|
|
|
: `border-transparent hover:border-th-primary`
|
|
|
|
}
|
|
|
|
`}
|
|
|
|
>
|
|
|
|
Stats
|
|
|
|
</a>
|
|
|
|
</Link>
|
|
|
|
</Menu.Item>
|
|
|
|
<Menu.Item>
|
|
|
|
<Link href="https://docs.mango.markets/">
|
|
|
|
<a
|
|
|
|
className={`block text-th-fgd-1 font-bold items-center p-2 hover:text-th-primary hover:opacity-100`}
|
|
|
|
>
|
|
|
|
Learn
|
|
|
|
</a>
|
|
|
|
</Link>
|
|
|
|
</Menu.Item>
|
|
|
|
</Menu.Items>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</Menu>
|
2021-05-17 22:33:04 -07:00
|
|
|
</div>
|
2021-03-30 15:47:08 -07:00
|
|
|
</div>
|
2021-04-19 06:45:59 -07:00
|
|
|
<div className="flex items-center">
|
2021-05-17 22:33:04 -07:00
|
|
|
<div className={`pl-2`}>
|
2021-04-19 06:45:59 -07:00
|
|
|
<ThemeSwitch />
|
|
|
|
</div>
|
2021-05-07 12:41:26 -07:00
|
|
|
{connected ? (
|
2021-05-17 22:33:04 -07:00
|
|
|
<div className="pl-2">
|
2021-05-07 12:41:26 -07:00
|
|
|
<AlertsList />
|
|
|
|
</div>
|
|
|
|
) : null}
|
2021-05-17 22:33:04 -07:00
|
|
|
<div className="flex">
|
|
|
|
<div className="hidden md:block pl-4">
|
2021-04-18 18:58:16 -07:00
|
|
|
<ConnectWalletButton />
|
2021-05-17 22:33:04 -07:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div className={`-mr-2 ml-2 flex items-center md:hidden`}>
|
|
|
|
<button
|
|
|
|
type="button"
|
|
|
|
className={`inline-flex items-center justify-center p-2 rounded-md text-black dark:text-white hover:text-gray-400 focus:outline-none focus:ring-2 focus:ring-inset focus:ring-mango-orange`}
|
|
|
|
aria-controls="mobile-menu"
|
|
|
|
aria-expanded="false"
|
|
|
|
onClick={() => setShowMenu((showMenu) => !showMenu)}
|
|
|
|
>
|
|
|
|
<span className="sr-only">Open main menu</span>
|
|
|
|
{showMenu ? (
|
|
|
|
<XIcon className="h-5 w-5 text-th-primary" />
|
|
|
|
) : (
|
|
|
|
<MenuIcon className="h-5 w-5 text-th-primary" />
|
|
|
|
)}
|
|
|
|
</button>
|
2021-04-11 14:25:01 -07:00
|
|
|
</div>
|
|
|
|
</div>
|
2021-03-30 15:47:08 -07:00
|
|
|
</div>
|
|
|
|
</div>
|
2021-04-12 09:49:02 -07:00
|
|
|
<div
|
2021-05-17 22:33:04 -07:00
|
|
|
className={`${showMenu ? `visible` : `hidden`} md:hidden`}
|
|
|
|
id="mobile-menu"
|
2021-04-12 09:49:02 -07:00
|
|
|
>
|
2021-05-17 22:33:04 -07:00
|
|
|
<div
|
|
|
|
className={`bg-th-bkg-3 pt-2 pb-3 space-y-1 border-b border-th-fgd-4`}
|
|
|
|
>
|
|
|
|
<MenuItem href="/">Trade</MenuItem>
|
|
|
|
<MenuItem href="/stats">Stats</MenuItem>
|
|
|
|
<MenuItem href="/alerts">Alerts</MenuItem>
|
|
|
|
<MenuItem href="https://docs.mango.markets/">Learn</MenuItem>
|
2021-04-22 08:00:13 -07:00
|
|
|
|
2021-05-17 22:33:04 -07:00
|
|
|
{connected && wallet?.publicKey ? (
|
|
|
|
<button
|
|
|
|
className="block text-th-fgd-1 text-base items-center pl-3 pr-4 py-2 font-normal
|
2021-05-07 12:41:26 -07:00
|
|
|
md:inline-flex md:ml-4 md:px-1 md:py-0 border-l-4 md:border-l-0 md:border-b-2 hover:text-th-primary
|
2021-04-22 08:00:13 -07:00
|
|
|
border-transparent hover:border-th-primary rounded-none outline-none focus:outline-none"
|
2021-05-17 22:33:04 -07:00
|
|
|
onClick={() => wallet.disconnect()}
|
|
|
|
>
|
|
|
|
Disconnect
|
|
|
|
</button>
|
|
|
|
) : (
|
|
|
|
<button
|
|
|
|
className="block text-th-fgd-1 text-base items-center pl-3 pr-4 py-2 font-normal
|
2021-05-07 12:41:26 -07:00
|
|
|
md:inline-flex md:ml-4 md:px-1 md:py-0 border-l-4 md:border-l-0 md:border-b-2 hover:text-th-primary
|
2021-04-22 08:00:13 -07:00
|
|
|
border-transparent hover:border-th-primary rounded-none outline-none focus:outline-none"
|
2021-05-17 22:33:04 -07:00
|
|
|
onClick={() => wallet.connect()}
|
|
|
|
>
|
|
|
|
Connect
|
|
|
|
</button>
|
|
|
|
)}
|
|
|
|
</div>
|
2021-03-30 15:47:08 -07:00
|
|
|
</div>
|
2021-05-17 22:33:04 -07:00
|
|
|
</nav>
|
|
|
|
</>
|
2021-03-30 15:47:08 -07:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export default TopBar
|