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

54 lines
1.5 KiB
TypeScript
Raw Normal View History

import { useEffect, useMemo, useState } from 'react'
2022-09-12 08:53:57 -07:00
import mangoStore from '@store/mangoStore'
2022-08-10 04:17:10 -07:00
import TabButtons from '../shared/TabButtons'
import TokenList from '../TokenList'
2022-09-19 03:43:38 -07:00
import SwapHistoryTable from '../swap/SwapHistoryTable'
2022-09-26 23:22:51 -07:00
import ActivityFeed from './ActivityFeed'
2022-08-10 04:17:10 -07:00
2022-09-30 05:39:38 -07:00
const TABS = ['balances', 'activity:activity', 'swap:swap-history']
2022-08-10 04:17:10 -07:00
const AccountTabs = () => {
2022-09-04 23:32:10 -07:00
const [activeTab, setActiveTab] = useState('balances')
2022-08-12 23:06:09 -07:00
const actions = mangoStore((s) => s.actions)
2022-08-10 04:17:10 -07:00
const mangoAccount = mangoStore((s) => s.mangoAccount.current)
const tabsWithCount: [string, number][] = useMemo(() => {
return TABS.map((t) => [t, 0])
}, [])
2022-08-10 04:17:10 -07:00
useEffect(() => {
if (mangoAccount) {
2022-09-26 23:22:51 -07:00
actions.fetchSwapHistory(mangoAccount.publicKey.toString())
2022-08-10 04:17:10 -07:00
}
2022-08-13 22:07:53 -07:00
}, [actions, mangoAccount])
2022-08-10 04:17:10 -07:00
return (
<>
2022-09-19 03:43:38 -07:00
<TabButtons
activeValue={activeTab}
onChange={(v) => setActiveTab(v)}
values={tabsWithCount}
2022-09-19 03:43:38 -07:00
showBorders
/>
2022-09-26 23:22:51 -07:00
<TabContent activeTab={activeTab} />
2022-08-10 04:17:10 -07:00
</>
)
}
2022-09-26 23:22:51 -07:00
const TabContent = ({ activeTab }: { activeTab: string }) => {
const swapHistory = mangoStore((s) => s.mangoAccount.stats.swapHistory.data)
const loading = mangoStore((s) => s.mangoAccount.stats.swapHistory.loading)
switch (activeTab) {
case 'balances':
return <TokenList />
2022-09-28 06:04:58 -07:00
case 'activity:activity':
2022-09-26 23:22:51 -07:00
return <ActivityFeed />
case 'swap:swap-history':
return <SwapHistoryTable swapHistory={swapHistory} loading={loading} />
default:
return <TokenList />
}
}
2022-08-10 04:17:10 -07:00
export default AccountTabs