mango-v4-ui/components/account/AccountPage.tsx

64 lines
1.7 KiB
TypeScript
Raw Normal View History

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'
2023-07-11 05:00:23 -07:00
export type ViewToShow =
| ''
2023-10-17 04:28:43 -07:00
| 'account-stats'
| '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'
2023-10-17 04:28:43 -07:00
export const handleViewChange = (view: ViewToShow, router: NextRouter) => {
const query = { ...router.query, ['view']: view }
router.push({ pathname: router.pathname, query })
}
2022-09-01 10:33:29 -07:00
const AccountPage = () => {
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
) : (
2023-10-17 04:28:43 -07:00
<AccountTabs />
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} />
default:
return null
}
2022-09-01 10:33:29 -07:00
}