lev-stake-sol/pages/index.tsx

77 lines
2.0 KiB
TypeScript
Raw Normal View History

2023-09-24 05:55:00 -07:00
import NavTabs from '@components/NavTabs'
import Positions from '@components/Positions'
import Stake from '@components/Stake'
import TransactionHistory from '@components/TransactionHistory'
2023-09-14 19:31:59 -07:00
import mangoStore from '@store/mangoStore'
2023-09-12 17:37:41 -07:00
import type { NextPage } from 'next'
import { serverSideTranslations } from 'next-i18next/serverSideTranslations'
2023-09-14 19:31:59 -07:00
import { useEffect, useState } from 'react'
import { BOOST_ACCOUNT_PREFIX } from 'utils/constants'
2023-09-12 17:37:41 -07:00
2023-09-14 19:31:59 -07:00
const set = mangoStore.getState().set
2023-09-14 06:18:39 -07:00
2023-09-12 17:37:41 -07:00
export async function getStaticProps({ locale }: { locale: string }) {
return {
props: {
2023-09-29 16:46:54 -07:00
...(await serverSideTranslations(locale, ['common', 'swap'])),
2023-09-12 17:37:41 -07:00
},
}
}
const Index: NextPage = () => {
2023-09-24 05:55:00 -07:00
const [activeTab, setActiveTab] = useState('Boost!')
2023-09-14 19:31:59 -07:00
const selectedToken = mangoStore((s) => s.selectedToken)
useEffect(() => {
const mangoAccounts = mangoStore.getState().mangoAccounts
const selectedMangoAccount = mangoAccounts.find(
2023-09-20 14:50:35 -07:00
(ma) =>
ma.name.toLowerCase() ===
`${(BOOST_ACCOUNT_PREFIX + selectedToken).toLowerCase()}`,
)
console.log(
'selectedMangoAccount',
(BOOST_ACCOUNT_PREFIX + selectedToken).toLowerCase(),
selectedMangoAccount,
2023-09-14 19:31:59 -07:00
)
set((s) => {
s.mangoAccount.current = selectedMangoAccount
})
}, [selectedToken])
2023-09-12 17:37:41 -07:00
return (
2023-09-24 05:55:00 -07:00
<>
2023-10-01 18:24:28 -07:00
<div className="mb-6 grid grid-cols-3">
2023-09-24 05:55:00 -07:00
<NavTabs
activeValue={activeTab}
2023-10-01 18:24:28 -07:00
values={['Boost!', 'Positions', 'Activity']}
2023-09-24 05:55:00 -07:00
onChange={setActiveTab}
/>
2023-09-12 17:37:41 -07:00
</div>
2023-09-14 21:24:29 -07:00
<TabContent activeTab={activeTab} setActiveTab={setActiveTab} />
2023-09-24 05:55:00 -07:00
</>
2023-09-12 17:37:41 -07:00
)
}
export default Index
2023-09-14 21:24:29 -07:00
const TabContent = ({
activeTab,
setActiveTab,
}: {
activeTab: string
setActiveTab: (tab: string) => void
}) => {
switch (activeTab) {
2023-09-24 05:55:00 -07:00
case 'Boost!':
return <Stake />
case 'Positions':
2023-09-14 21:24:29 -07:00
return <Positions setActiveTab={setActiveTab} />
2023-09-25 20:02:58 -07:00
case 'Activity':
return <TransactionHistory />
default:
return <Stake />
}
}