2023-10-17 04:28:43 -07:00
|
|
|
import { useCallback } from 'react'
|
2022-09-01 10:33:29 -07:00
|
|
|
import AccountTabs from './AccountTabs'
|
2023-07-10 04:56:38 -07:00
|
|
|
import HealthContributions from './HealthContributions'
|
2023-10-17 04:28:43 -07:00
|
|
|
import { NextRouter, useRouter } from 'next/router'
|
2023-07-14 06:34:09 -07:00
|
|
|
import { useWallet } from '@solana/wallet-adapter-react'
|
2023-10-17 04:28:43 -07:00
|
|
|
import AccountStats from './AccountStats'
|
|
|
|
import PerpStatsPage from '@components/stats/perps/PerpStatsPage'
|
|
|
|
import TokenPage from '@components/token/TokenPage'
|
2024-03-14 05:08:58 -07:00
|
|
|
import mangoStore from '@store/mangoStore'
|
2023-03-21 03:27:37 -07:00
|
|
|
|
2023-07-11 05:00:23 -07:00
|
|
|
export type ViewToShow =
|
2023-05-02 23:12:08 -07:00
|
|
|
| ''
|
2023-10-17 04:28:43 -07:00
|
|
|
| 'account-stats'
|
2023-05-02 23:12:08 -07:00
|
|
|
| 'account-value'
|
|
|
|
| 'cumulative-interest-value'
|
|
|
|
| 'pnl'
|
|
|
|
| 'hourly-funding'
|
2023-07-03 20:24:13 -07:00
|
|
|
| 'hourly-volume'
|
2023-07-10 04:56:38 -07:00
|
|
|
| 'health-contributions'
|
2024-03-14 05:08:58 -07:00
|
|
|
| 'overview'
|
|
|
|
| 'balances'
|
|
|
|
| 'positions'
|
|
|
|
| 'orders'
|
|
|
|
| 'unsettled'
|
|
|
|
| 'history'
|
2023-05-02 23:12:08 -07:00
|
|
|
|
2023-10-17 04:28:43 -07:00
|
|
|
export const handleViewChange = (view: ViewToShow, router: NextRouter) => {
|
|
|
|
const query = { ...router.query, ['view']: view }
|
2023-10-18 17:12:15 -07:00
|
|
|
router.push({ pathname: router.pathname, query }, undefined, {
|
|
|
|
shallow: true,
|
|
|
|
})
|
2023-10-17 04:28:43 -07:00
|
|
|
}
|
|
|
|
|
2022-09-01 10:33:29 -07:00
|
|
|
const AccountPage = () => {
|
2024-03-14 05:08:58 -07:00
|
|
|
const activeAccountTab = mangoStore((s) => s.accountPageTab)
|
2023-07-11 06:14:44 -07:00
|
|
|
const router = useRouter()
|
2023-10-17 04:28:43 -07:00
|
|
|
const { market, token, view } = router.query
|
|
|
|
|
|
|
|
return market ? (
|
|
|
|
<PerpStatsPage />
|
|
|
|
) : token ? (
|
|
|
|
<TokenPage />
|
|
|
|
) : view ? (
|
|
|
|
<AccountView view={view as ViewToShow} />
|
2022-09-01 10:33:29 -07:00
|
|
|
) : (
|
2024-03-14 05:08:58 -07:00
|
|
|
<AccountTabs view={activeAccountTab} />
|
2023-07-11 05:00:23 -07:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export default AccountPage
|
|
|
|
|
2023-10-17 04:28:43 -07:00
|
|
|
const AccountView = ({ view }: { view: ViewToShow }) => {
|
2023-07-11 06:14:44 -07:00
|
|
|
const router = useRouter()
|
2023-07-14 06:34:09 -07:00
|
|
|
const { connected } = useWallet()
|
2023-07-11 06:14:44 -07:00
|
|
|
const { address } = router.query
|
2023-07-11 05:00:23 -07:00
|
|
|
|
2023-07-11 06:14:44 -07:00
|
|
|
const handleHideChart = useCallback(() => {
|
2023-07-14 06:34:09 -07:00
|
|
|
if (address && !connected) {
|
|
|
|
router.push(`/?address=${address}`, undefined, { shallow: true })
|
2023-07-11 06:14:44 -07:00
|
|
|
} else {
|
2023-07-14 06:34:09 -07:00
|
|
|
router.push('/', undefined, { shallow: true })
|
2023-07-11 06:14:44 -07:00
|
|
|
}
|
2023-07-14 06:34:09 -07:00
|
|
|
}, [address, router, connected])
|
2023-07-11 05:00:23 -07:00
|
|
|
|
|
|
|
switch (view) {
|
2023-10-17 04:28:43 -07:00
|
|
|
case 'account-stats':
|
|
|
|
return <AccountStats hideView={handleHideChart} />
|
2023-07-11 05:00:23 -07:00
|
|
|
case 'health-contributions':
|
|
|
|
return <HealthContributions hideView={handleHideChart} />
|
2024-03-14 06:20:40 -07:00
|
|
|
case 'overview':
|
|
|
|
return <AccountTabs view="overview" />
|
2024-03-14 05:08:58 -07:00
|
|
|
case 'balances':
|
|
|
|
return <AccountTabs view="balances" />
|
|
|
|
case 'positions':
|
|
|
|
return <AccountTabs view="trade:positions" />
|
|
|
|
case 'orders':
|
|
|
|
return <AccountTabs view="trade:orders" />
|
|
|
|
case 'unsettled':
|
|
|
|
return <AccountTabs view="trade:unsettled" />
|
|
|
|
case 'history':
|
|
|
|
return <AccountTabs view="history" />
|
2023-07-11 05:00:23 -07:00
|
|
|
default:
|
|
|
|
return null
|
|
|
|
}
|
2022-09-01 10:33:29 -07:00
|
|
|
}
|