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'
|
2022-09-14 18:06:00 -07:00
|
|
|
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 (
|
|
|
|
<>
|
2022-09-14 12:38:25 -07:00
|
|
|
<div className="mb-4">
|
2022-08-10 04:17:10 -07:00
|
|
|
<TabButtons
|
|
|
|
activeValue={activeTab}
|
|
|
|
onChange={(v) => setActiveTab(v)}
|
2022-09-14 18:06:00 -07:00
|
|
|
values={['balances', 'swap:swap-history']}
|
2022-09-18 20:53:52 -07:00
|
|
|
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 />
|
|
|
|
) : (
|
2022-09-14 18:06:00 -07:00
|
|
|
<SwapHistoryTable tradeHistory={tradeHistory} loading={loading} />
|
2022-08-10 04:17:10 -07:00
|
|
|
)}
|
|
|
|
</>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export default AccountTabs
|