diff --git a/components/MarketsTable.tsx b/components/MarketsTable.tsx index 55417845..a3a7ade2 100644 --- a/components/MarketsTable.tsx +++ b/components/MarketsTable.tsx @@ -14,11 +14,16 @@ import { useRouter } from 'next/router' import { AreaChart, Area, XAxis, YAxis } from 'recharts' import { useTheme } from 'next-themes' -const MarketsTable = ({ isPerpMarket }) => { +const MarketsTable = ({ + isPerpMarket, + markets, +}: { + isPerpMarket?: boolean + markets: any[] +}) => { const { t } = useTranslation('common') const { width } = useViewport() const isMobile = width ? width < breakpoints.md : false - const marketsInfo = useMangoStore((s) => s.marketsInfo) const actions = useMangoStore((s) => s.actions) const coingeckoPrices = useMangoStore((s) => s.coingeckoPrices.data) const loadingCoingeckoPrices = useMangoStore((s) => s.coingeckoPrices.loading) @@ -31,290 +36,266 @@ const MarketsTable = ({ isPerpMarket }) => { } }, [coingeckoPrices]) - const perpMarketsInfo = useMemo( - () => - marketsInfo - .filter((mkt) => mkt?.name.includes('PERP')) - .sort((a, b) => b.volumeUsd24h - a.volumeUsd24h), - [marketsInfo] - ) + const { items, requestSort, sortConfig } = useSortableData(markets) - const spotMarketsInfo = useMemo( - () => - marketsInfo - .filter((mkt) => mkt?.name.includes('USDC')) - .sort((a, b) => b.volumeUsd24h - a.volumeUsd24h), - [marketsInfo] - ) - - const { items, requestSort, sortConfig } = useSortableData( - isPerpMarket ? perpMarketsInfo : spotMarketsInfo - ) - - return items.length > 0 ? ( - !isMobile ? ( - - - - - - - - {isPerpMarket ? ( - <> - - - - ) : null} - - - - - {items.map((market) => { - const { - baseSymbol, - change24h, - funding1h, - last, - name, - openInterest, - openInterestUsd, - volumeUsd24h, - } = market - const fundingApr = funding1h - ? (funding1h * 24 * 365).toFixed(2) - : '-' - const coingeckoData = coingeckoPrices.find( - (asset) => asset.symbol === baseSymbol - ) - const chartData = coingeckoData ? coingeckoData.prices : undefined - const chartColor = - change24h >= 0 - ? theme === 'Mango' - ? '#AFD803' - : '#5EBF4D' - : theme === 'Mango' - ? '#F84638' - : '#CC2929' - return ( - - - - + + + {isPerpMarket ? ( + <> + + + + ) : null} + + + ) + })} + +
- requestSort('name')} - > - - {t('market')} - - - - - requestSort('last')} - > - - {t('price')} - - - - - requestSort('change24h')} - > - - {t('rolling-change')} - - - - - requestSort('volumeUsd24h')} - > - - {t('daily-volume')} - - - - - requestSort('funding1h')} - > - - {t('average-funding')} - - - - - requestSort('openInterestUsd')} - > - - {t('open-interest')} - - - - - {t('favorite')} -
- - -
- - {name} -
-
- -
-
- {last ? ( - formatUsdValue(last) - ) : ( - {t('unavailable')} - )} -
-
- {!loadingCoingeckoPrices ? ( - chartData !== undefined ? ( - - ) : ( - t('unavailable') - ) - ) : ( -
- )} -
-
- = 0 ? 'text-th-green' : 'text-th-red'} - > - {change24h || change24h === 0 ? ( - `${(change24h * 100).toFixed(2)}%` - ) : ( - {t('unavailable')} - )} + return !isMobile ? ( + + + + + + + + {isPerpMarket ? ( + <> + + + ) : null} + + + + + {items.map((market) => { + const { + baseSymbol, + change24h, + funding1h, + last, + name, + openInterest, + openInterestUsd, + volumeUsd24h, + } = market + const fundingApr = funding1h ? (funding1h * 24 * 365).toFixed(2) : '-' + const coingeckoData = coingeckoPrices.find( + (asset) => asset.symbol === baseSymbol + ) + const chartData = coingeckoData ? coingeckoData.prices : undefined + const chartColor = + change24h >= 0 + ? theme === 'Mango' + ? '#AFD803' + : '#5EBF4D' + : theme === 'Mango' + ? '#F84638' + : '#CC2929' + return ( + + + - {isPerpMarket ? ( - <> - - - - ) : null} - - - ) - })} - -
+ requestSort('name')} + > + + {t('market')} + + + + + requestSort('last')} + > + + {t('price')} + + + + + requestSort('change24h')} + > + + {t('rolling-change')} + + + + + requestSort('volumeUsd24h')} + > + + {t('daily-volume')} + + + + + requestSort('funding1h')} + > + + {t('average-funding')} - - - {volumeUsd24h ? ( - usdFormatter(volumeUsd24h, 0) + + + + + requestSort('openInterestUsd')} + > + + {t('open-interest')} + + + + + {t('favorite')} +
+ + +
+ + {name} +
+
+ +
+
+ {last ? ( + formatUsdValue(last) ) : ( {t('unavailable')} )} -
- {funding1h ? ( - <> - {`${funding1h.toFixed(4)}%`}{' '} - {`(${fundingApr}% APR)`} - - ) : ( - - {t('unavailable')} - - )} - - {openInterestUsd ? ( - <> - {usdFormatter(openInterestUsd, 0)}{' '} - {openInterest ? ( -
- {openInterest.toLocaleString(undefined, { - maximumFractionDigits: - perpContractPrecision[baseSymbol], - })}{' '} - {baseSymbol} -
- ) : null} - - ) : ( - - {t('unavailable')} - - )} -
-
- -
-
- ) : ( - items.map((market) => { + +
+ {!loadingCoingeckoPrices ? ( + chartData !== undefined ? ( + + ) : ( + t('unavailable') + ) + ) : ( +
+ )} +
+
+ = 0 ? 'text-th-green' : 'text-th-red'} + > + {change24h || change24h === 0 ? ( + `${(change24h * 100).toFixed(2)}%` + ) : ( + {t('unavailable')} + )} + + + {volumeUsd24h ? ( + usdFormatter(volumeUsd24h, 0) + ) : ( + {t('unavailable')} + )} + + {funding1h ? ( + <> + {`${funding1h.toFixed(4)}%`}{' '} + {`(${fundingApr}% APR)`} + + ) : ( + {t('unavailable')} + )} + + {openInterestUsd ? ( + <> + {usdFormatter(openInterestUsd, 0)}{' '} + {openInterest ? ( +
+ {openInterest.toLocaleString(undefined, { + maximumFractionDigits: + perpContractPrecision[baseSymbol], + })}{' '} + {baseSymbol} +
+ ) : null} + + ) : ( + {t('unavailable')} + )} +
+
+ +
+
+ ) : ( + <> + {items.map((market) => { const { baseSymbol, change24h, funding1h, last, name } = market const fundingApr = funding1h ? (funding1h * 24 * 365).toFixed(2) : '-' const coingeckoData = coingeckoPrices.find( @@ -332,7 +313,7 @@ const MarketsTable = ({ isPerpMarket }) => { return ( router.push(`/?name=${name}`, undefined, { shallow: true, @@ -405,13 +386,11 @@ const MarketsTable = ({ isPerpMarket }) => { ) - }) - ) - ) : null + })} + + ) } -export default MarketsTable as any - const PriceChart = ({ data, width, height, color }) => ( @@ -431,3 +410,29 @@ const PriceChart = ({ data, width, height, color }) => ( ) + +export const SpotMarketsTable = () => { + const marketsInfo = useMangoStore((s) => s.marketsInfo) + + const spotMarketsInfo = useMemo( + () => + marketsInfo + .filter((mkt) => mkt?.name.includes('USDC')) + .sort((a, b) => b.volumeUsd24h - a.volumeUsd24h), + [marketsInfo] + ) + return +} + +export const PerpMarketsTable = () => { + const marketsInfo = useMangoStore((s) => s.marketsInfo) + const perpMarketsInfo = useMemo( + () => + marketsInfo + .filter((mkt) => mkt?.name.includes('PERP')) + .sort((a, b) => b.volumeUsd24h - a.volumeUsd24h), + [marketsInfo] + ) + + return +} diff --git a/components/mobile/BottomBar.tsx b/components/mobile/BottomBar.tsx index 3feb8dfd..6c60b147 100644 --- a/components/mobile/BottomBar.tsx +++ b/components/mobile/BottomBar.tsx @@ -33,7 +33,7 @@ const BottomBar = () => { return ( <> -
+
{ setActiveTab(tabName) } + const handleChangeViewIndex = (index) => { + setViewIndex(index) + } + return (
@@ -34,13 +45,36 @@ export default function Markets() {
- + {!isMobile ? ( + + ) : ( + + )}
- + {!isMobile ? ( + activeTab === 'futures' ? ( + + ) : ( + + ) + ) : ( + +
+ +
+
+ +
+
+ )}