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

42 lines
1.2 KiB
TypeScript
Raw Normal View History

2022-08-10 04:17:10 -07:00
import { useEffect, 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'
import SwapHistoryTable from '../SwapHistoryTable'
2022-09-14 23:06:23 -07:00
import { useRouter } from 'next/router'
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)
2022-08-12 23:06:09 -07:00
const tradeHistory = mangoStore((s) => s.mangoAccount.stats.tradeHistory.data)
const loading = mangoStore((s) => s.mangoAccount.stats.tradeHistory.loading)
2022-09-14 23:06:23 -07:00
const { pathname } = useRouter()
2022-08-10 04:17:10 -07:00
useEffect(() => {
if (mangoAccount) {
2022-08-12 23:06:09 -07:00
actions.fetchTradeHistory(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 (
<>
<div className="mb-4">
2022-08-10 04:17:10 -07:00
<TabButtons
activeValue={activeTab}
onChange={(v) => setActiveTab(v)}
values={['balances', 'swap:swap-history']}
showBorders
2022-08-10 04:17:10 -07:00
/>
</div>
2022-09-04 23:32:10 -07:00
{activeTab === 'balances' ? (
2022-08-10 04:17:10 -07:00
<TokenList />
) : (
<SwapHistoryTable tradeHistory={tradeHistory} loading={loading} />
2022-08-10 04:17:10 -07:00
)}
</>
)
}
export default AccountTabs