mango-v4-ui/components/explore/Explore.tsx

88 lines
2.6 KiB
TypeScript
Raw Normal View History

2023-11-10 03:36:35 -08:00
import { useEffect, useMemo, useState } from 'react'
2023-10-17 04:28:43 -07:00
import PerpMarketsTable from './PerpMarketsTable'
import mangoStore from '@store/mangoStore'
import RecentGainersLosers from './RecentGainersLosers'
import Spot from './Spot'
2023-11-10 03:36:35 -08:00
import useBanks from 'hooks/useBanks'
import TabsText from '@components/shared/TabsText'
2023-11-13 20:41:16 -08:00
import useFollowedAccounts from 'hooks/useFollowedAccounts'
import FollowedAccounts from './FollowedAccounts'
2024-02-21 03:00:58 -08:00
import useLocalStorageState from 'hooks/useLocalStorageState'
import { SHOW_ANNOUNCEMENTS_KEY } from 'utils/constants'
2023-10-17 04:28:43 -07:00
const Explore = () => {
2023-11-10 03:36:35 -08:00
const { banks } = useBanks()
2023-11-13 20:41:16 -08:00
const { data: followedAccounts } = useFollowedAccounts()
2024-02-21 03:00:58 -08:00
const [showAnnouncements] = useLocalStorageState(SHOW_ANNOUNCEMENTS_KEY, true)
2023-10-17 04:28:43 -07:00
const perpStats = mangoStore((s) => s.perpStats.data)
2023-11-10 03:36:35 -08:00
const [activeTab, setActiveTab] = useState('tokens')
2023-10-17 04:28:43 -07:00
useEffect(() => {
if (!perpStats || !perpStats.length) {
const actions = mangoStore.getState().actions
actions.fetchPerpStats()
}
}, [perpStats])
2023-11-10 03:36:35 -08:00
const tabsWithCount: [string, number][] = useMemo(() => {
const perpMarkets = mangoStore.getState().perpMarkets
2023-12-02 04:26:39 -08:00
const followedAccountsNumber = followedAccounts
? followedAccounts.length
: 0
2023-11-10 03:36:35 -08:00
const tabs: [string, number][] = [
['tokens', banks.length],
2023-11-14 15:53:34 -08:00
['perp', perpMarkets.length],
2023-12-02 04:26:39 -08:00
['account:followed-accounts', followedAccountsNumber],
2023-11-10 03:36:35 -08:00
]
return tabs
2023-11-13 20:41:16 -08:00
}, [banks, followedAccounts])
2023-11-10 03:36:35 -08:00
2023-10-17 04:28:43 -07:00
return (
2024-02-21 03:00:58 -08:00
<div className={showAnnouncements ? 'pt-4' : 'pt-10'}>
{/* <div className="px-4 pt-10 md:px-6">
2023-11-10 03:36:35 -08:00
<h2 className="mb-4 text-center text-lg md:text-left">
2023-10-17 04:28:43 -07:00
{t('explore')}
</h2>
2024-02-21 03:00:58 -08:00
</div> */}
2023-10-17 04:28:43 -07:00
<RecentGainersLosers />
2023-12-23 16:20:57 -08:00
<div className="z-10 w-max px-4 pt-8 md:px-6">
2023-11-10 03:36:35 -08:00
<div
className={`flex h-10 flex-col items-center justify-end md:items-start ${
activeTab === 'tokens' ? 'mb-4 lg:mb-0' : ''
}`}
2024-02-11 19:14:47 -08:00
id="account-explore-tabs"
2023-11-10 03:36:35 -08:00
>
<TabsText
activeTab={activeTab}
onChange={setActiveTab}
tabs={tabsWithCount}
2023-11-14 15:53:34 -08:00
className="xl:text-lg"
2023-10-17 04:28:43 -07:00
/>
</div>
</div>
2024-01-14 18:09:34 -08:00
<div className="pb-20 md:pb-0">
<TabContent activeTab={activeTab} />
</div>
2024-02-21 03:00:58 -08:00
</div>
2023-10-17 04:28:43 -07:00
)
}
export default Explore
const TabContent = ({ activeTab }: { activeTab: string }) => {
switch (activeTab) {
2023-11-10 03:36:35 -08:00
case 'tokens':
2023-10-17 04:28:43 -07:00
return <Spot />
2023-12-02 03:59:37 -08:00
case 'perp':
2023-10-17 04:28:43 -07:00
return (
<div className="mt-6 border-t border-th-bkg-3">
<PerpMarketsTable />
</div>
)
2023-11-13 20:41:16 -08:00
case 'account:followed-accounts':
return <FollowedAccounts />
2023-10-17 04:28:43 -07:00
default:
return <Spot />
}
}