2021-08-20 04:51:29 -07:00
|
|
|
import { useEffect, useState } from 'react'
|
2021-08-22 05:45:10 -07:00
|
|
|
import useMangoStore from '../stores/useMangoStore'
|
|
|
|
import { useOpenOrders } from '../hooks/useOpenOrders'
|
2021-09-03 12:02:51 -07:00
|
|
|
import usePerpPositions from '../hooks/usePerpPositions'
|
2021-04-05 07:32:11 -07:00
|
|
|
import FloatingElement from './FloatingElement'
|
2021-04-05 14:38:59 -07:00
|
|
|
import OpenOrdersTable from './OpenOrdersTable'
|
2021-06-22 20:32:10 -07:00
|
|
|
import BalancesTable from './BalancesTable'
|
2021-08-15 10:06:52 -07:00
|
|
|
import PositionsTable from './PerpPositionsTable'
|
2021-06-20 11:08:14 -07:00
|
|
|
import TradeHistoryTable from './TradeHistoryTable'
|
2021-08-18 07:23:55 -07:00
|
|
|
// import FeeDiscountsTable from './FeeDiscountsTable'
|
2021-09-03 05:11:21 -07:00
|
|
|
import Select from './Select'
|
2021-09-09 17:23:02 -07:00
|
|
|
import ManualRefresh from './ManualRefresh'
|
2021-04-05 14:38:59 -07:00
|
|
|
|
2021-07-01 07:12:42 -07:00
|
|
|
const TABS = [
|
|
|
|
'Balances',
|
2021-07-19 10:13:03 -07:00
|
|
|
'Open Orders',
|
2021-07-24 11:12:52 -07:00
|
|
|
'Perp Positions',
|
2021-08-18 07:23:55 -07:00
|
|
|
// 'Fees',
|
2021-07-01 07:12:42 -07:00
|
|
|
'Trade History',
|
|
|
|
]
|
2021-04-05 14:38:59 -07:00
|
|
|
|
|
|
|
const UserInfoTabs = ({ activeTab, setActiveTab }) => {
|
2021-08-22 05:45:10 -07:00
|
|
|
const openOrders = useOpenOrders()
|
2021-09-03 12:02:51 -07:00
|
|
|
const perpPositions = usePerpPositions()
|
2021-09-09 17:23:02 -07:00
|
|
|
const connected = useMangoStore((s) => s.connection.current)
|
|
|
|
const mangoAccount = useMangoStore((s) => s.selectedMangoAccount.current)
|
2021-04-05 14:38:59 -07:00
|
|
|
const handleTabChange = (tabName) => {
|
|
|
|
setActiveTab(tabName)
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div>
|
2021-09-06 10:35:40 -07:00
|
|
|
<div className={`pb-4 sm:hidden`}>
|
2021-04-12 09:49:02 -07:00
|
|
|
<label htmlFor="tabs" className={`sr-only`}>
|
2021-04-05 14:38:59 -07:00
|
|
|
Select a tab
|
|
|
|
</label>
|
2021-09-03 05:11:21 -07:00
|
|
|
<Select onChange={(t) => handleTabChange(t)} value={activeTab}>
|
2021-04-05 14:38:59 -07:00
|
|
|
{TABS.map((tabName) => (
|
2021-09-03 05:11:21 -07:00
|
|
|
<Select.Option key={tabName} value={tabName}>
|
2021-04-05 14:38:59 -07:00
|
|
|
{tabName}
|
2021-09-03 05:11:21 -07:00
|
|
|
</Select.Option>
|
2021-04-05 14:38:59 -07:00
|
|
|
))}
|
2021-09-03 05:11:21 -07:00
|
|
|
</Select>
|
2021-04-05 14:38:59 -07:00
|
|
|
</div>
|
2021-04-12 09:49:02 -07:00
|
|
|
<div className={`hidden sm:block`}>
|
2021-09-09 17:23:02 -07:00
|
|
|
<div className={`border-b border-th-fgd-4 mb-3 flex justify-between`}>
|
2021-05-07 12:41:26 -07:00
|
|
|
<nav className={`-mb-px flex space-x-6`} aria-label="Tabs">
|
2021-04-05 14:38:59 -07:00
|
|
|
{TABS.map((tabName) => (
|
|
|
|
<a
|
|
|
|
key={tabName}
|
|
|
|
onClick={() => handleTabChange(tabName)}
|
2021-08-22 05:45:10 -07:00
|
|
|
className={`whitespace-nowrap pt-2 pb-4 px-1 border-b-2 font-semibold cursor-pointer default-transition relative hover:opacity-100
|
2021-04-12 09:49:02 -07:00
|
|
|
${
|
|
|
|
activeTab === tabName
|
2021-04-16 04:50:56 -07:00
|
|
|
? `border-th-primary text-th-primary`
|
2021-04-16 07:08:33 -07:00
|
|
|
: `border-transparent text-th-fgd-4 hover:text-th-primary`
|
2021-04-12 09:49:02 -07:00
|
|
|
}
|
|
|
|
`}
|
2021-04-05 14:38:59 -07:00
|
|
|
>
|
2021-08-22 05:45:10 -07:00
|
|
|
{tabName}{' '}
|
|
|
|
{tabName === 'Open Orders' && openOrders?.length > 0 ? (
|
|
|
|
<Count count={openOrders?.length} />
|
|
|
|
) : null}
|
2021-09-03 12:02:51 -07:00
|
|
|
{tabName === 'Perp Positions' && perpPositions?.length > 0 ? (
|
2021-08-22 05:45:10 -07:00
|
|
|
<Count count={perpPositions?.length} />
|
2021-09-03 12:02:51 -07:00
|
|
|
) : null}
|
2021-04-05 14:38:59 -07:00
|
|
|
</a>
|
|
|
|
))}
|
|
|
|
</nav>
|
2021-09-09 17:23:02 -07:00
|
|
|
<div>
|
|
|
|
{connected && mangoAccount ? (
|
|
|
|
<ManualRefresh className="pl-2" />
|
|
|
|
) : null}
|
|
|
|
</div>
|
2021-04-05 14:38:59 -07:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
2021-04-05 07:32:11 -07:00
|
|
|
|
2021-08-22 05:45:10 -07:00
|
|
|
const Count = ({ count }) => (
|
|
|
|
<div className="absolute -top-2 -right-2 z-20">
|
2021-09-03 12:02:51 -07:00
|
|
|
<span className="h-4 p-1 bg-th-bkg-4 inline-flex rounded-lg items-center justify-center text-th-fgd-2 text-xxs">
|
2021-08-22 05:45:10 -07:00
|
|
|
{count}
|
2021-09-03 12:02:51 -07:00
|
|
|
</span>
|
2021-08-22 05:45:10 -07:00
|
|
|
</div>
|
|
|
|
)
|
|
|
|
|
2021-04-07 14:49:37 -07:00
|
|
|
const TabContent = ({ activeTab }) => {
|
|
|
|
switch (activeTab) {
|
2021-07-19 10:13:03 -07:00
|
|
|
case 'Open Orders':
|
2021-04-07 14:49:37 -07:00
|
|
|
return <OpenOrdersTable />
|
2021-06-22 20:32:10 -07:00
|
|
|
case 'Balances':
|
|
|
|
return <BalancesTable />
|
2021-06-20 11:08:14 -07:00
|
|
|
case 'Trade History':
|
2021-09-13 09:28:53 -07:00
|
|
|
return <TradeHistoryTable numTrades={100} />
|
2021-07-24 11:12:52 -07:00
|
|
|
case 'Perp Positions':
|
2021-06-25 04:30:51 -07:00
|
|
|
return <PositionsTable />
|
2021-08-18 07:23:55 -07:00
|
|
|
// case 'Fees':
|
|
|
|
// return <FeeDiscountsTable /> // now displayed in trade form. may add back when MRSRM deposits are supported
|
2021-04-07 14:49:37 -07:00
|
|
|
default:
|
2021-07-19 10:13:03 -07:00
|
|
|
return <BalancesTable />
|
2021-04-07 14:49:37 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-05 07:32:11 -07:00
|
|
|
const UserInfo = () => {
|
2021-08-23 07:14:03 -07:00
|
|
|
const marketConfig = useMangoStore((s) => s.selectedMarket.config)
|
|
|
|
const isPerpMarket = marketConfig.kind === 'perp'
|
2021-08-22 05:45:10 -07:00
|
|
|
const connected = useMangoStore((s) => s.wallet.connected)
|
2021-08-20 04:51:29 -07:00
|
|
|
const [activeTab, setActiveTab] = useState('')
|
|
|
|
|
|
|
|
useEffect(() => {
|
2021-08-23 07:14:03 -07:00
|
|
|
isPerpMarket ? setActiveTab(TABS[2]) : setActiveTab(TABS[0])
|
|
|
|
}, [isPerpMarket])
|
2021-04-05 07:32:11 -07:00
|
|
|
|
|
|
|
return (
|
2021-08-22 05:45:10 -07:00
|
|
|
<FloatingElement showConnect>
|
|
|
|
<div className={!connected ? 'filter blur-sm' : null}>
|
|
|
|
<UserInfoTabs activeTab={activeTab} setActiveTab={setActiveTab} />
|
|
|
|
<TabContent activeTab={activeTab} />
|
|
|
|
</div>
|
2021-04-05 07:32:11 -07:00
|
|
|
</FloatingElement>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export default UserInfo
|