Skip to content

Commit

Permalink
fix tv chart not ready / console errors
Browse files Browse the repository at this point in the history
  • Loading branch information
aforaleka committed Oct 3, 2024
1 parent 3b88a67 commit 91307b7
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 24 deletions.
8 changes: 4 additions & 4 deletions src/components/CollapsibleTabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export const CollapsibleTabs = <TabItemsValue extends string>({
defaultValue={defaultTab}
value={tab}
onValueChange={(v) => setTab?.(v as TabItemsValue)}
uiRefreshEnabled={uiRefresh}
$uiRefreshEnabled={uiRefresh}
asChild
>
<$CollapsibleRoot
Expand Down Expand Up @@ -112,15 +112,15 @@ export const CollapsibleTabs = <TabItemsValue extends string>({
</$TabsRoot>
);
};
const $TabsRoot = styled(TabsRoot)<{ uiRefreshEnabled: boolean }>`
const $TabsRoot = styled(TabsRoot)<{ $uiRefreshEnabled: boolean }>`
/* Overrides */
--trigger-backgroundColor: var(--color-layer-2);
--trigger-textColor: var(--color-text-0);
--trigger-active-backgroundColor: var(--color-layer-1);
--trigger-active-textColor: var(--color-text-2);
--trigger-active-underlineColor: ${({ uiRefreshEnabled }) => css`
${uiRefreshEnabled ? css`var(--color-accent);` : css`var(--color-text-2);`}
--trigger-active-underlineColor: ${({ $uiRefreshEnabled }) => css`
${$uiRefreshEnabled ? css`var(--color-accent);` : css`var(--color-text-2);`}
`};
--trigger-active-underline-size: 2px;
--trigger-underline-size: 0px;
Expand Down
17 changes: 12 additions & 5 deletions src/components/Separator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Fragment } from 'react';
import { Separator } from '@radix-ui/react-separator';
import styled, { css } from 'styled-components';

const StyledSeparator = styled(Separator)<{ fullHeight: boolean }>`
const StyledSeparator = styled(Separator)<{ $fullHeight: boolean }>`
flex: 0 !important;
z-index: -1;
Expand All @@ -17,10 +17,17 @@ const StyledSeparator = styled(Separator)<{ fullHeight: boolean }>`
&[data-orientation='vertical'] {
align-self: center;
width: 0;
height: ${({ fullHeight }) => (fullHeight ? css`100%;` : css`calc(100% - 1.5rem);`)}
margin: 0 !important;
border-right: solid var(--border-width) var(--color-border);
${({ $fullHeight }) =>
$fullHeight
? css`
height: 100%;
`
: css`
height: calc(100% - 1.5rem);
`}
}
`;

Expand All @@ -37,7 +44,7 @@ export const VerticalSeparator = ({
className={className}
orientation="vertical"
decorative={decorative}
fullHeight={fullHeight}
$fullHeight={fullHeight}
/>
);

Expand All @@ -59,7 +66,7 @@ export const WithSeparators = ({
{child}
{i < length - 1 && (
<StyledSeparator
fullHeight={fullHeight}
$fullHeight={fullHeight}
orientation={
(
{
Expand Down
8 changes: 4 additions & 4 deletions src/components/Tabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export const Tabs = <TabItemsValue extends string>({
onWheel={onWheel}
$side={side}
$withInnerBorder={withBorders || withUnderline}
uiRefreshEnabled={uiRefresh}
$uiRefreshEnabled={uiRefresh}
>
<$Header $side={side}>{triggers}</$Header>

Expand Down Expand Up @@ -154,7 +154,7 @@ export const Tabs = <TabItemsValue extends string>({
const $Root = styled(Root)<{
$side: 'top' | 'bottom';
$withInnerBorder?: boolean;
uiRefreshEnabled: boolean;
$uiRefreshEnabled: boolean;
}>`
/* Overrides */
--trigger-backgroundColor: var(--color-layer-2);
Expand All @@ -163,8 +163,8 @@ const $Root = styled(Root)<{
--trigger-active-backgroundColor: var(--color-layer-1);
--trigger-active-textColor: var(--color-text-2);
--trigger-hover-textColor: var(--trigger-active-textColor);
--trigger-active-underlineColor: ${({ uiRefreshEnabled }) => css`
${uiRefreshEnabled ? css`var(--color-accent);` : css`var(--color-text-2);`}
--trigger-active-underlineColor: ${({ $uiRefreshEnabled }) => css`
${$uiRefreshEnabled ? css`var(--color-accent);` : css`var(--color-text-2);`}
`};
--trigger-active-underline-backgroundColor: transparent;
--trigger-active-underline-size: 2px;
Expand Down
11 changes: 1 addition & 10 deletions src/hooks/tradingView/useTradingView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import type { TvWidget } from '@/constants/tvchart';
import { store } from '@/state/_store';
import { getSelectedNetwork } from '@/state/appSelectors';
import { useAppDispatch, useAppSelector } from '@/state/appTypes';
import { getAppColorMode, getAppTheme, getSelectedDisplayUnit } from '@/state/configsSelectors';
import { getAppColorMode, getAppTheme } from '@/state/configsSelectors';
import { getSelectedLocale } from '@/state/localizationSelectors';
import { getCurrentMarketConfig, getCurrentMarketId } from '@/state/perpetualsSelectors';
import { updateChartConfig } from '@/state/tradingView';
Expand Down Expand Up @@ -260,14 +260,5 @@ export const useTradingView = ({
tvWidgetRef,
]);

const displayUnit = useAppSelector(getSelectedDisplayUnit);
useEffect(() => {
// when display unit is toggled, update bars volume to be the correct unit
if (tvWidgetRef.current) {
const chart = tvWidgetRef.current.activeChart?.();
chart.resetData();
}
}, [displayUnit]);

return { savedResolution };
};
12 changes: 11 additions & 1 deletion src/views/charts/TradingView/TvChart.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useRef, useState } from 'react';
import { useEffect, useRef, useState } from 'react';

import type { ResolutionString } from 'public/tradingview/charting_library';

Expand All @@ -14,6 +14,7 @@ import { useTradingViewTheme } from '@/hooks/tradingView/useTradingViewTheme';
import { useTradingViewToggles } from '@/hooks/tradingView/useTradingViewToggles';

import { useAppSelector } from '@/state/appTypes';
import { getSelectedDisplayUnit } from '@/state/configsSelectors';
import { getCurrentMarketId } from '@/state/perpetualsSelectors';

import { BaseTvChart } from './BaseTvChart';
Expand Down Expand Up @@ -81,5 +82,14 @@ export const TvChart = () => {
});
useTradingViewTheme({ tvWidget, isWidgetReady, chartLines });

const displayUnit = useAppSelector(getSelectedDisplayUnit);
useEffect(() => {
if (!isChartReady || !tvWidget) return;

// when display unit is toggled, update bars volume to be the correct unit
const chart = tvWidget.activeChart?.();
chart?.resetData();
}, [displayUnit, tvWidget, isChartReady]);

return <BaseTvChart isChartReady={isChartReady} />;
};

0 comments on commit 91307b7

Please sign in to comment.