From b6b89a69ac7a19fdeb5a601dcea206a283b7491b Mon Sep 17 00:00:00 2001 From: saml33 Date: Tue, 29 Mar 2022 14:27:05 +1100 Subject: [PATCH] fix favorites change percentage --- components/FavoritesShortcutBar.tsx | 29 +++++++++++++++++++++++------ components/TradeNavMenu.tsx | 10 +++++----- 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/components/FavoritesShortcutBar.tsx b/components/FavoritesShortcutBar.tsx index c63d826c..3439dd81 100644 --- a/components/FavoritesShortcutBar.tsx +++ b/components/FavoritesShortcutBar.tsx @@ -9,14 +9,17 @@ import { useRouter } from 'next/router' import { initialMarket } from './SettingsModal' import * as MonoIcons from './icons' import { Transition } from '@headlessui/react' +import useMangoStore from '../stores/useMangoStore' const FavoritesShortcutBar = () => { const [favoriteMarkets] = useLocalStorageState(FAVORITE_MARKETS_KEY, []) const { width } = useViewport() const isMobile = width ? width < breakpoints.sm : false const { asPath } = useRouter() + const marketsInfo = useMangoStore((s) => s.marketsInfo) - const renderIcon = (symbol) => { + const renderIcon = (mktName) => { + const symbol = mktName.slice(0, -5) const iconName = `${symbol.slice(0, 1)}${symbol .slice(1, 4) .toLowerCase()}MonoIcon` @@ -39,18 +42,32 @@ const FavoritesShortcutBar = () => { > {favoriteMarkets.map((mkt) => { + const change24h = marketsInfo?.find((m) => m.name === mkt)?.change24h return ( - + - {renderIcon(mkt.baseSymbol)} - {mkt.name} + {renderIcon(mkt)} + {mkt} + {change24h ? ( +
= 0 + ? 'text-th-green' + : 'text-th-red' + : 'text-th-fgd-4' + }`} + > + {`${(change24h * 100).toFixed(1)}%`} +
+ ) : null}
) diff --git a/components/TradeNavMenu.tsx b/components/TradeNavMenu.tsx index 3a034eb3..530556bb 100644 --- a/components/TradeNavMenu.tsx +++ b/components/TradeNavMenu.tsx @@ -55,7 +55,7 @@ const TradeNavMenu = () => { ? perpMarketsInfo : activeMenuCategory === 'Spot' ? spotMarketsInfo - : favoriteMarkets, + : marketsInfo.filter((mkt) => favoriteMarkets.includes(mkt.name)), [activeMenuCategory, marketsInfo] ) @@ -235,20 +235,20 @@ export const FavoriteMarketButton = ({ market }) => { } const removeFromFavorites = (mkt) => { - setFavoriteMarkets(favoriteMarkets.filter((m) => m.name !== mkt.name)) + setFavoriteMarkets(favoriteMarkets.filter((m) => m.name !== mkt)) } - return favoriteMarkets.find((mkt) => mkt.name === market.name) ? ( + return favoriteMarkets.find((mkt) => mkt === market.name) ? ( ) : (