diff --git a/src/hooks/tradingView/useTradingView.ts b/src/hooks/tradingView/useTradingView.ts index 425d068..5206e2f 100644 --- a/src/hooks/tradingView/useTradingView.ts +++ b/src/hooks/tradingView/useTradingView.ts @@ -1,6 +1,5 @@ import { useEffect } from 'react'; import { shallowEqual, useSelector } from 'react-redux'; -import { useLocation } from 'react-router-dom'; import isEmpty from 'lodash/isEmpty'; import { LanguageCode, ResolutionString, widget } from 'public/tradingview/charting_library'; @@ -14,9 +13,8 @@ import { store } from '@/state/_store'; import { getSelectedNetwork } from '@/state/appSelectors'; import { getAppTheme } from '@/state/configsSelectors'; import { getSelectedLocale } from '@/state/localizationSelectors'; -import { getMarketIds } from '@/state/perpetualsSelectors'; +import { getCurrentMarketId, getMarketIds } from '@/state/perpetualsSelectors'; -import { getMarketIdFromLocation } from '@/lib/tradeData'; import { getDydxDatafeed } from '@/lib/tradingView/dydxfeed'; import { getSavedResolution, getWidgetOptions, getWidgetOverrides } from '@/lib/tradingView/utils'; @@ -30,8 +28,7 @@ export const useTradingView = ({ tvWidgetRef: React.MutableRefObject; setIsChartReady: React.Dispatch>; }) => { - const location = useLocation(); - const marketId = getMarketIdFromLocation(location); + const marketId = useSelector(getCurrentMarketId); const appTheme = useSelector(getAppTheme); const marketIds = useSelector(getMarketIds, shallowEqual); const selectedLocale = useSelector(getSelectedLocale); @@ -50,7 +47,6 @@ export const useTradingView = ({ if (hasMarkets) { const widgetOptions = getWidgetOptions(); const widgetOverrides = getWidgetOverrides(appTheme); - console.log(marketId); const options = { // debug: true, ...widgetOptions, diff --git a/src/hooks/useCurrentMarketId.ts b/src/hooks/useCurrentMarketId.ts index 528364b..2ae40ee 100644 --- a/src/hooks/useCurrentMarketId.ts +++ b/src/hooks/useCurrentMarketId.ts @@ -29,7 +29,7 @@ export const useCurrentMarketId = () => { const validId = useMemo(() => { if (marketIds.length === 0) return marketId ?? lastViewedMarket; - if (!marketIds.includes(marketId)) return DEFAULT_MARKETID; + if (!marketIds.includes(marketId ?? lastViewedMarket)) return DEFAULT_MARKETID; return marketId ?? lastViewedMarket; }, [marketIds, marketId]);