mango-ui-v3/components/UserInfo.tsx

96 lines
2.7 KiB
TypeScript
Raw Normal View History

import { useState } from 'react'
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-07-05 08:03:57 -07:00
import PositionsTable from './PositionsTable'
import TradeHistoryTable from './TradeHistoryTable'
2021-07-05 08:03:57 -07:00
// import { Position } from '../public/charting_library/charting_library'
// import FeeDiscountsTable from './FeeDiscountsTable'
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',
'Positions',
/*'Fee Discounts'*/
2021-07-01 07:12:42 -07:00
'Trade History',
]
2021-04-05 14:38:59 -07:00
const UserInfoTabs = ({ activeTab, setActiveTab }) => {
const handleTabChange = (tabName) => {
setActiveTab(tabName)
}
return (
<div>
<div className={`sm:hidden`}>
<label htmlFor="tabs" className={`sr-only`}>
2021-04-05 14:38:59 -07:00
Select a tab
</label>
<select
id="tabs"
name="tabs"
2021-04-24 19:10:28 -07:00
className={`block w-full pl-3 pr-10 py-2 bg-th-bkg-2 border border-th-fgd-4 focus:outline-none sm:text-sm rounded-md`}
2021-04-05 14:38:59 -07:00
onChange={(e) => handleTabChange(e.target.value)}
>
{TABS.map((tabName) => (
<option key={tabName} value={tabName}>
{tabName}
</option>
))}
</select>
</div>
<div className={`hidden sm:block`}>
<div className={`border-b border-th-fgd-4`}>
<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)}
className={`whitespace-nowrap pt-2 pb-4 px-1 border-b-2 font-semibold cursor-pointer default-transition hover:opacity-100
${
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-05 14:38:59 -07:00
>
{tabName}
</a>
))}
</nav>
</div>
</div>
</div>
)
}
const TabContent = ({ activeTab }) => {
switch (activeTab) {
2021-07-19 10:13:03 -07:00
case 'Open Orders':
return <OpenOrdersTable />
2021-06-22 20:32:10 -07:00
case 'Balances':
return <BalancesTable />
case 'Trade History':
return <TradeHistoryTable />
case 'Positions':
return <PositionsTable />
// case 'Fee Discounts':
// return <FeeDiscountsTable />
default:
2021-07-19 10:13:03 -07:00
return <BalancesTable />
}
}
const UserInfo = () => {
2021-04-05 14:38:59 -07:00
const [activeTab, setActiveTab] = useState(TABS[0])
return (
<FloatingElement>
2021-04-05 14:38:59 -07:00
<UserInfoTabs activeTab={activeTab} setActiveTab={setActiveTab} />
<TabContent activeTab={activeTab} />
</FloatingElement>
)
}
export default UserInfo