Skip to content

Commit

Permalink
update marks when there are new fills
Browse files Browse the repository at this point in the history
  • Loading branch information
tinaszheng committed Aug 15, 2024
1 parent b7d25b3 commit bacdd99
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/hooks/tradingView/useBuySellMarks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ import { Dispatch, SetStateAction, useEffect } from 'react';

import { TvWidget } from '@/constants/tvchart';

import { getMarketFills } from '@/state/accountSelectors';
import { useAppSelector } from '@/state/appTypes';
import { getCurrentMarketId } from '@/state/perpetualsSelectors';

/**
* @description Hook to handle marks for historic buys and sells on the TV chart
*/
Expand All @@ -18,8 +22,12 @@ export function useBuySellMarks({
tvWidget: TvWidget | null;
isChartReady: boolean;
}) {
const marketId = useAppSelector(getCurrentMarketId);
const fills = useAppSelector(getMarketFills);
const currentMarketFills = marketId ? fills[marketId] : undefined;

useEffect(() => {
// Initialize onClick for orderbook candles toggle
// Initialize onClick for Buys/Sells toggle
if (isChartReady && buySellMarksToggle) {
buySellMarksToggle.onclick = () => setBuySellMarksToggleOn((prev) => !prev);
}
Expand All @@ -42,6 +50,6 @@ export function useBuySellMarks({
});
});
},
[buySellMarksToggleOn, buySellMarksToggle, tvWidget, isChartReady]
[buySellMarksToggleOn, buySellMarksToggle, tvWidget, isChartReady, currentMarketFills]
);
}

0 comments on commit bacdd99

Please sign in to comment.