@@ -9,7 +9,7 @@ import type { RefObject } from "react";
99import { useEffect , useRef , useCallback } from "react" ;
1010import { z } from "zod" ;
1111
12- import theme from "./theme .module.scss" ;
12+ import styles from "./chart .module.scss" ;
1313import { useLivePriceData } from "../../hooks/use-live-price-data" ;
1414import { Cluster } from "../../services/pyth" ;
1515
@@ -22,14 +22,18 @@ export const Chart = ({ symbol, feedId }: Props) => {
2222 const chartContainerRef = useChart ( symbol , feedId ) ;
2323
2424 return (
25- < div style = { { width : "100%" , height : "100%" } } ref = { chartContainerRef } />
25+ < div
26+ style = { { width : "100%" , height : "100%" } }
27+ className = { styles . chart }
28+ ref = { chartContainerRef }
29+ />
2630 ) ;
2731} ;
2832
2933const useChart = ( symbol : string , feedId : string ) => {
3034 const { chartContainerRef, chartRef } = useChartElem ( symbol , feedId ) ;
3135 useChartResize ( chartContainerRef , chartRef ) ;
32- useChartColors ( chartRef ) ;
36+ useChartColors ( chartContainerRef , chartRef ) ;
3337 return chartContainerRef ;
3438} ;
3539
@@ -217,17 +221,24 @@ const useChartResize = (
217221 } ) ;
218222} ;
219223
220- const useChartColors = ( chartRef : RefObject < ChartRefContents | undefined > ) => {
224+ const useChartColors = (
225+ chartContainerRef : RefObject < HTMLDivElement | null > ,
226+ chartRef : RefObject < ChartRefContents | undefined > ,
227+ ) => {
221228 const { resolvedTheme } = useTheme ( ) ;
222229 useEffect ( ( ) => {
223- if ( chartRef . current && resolvedTheme ) {
224- applyColors ( chartRef . current , resolvedTheme ) ;
230+ if ( chartRef . current && chartContainerRef . current && resolvedTheme ) {
231+ applyColors ( chartRef . current , chartContainerRef . current , resolvedTheme ) ;
225232 }
226- } , [ resolvedTheme , chartRef ] ) ;
233+ } , [ resolvedTheme , chartRef , chartContainerRef ] ) ;
227234} ;
228235
229- const applyColors = ( { chart, ...series } : ChartRefContents , theme : string ) => {
230- const colors = getColors ( theme ) ;
236+ const applyColors = (
237+ { chart, ...series } : ChartRefContents ,
238+ container : HTMLDivElement ,
239+ theme : string ,
240+ ) => {
241+ const colors = getColors ( container , theme ) ;
231242 chart . applyOptions ( {
232243 grid : {
233244 horzLines : {
@@ -260,12 +271,20 @@ const applyColors = ({ chart, ...series }: ChartRefContents, theme: string) => {
260271 }
261272} ;
262273
263- const getColors = ( resolvedTheme : string ) => ( {
264- border : theme [ `border-${ resolvedTheme } ` ] ?? "red" ,
265- muted : theme [ `muted-${ resolvedTheme } ` ] ?? "" ,
266- chartNeutral : theme [ `chart-series-neutral-${ resolvedTheme } ` ] ?? "" ,
267- chartPrimary : theme [ `chart-series-primary-${ resolvedTheme } ` ] ?? "" ,
268- } ) ;
274+ const getColors = ( container : HTMLDivElement , resolvedTheme : string ) => {
275+ const style = getComputedStyle ( container ) ;
276+
277+ return {
278+ border : style . getPropertyValue ( `--border-${ resolvedTheme } ` ) ,
279+ muted : style . getPropertyValue ( `--muted-${ resolvedTheme } ` ) ,
280+ chartNeutral : style . getPropertyValue (
281+ `--chart-series-neutral-${ resolvedTheme } ` ,
282+ ) ,
283+ chartPrimary : style . getPropertyValue (
284+ `--chart-series-primary-${ resolvedTheme } ` ,
285+ ) ,
286+ } ;
287+ } ;
269288
270289const getLocalTimestamp = ( date : Date ) : UTCTimestamp =>
271290 ( Date . UTC (
0 commit comments