routing and pages for HLS (#538)

This commit is contained in:
Bob van der Helm 2023-10-12 14:40:40 +02:00 committed by GitHub
parent 3fce7f5851
commit 4915729ed5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 77 additions and 24 deletions

View File

@ -8,7 +8,8 @@ const underlineClasses =
'relative before:absolute before:h-[2px] before:-bottom-1 before:left-0 before:right-0 before:gradient-active-tab'
interface Props {
isFarm?: boolean
tabs: Tab[]
activeTabIdx: number
}
export default function Tab(props: Props) {
@ -17,24 +18,18 @@ export default function Tab(props: Props) {
return (
<div className='relative w-full'>
<NavLink
to={getRoute('lend', address, accountId)}
className={classNames(
props.isFarm ? 'text-white/40' : underlineClasses,
'relative mr-8 text-xl ',
)}
>
Lend
</NavLink>
<NavLink
to={getRoute('farm', address, accountId)}
className={classNames(
!props.isFarm ? 'text-white/40' : underlineClasses,
'relative text-xl',
)}
>
Farm
</NavLink>
{props.tabs.map((tab, index) => (
<NavLink
key={tab.page}
to={getRoute(tab.page, address, accountId)}
className={classNames(
props.activeTabIdx === index ? underlineClasses : 'text-white/40',
'relative mr-8 text-xl ',
)}
>
{tab.name}
</NavLink>
))}
</div>
)
}

View File

@ -9,12 +9,14 @@ import Settings from 'components/Settings'
import Wallet from 'components/Wallet'
import useAccountId from 'hooks/useAccountId'
import useStore from 'store'
import { ENABLE_HLS } from 'utils/constants'
export const menuTree: { pages: Page[]; label: string }[] = [
{ pages: ['trade'], label: 'Trade' },
{ pages: ['lend', 'farm'], label: 'Earn' },
{ pages: ['borrow'], label: 'Borrow' },
{ pages: ['portfolio'], label: 'Portfolio' },
...(ENABLE_HLS ? [{ pages: ['hls-farm', 'hls-staking'] as Page[], label: 'High Leverage' }] : []),
]
export default function DesktopHeader() {

View File

@ -15,7 +15,8 @@ export default function DesktopNavigation() {
const focusComponent = useStore((s) => s.focusComponent)
function getIsActive(pages: string[]) {
return pages.some((page) => location.pathname.includes(page))
const segments = location.pathname.split('/')
return pages.some((page) => segments.includes(page))
}
return (

View File

@ -3,6 +3,8 @@ import { Navigate, Outlet, Route, Routes as RoutesWrapper } from 'react-router-d
import Layout from 'pages/_layout'
import BorrowPage from 'pages/BorrowPage'
import FarmPage from 'pages/FarmPage'
import HLSFarmPage from 'pages/HLSFarmPage'
import HLSStakingPage from 'pages/HLSStakingPage'
import LendPage from 'pages/LendPage'
import MobilePage from 'pages/MobilePage'
import PortfolioAccountPage from 'pages/PortfolioAccountPage'
@ -25,6 +27,8 @@ export default function Routes() {
<Route path='/borrow' element={<BorrowPage />} />
<Route path='/portfolio' element={<PortfolioPage />} />
<Route path='/mobile' element={<MobilePage />} />
<Route path='/hls-staking' element={<HLSStakingPage />} />
<Route path='/hls-farm' element={<HLSFarmPage />} />
<Route path='/' element={<TradePage />} />
<Route path='/wallets/:address'>
<Route path='trade' element={<TradePage />} />
@ -35,6 +39,8 @@ export default function Routes() {
<Route path='portfolio/:accountId'>
<Route path='' element={<PortfolioAccountPage />} />
</Route>
<Route path='hls-staking' element={<HLSStakingPage />} />
<Route path='hls-farm' element={<HLSFarmPage />} />
<Route path='' element={<TradePage />} />
</Route>
<Route path='*' element={<Navigate to='/' />} />

9
src/constants/pages.ts Normal file
View File

@ -0,0 +1,9 @@
export const EARN_TABS: Tab[] = [
{ page: 'lend', name: 'Lend' },
{ page: 'farm', name: 'Farm' },
]
export const HLS_TABS: Tab[] = [
{ page: 'hls-farm', name: 'Farm' },
{ page: 'hls-staking', name: 'Staking' },
]

View File

@ -2,12 +2,13 @@ import FarmIntro from 'components/Earn/Farm/FarmIntro'
import { AvailableVaults, DepositedVaults } from 'components/Earn/Farm/Vaults'
import Tab from 'components/Earn/Tab'
import MigrationBanner from 'components/MigrationBanner'
import { EARN_TABS } from 'constants/pages'
export default function FarmPage() {
return (
<div className='flex flex-wrap w-full gap-6'>
<MigrationBanner />
<Tab isFarm />
<Tab tabs={EARN_TABS} activeTabIdx={1} />
<FarmIntro />
<DepositedVaults />
<AvailableVaults />

12
src/pages/HLSFarmPage.tsx Normal file
View File

@ -0,0 +1,12 @@
import Tab from 'components/Earn/Tab'
import MigrationBanner from 'components/MigrationBanner'
import { HLS_TABS } from 'constants/pages'
export default function HLSFarmPage() {
return (
<div className='flex flex-wrap w-full gap-6'>
<MigrationBanner />
<Tab tabs={HLS_TABS} activeTabIdx={0} />
</div>
)
}

View File

@ -0,0 +1,12 @@
import Tab from 'components/Earn/Tab'
import MigrationBanner from 'components/MigrationBanner'
import { HLS_TABS } from 'constants/pages'
export default function HLSStakingPage() {
return (
<div className='flex flex-wrap w-full gap-6'>
<MigrationBanner />
<Tab tabs={HLS_TABS} activeTabIdx={1} />
</div>
)
}

View File

@ -1,7 +1,8 @@
import LendIntro from 'components/Earn/Lend/LendIntro'
import LendingMarketsTable from 'components/Earn/Lend/LendingMarketsTable'
import LendIntro from 'components/Earn/Lend/LendIntro'
import Tab from 'components/Earn/Tab'
import MigrationBanner from 'components/MigrationBanner'
import { EARN_TABS } from 'constants/pages'
import useLendingMarketAssetsTableData from 'hooks/useLendingMarketAssetsTableData'
export default function LendPage() {
@ -9,7 +10,7 @@ export default function LendPage() {
return (
<div className='flex flex-wrap w-full gap-6'>
<MigrationBanner />
<Tab />
<Tab tabs={EARN_TABS} activeTabIdx={0} />
<LendIntro />
<LendingMarketsTable data={accountLentAssets} title='Lent Assets' />
<LendingMarketsTable data={availableAssets} title='Available Markets' />

View File

@ -0,0 +1,4 @@
interface Tab {
page: Page
name: string
}

View File

@ -1 +1,9 @@
type Page = 'trade' | 'borrow' | 'farm' | 'lend' | 'portfolio' | 'portfolio/{accountId}'
type Page =
| 'trade'
| 'borrow'
| 'farm'
| 'lend'
| 'portfolio'
| 'portfolio/{accountId}'
| 'hls-farm'
| 'hls-staking'

View File

@ -22,3 +22,5 @@ export const DEFAULT_PORTFOLIO_STATS = [
{ title: null, sub: 'APR' },
{ title: null, sub: 'Account Leverage' },
]
export const ENABLE_HLS = false