refactor: renaming chart settings

This commit is contained in:
Matthew Russell
2023-12-12 14:20:16 -08:00
parent 304fa3d2a1
commit b6a8a0cacc
5 changed files with 18 additions and 24 deletions
@@ -1,6 +1,6 @@
import { render, screen } from '@testing-library/react';
import { ChartContainer } from './chart-container';
import { useCandlesChartSettingsStore } from './use-candles-chart-settings';
import { useChartSettingsStore } from './use-chart-settings';
import { useEnvironment } from '@vegaprotocol/environment';
jest.mock('@vegaprotocol/candles-chart', () => ({
@@ -18,7 +18,7 @@ jest.mock('@vegaprotocol/trading-view', () => ({
describe('ChartContainer', () => {
it('renders pennant if no library path is set', () => {
useCandlesChartSettingsStore.setState({
useChartSettingsStore.setState({
chartlib: 'tradingview',
});
@@ -35,7 +35,7 @@ describe('ChartContainer', () => {
});
it('renders trading view if library path is set', () => {
useCandlesChartSettingsStore.setState({
useChartSettingsStore.setState({
chartlib: 'tradingview',
});
@@ -52,7 +52,7 @@ describe('ChartContainer', () => {
});
it('renders pennant chart if stored in settings', () => {
useCandlesChartSettingsStore.setState({
useChartSettingsStore.setState({
chartlib: 'pennant',
});
@@ -1,10 +1,7 @@
import invert from 'lodash/invert';
import { Interval } from 'pennant';
import { CandlesChartContainer } from '@vegaprotocol/candles-chart';
import {
useCandlesChartSettings,
STUDY_SIZE,
} from './use-candles-chart-settings';
import { useChartSettings, STUDY_SIZE } from './use-chart-settings';
import {
TradingViewContainer,
ALLOWED_TRADINGVIEW_HOSTNAMES,
@@ -28,7 +25,7 @@ export const ChartContainer = ({ marketId }: { marketId: string }) => {
setStudies,
setStudySizes,
setOverlays,
} = useCandlesChartSettings();
} = useChartSettings();
const pennantChart = (
<CandlesChartContainer
@@ -2,9 +2,9 @@ import { render, screen, within } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { ChartMenu } from './chart-menu';
import {
useCandlesChartSettingsStore,
useChartSettingsStore,
DEFAULT_CHART_SETTINGS,
} from './use-candles-chart-settings';
} from './use-chart-settings';
import { Overlay, Study, overlayLabels, studyLabels } from 'pennant';
import { useEnvironment } from '@vegaprotocol/environment';
@@ -25,7 +25,7 @@ describe('ChartMenu', () => {
it('shows trading view option if library path is set', async () => {
useEnvironment.setState({ CHARTING_LIBRARY_PATH: 'dummy' });
useCandlesChartSettingsStore.setState({
useChartSettingsStore.setState({
chartlib: 'tradingview',
});
@@ -45,7 +45,7 @@ describe('ChartMenu', () => {
await userEvent.click(pennantOption);
expect(useCandlesChartSettingsStore.getState().chartlib).toEqual('pennant');
expect(useChartSettingsStore.getState().chartlib).toEqual('pennant');
});
describe('tradingview', () => {
@@ -53,7 +53,7 @@ describe('ChartMenu', () => {
useEnvironment.setState({ CHARTING_LIBRARY_PATH: 'dummy-path' });
// clear store each time to avoid conditional testing of defaults
useCandlesChartSettingsStore.setState({
useChartSettingsStore.setState({
chartlib: 'tradingview',
});
});
@@ -78,7 +78,7 @@ describe('ChartMenu', () => {
beforeEach(() => {
// clear store each time to avoid conditional testing of defaults
useCandlesChartSettingsStore.setState({
useChartSettingsStore.setState({
chartlib: 'pennant',
overlays: [],
studies: [],
@@ -121,7 +121,7 @@ describe('ChartMenu', () => {
});
it('should render with the correct default studies and overlays', async () => {
useCandlesChartSettingsStore.setState({
useChartSettingsStore.setState({
...DEFAULT_CHART_SETTINGS,
chartlib: 'pennant',
});
@@ -22,10 +22,7 @@ import {
import { useEnvironment } from '@vegaprotocol/environment';
import { ALLOWED_TRADINGVIEW_HOSTNAMES } from '@vegaprotocol/trading-view';
import { IconNames, type IconName } from '@blueprintjs/icons';
import {
useCandlesChartSettings,
type Chartlib,
} from './use-candles-chart-settings';
import { useChartSettings, type Chartlib } from './use-chart-settings';
import { useT } from '../../lib/use-t';
const chartTypeIcon = new Map<ChartType, IconName>([
@@ -48,7 +45,7 @@ export const ChartMenu = () => {
setType,
setStudies,
setOverlays,
} = useCandlesChartSettings();
} = useChartSettings();
const t = useT();
const contentAlign = 'end';
@@ -39,7 +39,7 @@ export const DEFAULT_CHART_SETTINGS = {
studySizes: {},
};
export const useCandlesChartSettingsStore = create<
export const useChartSettingsStore = create<
StoredSettings & {
setType: (type: ChartType) => void;
setInterval: (interval: Interval) => void;
@@ -101,8 +101,8 @@ export const useCandlesChartSettingsStore = create<
)
);
export const useCandlesChartSettings = () => {
const settings = useCandlesChartSettingsStore();
export const useChartSettings = () => {
const settings = useChartSettingsStore();
const interval: Interval = getValidItem(
settings.interval,