-
Notifications
You must be signed in to change notification settings - Fork 66
/
useOrderbookCandles.ts
40 lines (35 loc) · 1.12 KB
/
useOrderbookCandles.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import { useEffect } from 'react';
import { TOGGLE_ACTIVE_CLASS_NAME } from '@/constants/charts';
import { TvWidget } from '@/constants/tvchart';
import abacusStateManager from '@/lib/abacus';
/**
* @description Hook to handle drawing candles with historical trades or orderbook prices
*/
export const useOrderbookCandles = ({
orderbookCandlesToggle,
orderbookCandlesToggleOn,
tvWidget,
}: {
orderbookCandlesToggle: HTMLElement | null;
orderbookCandlesToggleOn: boolean;
tvWidget?: TvWidget;
}) => {
useEffect(
// Update orderbookCandles button on toggle
() => {
if (!tvWidget) return;
tvWidget.onChartReady(() => {
tvWidget.headerReady().then(() => {
if (orderbookCandlesToggleOn) {
orderbookCandlesToggle?.classList.add(TOGGLE_ACTIVE_CLASS_NAME);
} else {
orderbookCandlesToggle?.classList.remove(TOGGLE_ACTIVE_CLASS_NAME);
}
abacusStateManager.toggleOrderbookCandles(orderbookCandlesToggleOn);
});
});
},
[orderbookCandlesToggleOn, orderbookCandlesToggle, tvWidget]
);
return { orderbookCandlesToggleOn };
};