2021-07-23 07:07:05 -07:00
|
|
|
import { useCallback, useState } from 'react'
|
2021-09-01 07:30:34 -07:00
|
|
|
import Link from 'next/link'
|
2021-07-23 07:07:05 -07:00
|
|
|
import { abbreviateAddress } from '../utils/index'
|
2021-10-01 03:05:42 -07:00
|
|
|
import useLocalStorageState from '../hooks/useLocalStorageState'
|
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-07-17 06:49:52 -07:00
|
|
|
import NavDropMenu from './NavDropMenu'
|
2021-07-23 07:07:05 -07:00
|
|
|
import AccountsModal from './AccountsModal'
|
2021-10-20 05:42:40 -07:00
|
|
|
import LanguageSwitch from './LanguageSwitch'
|
2021-10-01 03:05:42 -07:00
|
|
|
import { DEFAULT_MARKET_KEY, initialMarket } from './SettingsModal'
|
2021-10-20 05:42:40 -07:00
|
|
|
// import { useRouter } from 'next/router'
|
|
|
|
import { useTranslation } from 'next-i18next'
|
2021-10-27 14:43:10 -07:00
|
|
|
import Settings from './Settings'
|
2021-03-30 15:47:08 -07:00
|
|
|
|
2021-04-05 07:32:11 -07:00
|
|
|
const TopBar = () => {
|
2021-10-20 05:42:40 -07:00
|
|
|
const { t } = useTranslation('common')
|
2021-07-23 07:07:05 -07:00
|
|
|
const mangoAccount = useMangoStore((s) => s.selectedMangoAccount.current)
|
2021-09-19 17:36:02 -07:00
|
|
|
const connected = useMangoStore((s) => s.wallet.connected)
|
2021-07-23 07:07:05 -07:00
|
|
|
const [showAccountsModal, setShowAccountsModal] = useState(false)
|
2021-10-01 03:05:42 -07:00
|
|
|
const [defaultMarket] = useLocalStorageState(
|
|
|
|
DEFAULT_MARKET_KEY,
|
|
|
|
initialMarket
|
|
|
|
)
|
2021-07-23 07:07:05 -07:00
|
|
|
|
|
|
|
const handleCloseAccounts = useCallback(() => {
|
|
|
|
setShowAccountsModal(false)
|
|
|
|
}, [])
|
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-09-19 17:50:51 -07:00
|
|
|
<div className={`pl-2 md:px-4 lg:px-10`}>
|
2021-05-17 22:33:04 -07:00
|
|
|
<div className={`flex justify-between h-14`}>
|
|
|
|
<div className={`flex`}>
|
2021-10-01 03:05:42 -07:00
|
|
|
<Link href={defaultMarket.path}>
|
2021-09-01 07:30:34 -07:00
|
|
|
<div
|
|
|
|
className={`cursor-pointer flex-shrink-0 flex items-center`}
|
|
|
|
>
|
|
|
|
<img
|
|
|
|
className={`h-8 w-auto`}
|
|
|
|
src="/assets/icons/logo.svg"
|
|
|
|
alt="next"
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</Link>
|
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
|
2021-07-06 21:34:21 -07:00
|
|
|
className={`hidden md:flex md:items-center md:space-x-6 md:ml-4`}
|
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
|
|
|
>
|
2021-10-20 05:42:40 -07:00
|
|
|
<MenuItem href={defaultMarket.path}>{t('trade')}</MenuItem>
|
|
|
|
<MenuItem href="/account">{t('account')}</MenuItem>
|
|
|
|
<MenuItem href="/borrow">{t('borrow')}</MenuItem>
|
|
|
|
<MenuItem href="/stats">{t('stats')}</MenuItem>
|
2021-08-16 11:20:19 -07:00
|
|
|
<MenuItem href="https://docs.mango.markets/" newWindow>
|
2021-10-20 05:42:40 -07:00
|
|
|
{t('learn')}
|
2021-08-16 11:20:19 -07:00
|
|
|
</MenuItem>
|
2021-07-17 06:49:52 -07:00
|
|
|
<NavDropMenu
|
2021-10-20 05:42:40 -07:00
|
|
|
menuTitle={t('more')}
|
2021-07-17 06:49:52 -07:00
|
|
|
// linksArray: [name: string, href: string, isExternal: boolean]
|
|
|
|
linksArray={[
|
|
|
|
['Mango v1', 'https://usdt.mango.markets', true],
|
2021-08-31 10:47:03 -07:00
|
|
|
['Mango v2', 'https://v2.mango.markets', true],
|
2021-07-17 06:49:52 -07:00
|
|
|
]}
|
|
|
|
/>
|
2021-10-20 05:42:40 -07:00
|
|
|
{/* <button
|
|
|
|
onClick={() => {
|
|
|
|
handleLocaleChange('en')
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
English
|
|
|
|
</button>
|
|
|
|
<button
|
|
|
|
onClick={() => {
|
|
|
|
handleLocaleChange('zh')
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
简体中文
|
|
|
|
</button>
|
|
|
|
<button
|
|
|
|
onClick={() => {
|
|
|
|
handleLocaleChange('zh_tw')
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
繁體中文
|
|
|
|
</button> */}
|
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-10-20 05:42:40 -07:00
|
|
|
<div className={`pl-2`}>
|
|
|
|
<LanguageSwitch />
|
|
|
|
</div>
|
2021-05-17 22:33:04 -07:00
|
|
|
<div className={`pl-2`}>
|
2021-04-19 06:45:59 -07:00
|
|
|
<ThemeSwitch />
|
|
|
|
</div>
|
2021-10-27 14:43:10 -07:00
|
|
|
<div className="pl-2">
|
|
|
|
<Settings />
|
|
|
|
</div>
|
2021-07-23 07:07:05 -07:00
|
|
|
{mangoAccount ? (
|
2021-09-19 17:36:02 -07:00
|
|
|
<div className="pl-2">
|
2021-07-29 06:19:32 -07:00
|
|
|
<button
|
|
|
|
className="border border-th-bkg-4 py-1 px-2 rounded text-xs focus:outline-none hover:border-th-fgd-4"
|
2021-07-23 07:07:05 -07:00
|
|
|
onClick={() => setShowAccountsModal(true)}
|
|
|
|
>
|
2021-09-19 17:36:02 -07:00
|
|
|
<div className="font-normal text-th-primary text-xs">
|
2021-10-20 05:42:40 -07:00
|
|
|
{t('account')}
|
2021-07-23 07:07:05 -07:00
|
|
|
</div>
|
2021-08-18 23:15:25 -07:00
|
|
|
{mangoAccount.name
|
|
|
|
? mangoAccount.name
|
|
|
|
: abbreviateAddress(mangoAccount.publicKey)}
|
2021-07-29 06:19:32 -07:00
|
|
|
</button>
|
2021-07-23 07:07:05 -07:00
|
|
|
</div>
|
|
|
|
) : null}
|
2021-05-17 22:33:04 -07:00
|
|
|
<div className="flex">
|
2021-09-19 17:36:02 -07:00
|
|
|
<div className={`${connected ? 'pr-2 md:pr-0' : ''} pl-2`}>
|
2021-08-20 08:05:05 -07:00
|
|
|
<ConnectWalletButton />
|
2021-05-17 22:33:04 -07:00
|
|
|
</div>
|
|
|
|
</div>
|
2021-04-11 14:25:01 -07:00
|
|
|
</div>
|
2021-03-30 15:47:08 -07:00
|
|
|
</div>
|
|
|
|
</div>
|
2021-05-17 22:33:04 -07:00
|
|
|
</nav>
|
2021-07-23 07:07:05 -07:00
|
|
|
{showAccountsModal ? (
|
|
|
|
<AccountsModal
|
|
|
|
onClose={handleCloseAccounts}
|
|
|
|
isOpen={showAccountsModal}
|
|
|
|
/>
|
|
|
|
) : null}
|
2021-05-17 22:33:04 -07:00
|
|
|
</>
|
2021-03-30 15:47:08 -07:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export default TopBar
|