2021-03-30 15:47:08 -07:00
|
|
|
import { useState } from 'react'
|
2021-04-05 07:32:11 -07:00
|
|
|
import styled from '@emotion/styled'
|
2021-04-12 09:20:17 -07:00
|
|
|
import { MenuIcon, XIcon } from '@heroicons/react/outline'
|
2021-03-30 15:47:08 -07:00
|
|
|
import MenuItem from './MenuItem'
|
2021-04-02 11:26:21 -07:00
|
|
|
import useWallet from '../hooks/useWallet'
|
2021-04-12 06:32:01 -07:00
|
|
|
import ThemeSwitch from './ThemeSwitch'
|
2021-03-30 15:47:08 -07:00
|
|
|
|
2021-04-05 07:32:11 -07:00
|
|
|
const Code = styled.code`
|
|
|
|
border: 1px solid hsla(0, 0%, 39.2%, 0.2);
|
|
|
|
border-radius: 3px;
|
|
|
|
background: hsla(0, 0%, 58.8%, 0.1);
|
|
|
|
`
|
2021-04-02 11:26:21 -07:00
|
|
|
|
2021-04-05 07:32:11 -07:00
|
|
|
const TopBar = () => {
|
2021-04-02 11:26:21 -07:00
|
|
|
const { connected, wallet } = useWallet()
|
2021-03-30 15:47:08 -07:00
|
|
|
const [showMenu, setShowMenu] = useState(false)
|
|
|
|
|
2021-04-02 11:26:21 -07:00
|
|
|
const handleConnectDisconnect = () => {
|
2021-03-30 15:47:08 -07:00
|
|
|
connected ? wallet.disconnect() : wallet.connect()
|
2021-04-02 11:26:21 -07:00
|
|
|
}
|
2021-03-30 15:47:08 -07:00
|
|
|
|
|
|
|
return (
|
2021-04-12 09:49:02 -07:00
|
|
|
<nav className={`bg-th-bkg-1`}>
|
|
|
|
<div className={`px-4 sm:px-6 lg:px-8`}>
|
|
|
|
<div className={`flex justify-between h-16`}>
|
|
|
|
<div className={`flex`}>
|
|
|
|
<div className={`flex-shrink-0 flex items-center ml-2`}>
|
2021-03-30 15:47:08 -07:00
|
|
|
<img
|
2021-04-12 09:49:02 -07:00
|
|
|
className={`h-8 w-auto`}
|
2021-03-30 15:47:08 -07:00
|
|
|
src="/assets/icons/logo.svg"
|
|
|
|
alt="next"
|
|
|
|
/>
|
|
|
|
</div>
|
2021-04-12 09:49:02 -07:00
|
|
|
<div className={`hidden sm:flex sm:space-x-8 sm:ml-4 py-2`}>
|
2021-03-30 15:47:08 -07:00
|
|
|
<MenuItem href="/">Trade</MenuItem>
|
|
|
|
<MenuItem href="/stats">Stats</MenuItem>
|
|
|
|
<MenuItem href="https://docs.mango.markets/">Learn</MenuItem>
|
|
|
|
</div>
|
|
|
|
</div>
|
2021-04-12 09:49:02 -07:00
|
|
|
<div className={`flex`}>
|
|
|
|
<div className={`flex items-center pr-1`}>
|
2021-04-12 06:32:01 -07:00
|
|
|
<ThemeSwitch />
|
|
|
|
{/*<button
|
2021-04-11 14:25:01 -07:00
|
|
|
type="button"
|
2021-04-12 09:49:02 -07:00
|
|
|
className={`inline-flex items-center justify-center p-2 rounded-md text-black dark:text-white hover:text-gray-400 focus:outline-none`}
|
2021-04-11 14:25:01 -07:00
|
|
|
onClick={() => setTheme(theme === 'dark' ? 'light' : 'dark')}
|
2021-03-30 15:47:08 -07:00
|
|
|
>
|
2021-04-11 14:25:01 -07:00
|
|
|
{theme === 'light' ? (
|
2021-04-12 09:49:02 -07:00
|
|
|
<MoonIcon className={`h-5 w-5`} />
|
2021-04-11 14:25:01 -07:00
|
|
|
) : (
|
2021-04-12 09:49:02 -07:00
|
|
|
<SunIcon className={`h-5 w-5`} />
|
2021-04-11 14:25:01 -07:00
|
|
|
)}
|
2021-04-12 06:32:01 -07:00
|
|
|
</button>*/}
|
2021-04-12 09:49:02 -07:00
|
|
|
<div className={`hidden sm:ml-4 sm:flex sm:items-center`}>
|
2021-04-11 14:25:01 -07:00
|
|
|
<button
|
|
|
|
onClick={handleConnectDisconnect}
|
2021-04-13 07:10:57 -07:00
|
|
|
className={`border border-th-primary hover:bg-th-primary rounded-md px-4 py-2 focus:outline-none text-th-primary hover:text-th-fgd-1 font-semibold text-base`}
|
2021-04-11 14:25:01 -07:00
|
|
|
>
|
2021-04-12 06:32:01 -07:00
|
|
|
<div>
|
2021-04-11 14:25:01 -07:00
|
|
|
{connected ? (
|
|
|
|
<div onClick={wallet.disconnect}>
|
|
|
|
<span>Disconnect: </span>
|
2021-04-12 06:32:01 -07:00
|
|
|
<Code
|
2021-04-12 09:49:02 -07:00
|
|
|
className={`text-xs p-1 text-th-fgd-1 font-extralight`}
|
2021-04-12 06:32:01 -07:00
|
|
|
>
|
2021-04-11 14:25:01 -07:00
|
|
|
{wallet.publicKey.toString().substr(0, 4) +
|
|
|
|
'...' +
|
|
|
|
wallet.publicKey.toString().substr(-4)}
|
|
|
|
</Code>
|
|
|
|
</div>
|
|
|
|
) : (
|
|
|
|
'Connect Wallet'
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
</button>
|
|
|
|
</div>
|
2021-03-30 15:47:08 -07:00
|
|
|
</div>
|
2021-04-12 09:49:02 -07:00
|
|
|
<div className={`-mr-2 flex items-center sm:hidden`}>
|
2021-04-11 14:25:01 -07:00
|
|
|
<button
|
|
|
|
type="button"
|
2021-04-12 09:49:02 -07:00
|
|
|
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`}
|
2021-04-11 14:25:01 -07:00
|
|
|
aria-controls="mobile-menu"
|
|
|
|
aria-expanded="false"
|
|
|
|
onClick={() => setShowMenu((showMenu) => !showMenu)}
|
2021-03-30 15:47:08 -07:00
|
|
|
>
|
2021-04-12 09:49:02 -07:00
|
|
|
<span className={`sr-only`}>Open main menu</span>
|
2021-04-11 14:25:01 -07:00
|
|
|
{showMenu ? (
|
2021-04-12 09:49:02 -07:00
|
|
|
<XIcon className={`h-5 w-5 text-th-primary`} />
|
2021-04-11 14:25:01 -07:00
|
|
|
) : (
|
2021-04-12 09:49:02 -07:00
|
|
|
<MenuIcon className={`h-5 w-5 text-th-primary`} />
|
2021-04-11 14:25:01 -07:00
|
|
|
)}
|
|
|
|
</button>
|
|
|
|
</div>
|
2021-03-30 15:47:08 -07:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div
|
2021-04-12 09:49:02 -07:00
|
|
|
className={`${showMenu ? `visible` : `hidden`} sm:hidden`}
|
2021-03-30 15:47:08 -07:00
|
|
|
id="mobile-menu"
|
|
|
|
>
|
2021-04-12 09:49:02 -07:00
|
|
|
<div
|
|
|
|
className={`bg-th-bkg-3 pt-2 pb-3 space-y-1 border-b border-th-fgd-4`}
|
|
|
|
>
|
2021-03-30 15:47:08 -07:00
|
|
|
<MenuItem href="/">Trade</MenuItem>
|
|
|
|
<MenuItem href="/stats">Stats</MenuItem>
|
|
|
|
<MenuItem href="https://docs.mango.markets/">Learn</MenuItem>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</nav>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export default TopBar
|