diff --git a/components/HomePage.tsx b/components/HomePage.tsx index c56777a..88757be 100644 --- a/components/HomePage.tsx +++ b/components/HomePage.tsx @@ -3,17 +3,23 @@ import NavTabs from './NavTabs' import Positions from './Positions' import Stake from './Stake' import TransactionHistory from './TransactionHistory' -import mangoStore from '@store/mangoStore' -import { useEffect, useState } from 'react' +import mangoStore, { ActiveTab } from '@store/mangoStore' +import { useCallback, useEffect } from 'react' import { BOOST_ACCOUNT_PREFIX } from 'utils/constants' const set = mangoStore.getState().set const HomePage = () => { - const [activeTab, setActiveTab] = useState('Boost!') + const activeTab = mangoStore((s) => s.activeTab) const selectedToken = mangoStore((s) => s.selectedToken) const { positions } = usePositions() + const setActiveTab = useCallback((tab: ActiveTab) => { + return set((s) => { + s.activeTab = tab + }) + }, []) + useEffect(() => { const mangoAccounts = mangoStore.getState().mangoAccounts const selectedMangoAccount = mangoAccounts.find( @@ -56,7 +62,7 @@ const TabContent = ({ setActiveTab, }: { activeTab: string - setActiveTab: (tab: string) => void + setActiveTab: (tab: ActiveTab) => void }) => { switch (activeTab) { case 'Boost!': diff --git a/components/NavTabs.tsx b/components/NavTabs.tsx index f6eb453..b3a53b9 100644 --- a/components/NavTabs.tsx +++ b/components/NavTabs.tsx @@ -30,9 +30,9 @@ const NavTabs = ({
- {count} + {count}
) : null} diff --git a/components/Positions.tsx b/components/Positions.tsx index e4efcd7..8516f5f 100644 --- a/components/Positions.tsx +++ b/components/Positions.tsx @@ -4,7 +4,7 @@ import { BORROW_TOKEN, SHOW_INACTIVE_POSITIONS_KEY } from 'utils/constants' import TokenLogo from './shared/TokenLogo' import Button from './shared/Button' import { formatTokenSymbol } from 'utils/tokens' -import mangoStore from '@store/mangoStore' +import mangoStore, { ActiveTab } from '@store/mangoStore' import Switch from './forms/Switch' import useLocalStorageState from 'hooks/useLocalStorageState' import FormatNumericValue from './shared/FormatNumericValue' @@ -40,7 +40,7 @@ const getLiquidationRatio = ( const Positions = ({ setActiveTab, }: { - setActiveTab: (tab: string) => void + setActiveTab: (tab: ActiveTab) => void }) => { const [showInactivePositions, setShowInactivePositions] = useLocalStorageState(SHOW_INACTIVE_POSITIONS_KEY, true) @@ -92,7 +92,7 @@ const PositionItem = ({ borrowBank, }: { position: Position - setActiveTab: (v: string) => void + setActiveTab: (v: ActiveTab) => void borrowBank: Bank | undefined }) => { const { group } = useMangoGroup() diff --git a/store/mangoStore.ts b/store/mangoStore.ts index 0cd292e..c5593a4 100644 --- a/store/mangoStore.ts +++ b/store/mangoStore.ts @@ -136,8 +136,11 @@ export const DEFAULT_TRADE_FORM: TradeForm = { reduceOnly: false, } +export type ActiveTab = 'Boost!' | 'Positions' | 'Activity' + export type MangoStore = { // leverage stake + activeTab: ActiveTab selectedToken: string estimatedMaxAPY: { current: number @@ -301,6 +304,7 @@ const mangoStore = create()( return { // leverage stake + activeTab: 'Boost!', selectedToken: STAKEABLE_TOKENS[0], estimatedMaxAPY: { current: 0,