From 1a763c8c9ddb6d087beed6cae2ef7177ef234813 Mon Sep 17 00:00:00 2001 From: tjs Date: Sun, 26 Feb 2023 20:04:02 -0500 Subject: [PATCH] fix stable price line updates --- components/trade/RecentTrades.tsx | 5 ----- components/trade/TradingViewChart.tsx | 32 ++++++++++++++++----------- hooks/useStablePrice.ts | 6 ++--- 3 files changed, 21 insertions(+), 22 deletions(-) diff --git a/components/trade/RecentTrades.tsx b/components/trade/RecentTrades.tsx index 518d5fc3..8a804a09 100644 --- a/components/trade/RecentTrades.tsx +++ b/components/trade/RecentTrades.tsx @@ -93,11 +93,6 @@ const RecentTrades = () => { } ) - console.log( - 'selectedMarket instanceof PerpMarket', - selectedMarket instanceof PerpMarket - ) - useEffect(() => { const actions = mangoStore.getState().actions if (selectedMarket) { diff --git a/components/trade/TradingViewChart.tsx b/components/trade/TradingViewChart.tsx index 8d305396..7f9a659d 100644 --- a/components/trade/TradingViewChart.tsx +++ b/components/trade/TradingViewChart.tsx @@ -189,6 +189,10 @@ const TradingViewChart = () => { if (!tvWidgetRef?.current?.chart()) return const now = Date.now() / 1000 try { + const oldId = mangoStore.getState().tradingView.stablePriceLine + if (oldId) { + tvWidgetRef.current.chart().removeEntity(oldId) + } const id = tvWidgetRef.current.chart().createShape( { time: now, price: price }, { @@ -726,24 +730,26 @@ const TradingViewChart = () => { }, } + console.log('creating new chart') + const tvWidget = new widget(widgetOptions) tvWidgetRef.current = tvWidget tvWidgetRef.current.onChartReady(function () { createOLButton() createStablePriceButton() - if (showOrderLines) { - const openOrders = mangoStore.getState().mangoAccount.openOrders - deleteLines() - drawLinesForMarket(openOrders) - } - if (showStablePrice && stablePrice) { - const set = mangoStore.getState().set - const elementId = drawStablePriceLine(stablePrice) - set((s) => { - s.tradingView.stablePriceLine = elementId - }) - } + // if (showOrderLines) { + // const openOrders = mangoStore.getState().mangoAccount.openOrders + // deleteLines() + // drawLinesForMarket(openOrders) + // } + // if (showStablePrice && stablePrice) { + // const set = mangoStore.getState().set + // const elementId = drawStablePriceLine(stablePrice) + // set((s) => { + // s.tradingView.stablePriceLine = elementId + // }) + // } setChartReady(true) }) //eslint-disable-next-line @@ -759,7 +765,7 @@ const TradingViewChart = () => { drawLinesForMarket, showOrderLines, showStablePrice, - stablePrice, + // stablePrice, drawStablePriceLine, setChartReady, isMobile, diff --git a/hooks/useStablePrice.ts b/hooks/useStablePrice.ts index 078b70bf..8f610bd2 100644 --- a/hooks/useStablePrice.ts +++ b/hooks/useStablePrice.ts @@ -1,18 +1,16 @@ import { I80F48, PerpMarket } from '@blockworks-foundation/mango-v4' -import mangoStore from '@store/mangoStore' import { useMemo } from 'react' import useMangoGroup from './useMangoGroup' import useSelectedMarket from './useSelectedMarket' const useStablePrice = () => { const { selectedMarket } = useSelectedMarket() - const perpMarkets = mangoStore((s) => s.perpMarkets) const { group } = useMangoGroup() const banks = useMemo(() => { if (!group) return [] return Array.from(group.banksMapByMint) - .map(([mintAddress, banks]) => banks) + .map(([_mintAddress, banks]) => banks) .map((b) => b[0]) }, [group]) @@ -40,7 +38,7 @@ const useStablePrice = () => { stablePrice = baseStablePrice / quoteStablePrice } return stablePrice - }, [banks, group, perpMarkets, selectedMarket]) + }, [banks, group, selectedMarket]) return stablePrice }