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'
|
2021-11-09 02:40:07 -08:00
|
|
|
import usePerpPositions from '../hooks/usePerpPositions'
|
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-09-09 17:23:02 -07:00
|
|
|
import ManualRefresh from './ManualRefresh'
|
2021-09-20 05:24:42 -07:00
|
|
|
import Tabs from './Tabs'
|
2021-10-18 13:38:03 -07:00
|
|
|
import FeeDiscountsTable from './FeeDiscountsTable'
|
2021-11-30 13:04:55 -08:00
|
|
|
import useMangoAccount from '../hooks/useMangoAccount'
|
2021-12-06 12:14:29 -08:00
|
|
|
import { marketConfigSelector } from '../stores/selectors'
|
2021-04-05 14:38:59 -07:00
|
|
|
|
2021-07-01 07:12:42 -07:00
|
|
|
const TABS = [
|
|
|
|
'Balances',
|
2021-09-19 17:36:02 -07:00
|
|
|
'Orders',
|
|
|
|
'Positions',
|
2021-09-20 05:24:42 -07:00
|
|
|
'Trade History',
|
2021-10-18 13:38:03 -07:00
|
|
|
'Fee Discount',
|
2021-07-01 07:12:42 -07:00
|
|
|
]
|
2021-04-05 14:38:59 -07:00
|
|
|
|
|
|
|
const UserInfoTabs = ({ activeTab, setActiveTab }) => {
|
2022-01-27 08:57:36 -08:00
|
|
|
const totalOpenOrders = useMangoStore(
|
|
|
|
(s) => s.selectedMangoAccount.totalOpenOrders
|
|
|
|
)
|
2021-11-09 02:40:07 -08:00
|
|
|
const { openPositions } = usePerpPositions()
|
2021-11-30 13:04:55 -08:00
|
|
|
const { mangoAccount } = useMangoAccount()
|
|
|
|
|
2021-04-05 14:38:59 -07:00
|
|
|
const handleTabChange = (tabName) => {
|
|
|
|
setActiveTab(tabName)
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2021-12-07 20:00:02 -08:00
|
|
|
<div className="pb-2 relative">
|
2021-09-20 05:24:42 -07:00
|
|
|
<Tabs
|
|
|
|
activeTab={activeTab}
|
|
|
|
onChange={handleTabChange}
|
|
|
|
showCount={
|
2022-01-27 08:57:36 -08:00
|
|
|
totalOpenOrders > 0 && openPositions
|
2021-11-09 02:40:07 -08:00
|
|
|
? [
|
2022-01-27 08:57:36 -08:00
|
|
|
{ tabName: 'Orders', count: totalOpenOrders },
|
2021-11-09 02:40:07 -08:00
|
|
|
{ tabName: 'Positions', count: openPositions.length },
|
|
|
|
]
|
2021-09-20 05:24:42 -07:00
|
|
|
: null
|
|
|
|
}
|
|
|
|
tabs={TABS}
|
|
|
|
/>
|
2021-12-06 12:14:29 -08:00
|
|
|
{mangoAccount ? (
|
2021-09-20 05:24:42 -07:00
|
|
|
<div className="absolute right-0 top-0">
|
|
|
|
<ManualRefresh />
|
2021-04-05 14:38:59 -07:00
|
|
|
</div>
|
2021-09-20 05:24:42 -07:00
|
|
|
) : null}
|
2021-04-05 14:38:59 -07:00
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
2021-04-05 07:32:11 -07:00
|
|
|
|
2021-04-07 14:49:37 -07:00
|
|
|
const TabContent = ({ activeTab }) => {
|
|
|
|
switch (activeTab) {
|
2021-09-19 17:36:02 -07:00
|
|
|
case 'Orders':
|
2021-04-07 14:49:37 -07:00
|
|
|
return <OpenOrdersTable />
|
2021-06-22 20:32:10 -07:00
|
|
|
case 'Balances':
|
|
|
|
return <BalancesTable />
|
2021-09-20 06:15:44 -07:00
|
|
|
case 'Trade History':
|
2021-09-13 09:28:53 -07:00
|
|
|
return <TradeHistoryTable numTrades={100} />
|
2021-09-19 17:36:02 -07:00
|
|
|
case 'Positions':
|
2021-06-25 04:30:51 -07:00
|
|
|
return <PositionsTable />
|
2021-10-18 13:38:03 -07:00
|
|
|
case 'Fee Discount':
|
|
|
|
return <FeeDiscountsTable />
|
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-12-05 17:13:23 -08:00
|
|
|
const marketConfig = useMangoStore(marketConfigSelector)
|
2021-08-23 07:14:03 -07:00
|
|
|
const isPerpMarket = marketConfig.kind === 'perp'
|
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-12-01 08:49:28 -08:00
|
|
|
<div>
|
2021-09-19 17:36:02 -07:00
|
|
|
<UserInfoTabs activeTab={activeTab} setActiveTab={setActiveTab} />
|
|
|
|
<TabContent activeTab={activeTab} />
|
|
|
|
</div>
|
2021-04-05 07:32:11 -07:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export default UserInfo
|