add a state variable to track header ready state in trading view

This commit is contained in:
tjs 2023-03-06 14:50:07 -05:00
parent 317ba218d6
commit 90ab423d78
1 changed files with 6 additions and 1 deletions

View File

@ -69,6 +69,7 @@ const TradingViewChart = () => {
const { theme } = useTheme()
const { width } = useViewport()
const [chartReady, setChartReady] = useState(false)
const [headerReady, setHeaderReady] = useState(false)
const [spotOrPerp, setSpotOrPerp] = useState('spot')
const [showOrderLinesLocalStorage, toggleShowOrderLinesLocalStorage] =
useLocalStorageState(SHOW_ORDER_LINES_KEY, true)
@ -746,6 +747,9 @@ const TradingViewChart = () => {
tvWidgetRef.current.onChartReady(() => {
setChartReady(true)
})
tvWidgetRef.current.headerReady().then(() => {
setHeaderReady(true)
})
}
}, [theme, defaultProps, isMobile])
@ -753,13 +757,14 @@ const TradingViewChart = () => {
useEffect(() => {
if (
chartReady &&
headerReady &&
!orderLinesButtonRef.current &&
!stablePriceButtonRef.current
) {
createOLButton()
createStablePriceButton()
}
}, [createOLButton, chartReady, createStablePriceButton])
}, [createOLButton, chartReady, createStablePriceButton, headerReady])
// update order lines if a user's open orders change
useEffect(() => {