diff --git a/components/mobile/BottomBar.tsx b/components/mobile/BottomBar.tsx index 6e5cf6d6..7cadab58 100644 --- a/components/mobile/BottomBar.tsx +++ b/components/mobile/BottomBar.tsx @@ -1,10 +1,9 @@ -import { useEffect, useState } from 'react' +import { useEffect } from 'react' import Link from 'next/link' import { useRouter } from 'next/router' import { ChartBarIcon, CurrencyDollarIcon } from '@heroicons/react/solid' import { BtcMonoIcon, TradeIcon } from '../icons' import useMangoGroupConfig from '../../hooks/useMangoGroupConfig' -import MarketsModal from '../MarketsModal' import { useTranslation } from 'next-i18next' const StyledBarItemLabel = ({ children, ...props }) => ( @@ -15,8 +14,6 @@ const StyledBarItemLabel = ({ children, ...props }) => ( const BottomBar = () => { const { t } = useTranslation('common') - const [showMarketsModal, setShowMarketsModal] = useState(false) - const [sortedMarkets, setSortedMarkets] = useState([]) const { asPath } = useRouter() const groupConfig = useMangoGroupConfig() @@ -38,13 +35,20 @@ const BottomBar = () => { return ( <>
-
setShowMarketsModal(true)} + - - {t('markets')} -
+
+ + {t('markets')} +
+ { >
{
- {showMarketsModal ? ( - setShowMarketsModal(false)} - markets={sortedMarkets} - /> - ) : null} ) } diff --git a/components/mobile/MobileTradePage.tsx b/components/mobile/MobileTradePage.tsx index ecd60650..8ce5c3fd 100644 --- a/components/mobile/MobileTradePage.tsx +++ b/components/mobile/MobileTradePage.tsx @@ -16,6 +16,7 @@ import RecentMarketTrades from '../RecentMarketTrades' import FloatingElement from '../FloatingElement' import Swipeable from './Swipeable' import { useTranslation } from 'next-i18next' +import Link from 'next/link' const TVChartContainer = dynamic( () => import('../../components/TradingView/index'), @@ -54,27 +55,29 @@ const MobileTradePage = () => { return (
-
- +
-
{baseSymbol}
- - {isPerpMarket ? '-' : '/'} - -
- {isPerpMarket ? 'PERP' : groupConfig.quoteSymbol} + +
+
{baseSymbol}
+ + {isPerpMarket ? '-' : '/'} + +
+ {isPerpMarket ? 'PERP' : groupConfig.quoteSymbol} +
+ + {initLeverage}x +
- - {initLeverage}x - -
+ {({ open }) => ( <> diff --git a/pages/select.tsx b/pages/select.tsx new file mode 100644 index 00000000..482a3c8a --- /dev/null +++ b/pages/select.tsx @@ -0,0 +1,152 @@ +import { useTranslation } from 'next-i18next' +import { useEffect, useState } from 'react' +import { EyeIcon, EyeOffIcon } from '@heroicons/react/outline' +import { ChevronRightIcon } from '@heroicons/react/solid' +import useLocalStorageState from '../hooks/useLocalStorageState' +import useMangoGroupConfig from '../hooks/useMangoGroupConfig' +import useMangoStore from '../stores/useMangoStore' +import Link from 'next/link' +import { formatUsdValue } from '../utils' +import { serverSideTranslations } from 'next-i18next/serverSideTranslations' + +export async function getStaticProps({ locale }) { + return { + props: { + ...(await serverSideTranslations(locale, ['common', 'tv-chart'])), + // Will be passed to the page component as props + }, + } +} + +const SelectMarket = () => { + const { t } = useTranslation('common') + const groupConfig = useMangoGroupConfig() + const mangoGroup = useMangoStore((s) => s.selectedMangoGroup.current) + const mangoCache = useMangoStore((s) => s.selectedMangoGroup.cache) + + const [markets, setMarkets] = useState([]) + + const [hiddenMarkets, setHiddenMarkets] = useLocalStorageState( + 'hiddenMarkets', + [] + ) + + useEffect(() => { + const markets = [] + const allMarkets = [...groupConfig.spotMarkets, ...groupConfig.perpMarkets] + allMarkets.forEach((market) => { + const base = market.name.slice(0, -5) + const found = markets.find((b) => b.baseAsset === base) + if (!found) { + markets.push({ baseAsset: base, markets: [market] }) + } else { + found.markets.push(market) + } + }) + setMarkets(markets) + }, []) + + const handleHideShowMarket = (asset) => { + if (hiddenMarkets.includes(asset)) { + setHiddenMarkets(hiddenMarkets.filter((m) => m !== asset)) + } else { + setHiddenMarkets(hiddenMarkets.concat(asset)) + } + } + + return ( +
+
+
{t('markets')}
+ {/*hiddenMarkets.length === 0 ? ( + + setHiddenMarkets(markets.map((mkt) => mkt.baseAsset)) + } + > + {t('hide-all')} + + ) : ( + setHiddenMarkets([])} + > + {t('show-all')} + + )*/} +
+ {markets.map((mkt) => ( +
+
+
+ + {mkt.baseAsset} +
+
+ {hiddenMarkets.includes(mkt.baseAsset) ? ( + handleHideShowMarket(mkt.baseAsset)} + /> + ) : ( + handleHideShowMarket(mkt.baseAsset)} + /> + )} +
+
+ {/*
+ Markets +
+ + Price + + + 24h Change + + + 24h Vol + +
+
*/} + +
+ ))} + {/* spacer so last market can be selected albeit bottom bar overlay */} +

+
+ ) +} + +export default SelectMarket