2023-09-28 18:44:41 -07:00
|
|
|
import { useEffect, useMemo, useState } from 'react'
|
2022-10-06 20:16:11 -07:00
|
|
|
import TabButtons from '@components/shared/TabButtons'
|
2022-11-17 14:16:45 -08:00
|
|
|
import SwapTradeBalances from '../shared/BalancesTable'
|
2022-10-06 20:16:11 -07:00
|
|
|
import SwapHistoryTable from './SwapHistoryTable'
|
2022-11-18 09:09:39 -08:00
|
|
|
import useMangoAccount from 'hooks/useMangoAccount'
|
2023-06-13 18:09:15 -07:00
|
|
|
import ManualRefresh from '@components/shared/ManualRefresh'
|
|
|
|
import { useViewport } from 'hooks/useViewport'
|
2023-09-06 21:29:31 -07:00
|
|
|
import SwapTriggerOrders from './SwapTriggerOrders'
|
2023-09-28 18:44:41 -07:00
|
|
|
import mangoStore from '@store/mangoStore'
|
2022-10-06 20:16:11 -07:00
|
|
|
|
|
|
|
const SwapInfoTabs = () => {
|
|
|
|
const [selectedTab, setSelectedTab] = useState('balances')
|
2022-11-18 09:09:39 -08:00
|
|
|
const { mangoAccount } = useMangoAccount()
|
2023-08-31 20:22:50 -07:00
|
|
|
const { isMobile, isTablet } = useViewport()
|
2023-09-28 18:44:41 -07:00
|
|
|
const { swapOrTrigger } = mangoStore((s) => s.swap)
|
2022-10-06 20:16:11 -07:00
|
|
|
|
|
|
|
const tabsWithCount: [string, number][] = useMemo(() => {
|
2023-08-15 22:47:02 -07:00
|
|
|
const tabs: [string, number][] = [
|
2022-10-06 20:16:11 -07:00
|
|
|
['balances', 0],
|
|
|
|
['swap:swap-history', 0],
|
|
|
|
]
|
2023-09-28 18:44:41 -07:00
|
|
|
const stopOrdersCount =
|
|
|
|
mangoAccount?.tokenConditionalSwaps.filter((tcs) => tcs.hasData)
|
|
|
|
?.length || 0
|
|
|
|
tabs.splice(1, 0, ['trade:trigger-orders', stopOrdersCount])
|
2023-08-08 18:03:54 -07:00
|
|
|
return tabs
|
2023-09-28 18:44:41 -07:00
|
|
|
}, [mangoAccount])
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
if (swapOrTrigger !== 'swap') {
|
|
|
|
setSelectedTab('trade:trigger-orders')
|
|
|
|
} else {
|
|
|
|
if (selectedTab !== 'balances') {
|
|
|
|
setSelectedTab('balances')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, [swapOrTrigger])
|
2022-10-06 20:16:11 -07:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="hide-scroll h-full overflow-y-scroll">
|
2023-06-13 18:09:15 -07:00
|
|
|
<div className="flex items-center border-b border-th-bkg-3">
|
2023-08-30 22:34:22 -07:00
|
|
|
<div className="w-full md:border-r md:border-th-bkg-3">
|
|
|
|
<TabButtons
|
|
|
|
activeValue={selectedTab}
|
|
|
|
onChange={(tab: string) => setSelectedTab(tab)}
|
|
|
|
values={tabsWithCount}
|
|
|
|
showBorders
|
|
|
|
/>
|
|
|
|
</div>
|
2023-06-13 18:09:15 -07:00
|
|
|
<ManualRefresh
|
2023-08-30 22:34:22 -07:00
|
|
|
classNames="fixed bottom-16 right-4 md:relative md:px-2 md:bottom-0 md:right-0 z-10 shadow-lg md:shadow-none bg-th-bkg-3 md:bg-transparent"
|
2023-08-31 20:22:50 -07:00
|
|
|
hideBg={isMobile || isTablet}
|
|
|
|
size={isTablet ? 'large' : 'small'}
|
2023-06-13 18:09:15 -07:00
|
|
|
/>
|
2022-10-06 20:16:11 -07:00
|
|
|
</div>
|
|
|
|
{selectedTab === 'balances' ? <SwapTradeBalances /> : null}
|
2023-09-06 21:29:31 -07:00
|
|
|
{selectedTab === 'trade:trigger-orders' ? <SwapTriggerOrders /> : null}
|
2023-01-05 17:56:03 -08:00
|
|
|
{selectedTab === 'swap:swap-history' ? <SwapHistoryTable /> : null}
|
2022-10-06 20:16:11 -07:00
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export default SwapInfoTabs
|