Skip to content

Commit

Permalink
Revert "Akmal / feat: change default chart style from ticks to candles (
Browse files Browse the repository at this point in the history
deriv-com#16645)" (deriv-com#17179) (deriv-com#17182)

This reverts commit d09f4ca.

Co-authored-by: vinu-deriv <[email protected]>
  • Loading branch information
heorhi-deriv and vinu-deriv authored Oct 14, 2024
1 parent 4db57f9 commit 057d822
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 121 deletions.
75 changes: 26 additions & 49 deletions packages/core/src/Stores/contract-trade-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,10 @@ import {
isAccumulatorContractOpen,
isCallPut,
isDesktop,
isDigitContract,
isEnded,
isHighLow,
isMultiplierContract,
isTurbosContract,
isUpDownContract,
isVanillaContract,
LocalStore,
setTradeURLParams,
Expand All @@ -33,10 +31,10 @@ export default class ContractTradeStore extends BaseStore {
error_message = '';

// Chart specific observables
saved_granularity = +LocalStore.get('contract_trade.granularity');
saved_chart_type = LocalStore.get('contract_trade.chart_style');
chart_type = '';
granularity = null;
granularity = +LocalStore.get('contract_trade.granularity') || 0;
chart_type = LocalStore.get('contract_trade.chart_style') || 'line';
prev_chart_type = '';
prev_granularity = null;

// Accumulator barriers data:
accu_barriers_timeout_id = null;
Expand All @@ -47,36 +45,34 @@ export default class ContractTradeStore extends BaseStore {
super({ root_store });

makeObservable(this, {
accountSwitchListener: action.bound,
accu_barriers_timeout_id: observable,
accumulator_barriers_data: observable.struct,
accumulator_contract_barriers_data: observable.struct,
addContract: action.bound,
chart_type: observable,
clearAccumulatorBarriersData: action.bound,
clearError: action.bound,
contracts: observable.shallow,
error_message: observable,
filtered_contracts: computed,
getContractById: action.bound,
granularity: observable,
has_crossed_accu_barriers: computed,
has_error: observable,
last_contract: computed,
markers_array: computed,
onUnmount: override,
prev_contract: computed,
removeContract: action.bound,
saveChartType: action.bound,
saved_chart_type: observable,
saved_granularity: observable,
saveGranularity: action.bound,
setChartTypeAndGranularity: action.bound,
setNewAccumulatorBarriersData: action.bound,
error_message: observable,
granularity: observable,
chart_type: observable,
updateAccumulatorBarriersData: action.bound,
updateChartType: action.bound,
updateGranularity: action.bound,
markers_array: computed,
filtered_contracts: computed,
addContract: action.bound,
removeContract: action.bound,
accountSwitchListener: action.bound,
onUnmount: override,
prev_chart_type: observable,
prev_granularity: observable,
updateProposal: action.bound,
last_contract: computed,
clearError: action.bound,
getContractById: action.bound,
prev_contract: computed,
savePreviousChartMode: action.bound,
setNewAccumulatorBarriersData: action.bound,
});

this.root_store = root_store;
Expand Down Expand Up @@ -137,22 +133,6 @@ export default class ContractTradeStore extends BaseStore {
}
}

setChartTypeAndGranularity(type, granularity) {
this.chart_type = type;
this.granularity = granularity;
if (this.granularity === 0) {
this.root_store.notifications.removeNotificationMessage(switch_to_tick_chart);
}
}

saveChartType(chart_type) {
this.saved_chart_type = chart_type;
}

saveGranularity(granularity) {
this.saved_granularity = granularity;
}

updateAccumulatorBarriersData({
accumulators_high_barrier,
accumulators_low_barrier,
Expand Down Expand Up @@ -222,19 +202,12 @@ export default class ContractTradeStore extends BaseStore {
}

updateChartType(type) {
const { contract_type } = JSON.parse(sessionStorage.getItem('trade_store')) || {};
const is_ticks_contract =
isDigitContract(contract_type) || isAccumulatorContract(contract_type) || isUpDownContract(contract_type);
LocalStore.set('contract_trade.chart_style', type);
this.chart_type = type;
setTradeURLParams({ chartType: this.chart_type });
!is_ticks_contract && this.saveChartType(this.chart_type);
}

updateGranularity(granularity) {
const { contract_type } = JSON.parse(sessionStorage.getItem('trade_store')) || {};
const is_ticks_contract =
isDigitContract(contract_type) || isAccumulatorContract(contract_type) || isUpDownContract(contract_type);
const tick_chart_types = ['line', 'candles', 'hollow', 'ohlc'];

if (granularity === 0 && tick_chart_types.indexOf(this.chart_type) === -1) {
Expand All @@ -247,7 +220,11 @@ export default class ContractTradeStore extends BaseStore {
this.root_store.notifications.removeNotificationMessage(switch_to_tick_chart);
}
setTradeURLParams({ granularity: this.granularity });
!is_ticks_contract && this.saveGranularity(this.granularity);
}

savePreviousChartMode(chart_type, granularity) {
this.prev_chart_type = chart_type;
this.prev_granularity = granularity;
}

applicable_contracts = () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ import { TRADE_TYPES } from '../contract';
import { routes } from '../../routes';

const areaChartType = { text: 'area', value: 'line' };
const candleChartType = { text: 'candle', value: 'candles' };
const oneTickInterval = '1t';
const oneMinuteInterval = '1m';
const symbol = 'R_100';

describe('getTradeURLParams', () => {
Expand Down Expand Up @@ -58,10 +56,10 @@ describe('getTradeURLParams', () => {
});

it('should return an object with chartType & interval based on the URL query params when called without arguments', () => {
location.search = `?symbol=${symbol}&trade_type=${TRADE_TYPES.VANILLA}&chart_type=${candleChartType.text}&interval=${oneMinuteInterval}`;
location.search = `?symbol=${symbol}&trade_type=${TRADE_TYPES.ACCUMULATOR}&chart_type=${areaChartType.text}&interval=${oneTickInterval}`;
expect(getTradeURLParams()).toMatchObject({
chartType: candleChartType.value,
granularity: 60,
chartType: areaChartType.value,
granularity: 0,
});
});
it('should return an object without granularity if interval in the URL is incorrect', () => {
Expand All @@ -76,17 +74,24 @@ describe('getTradeURLParams', () => {
granularity: 0,
});
});
it('should return an object with "area" chartType if interval is 1t even if chart_type in the URL is valid but not area', () => {
location.search = `?symbol=${symbol}&trade_type=${TRADE_TYPES.ACCUMULATOR}&chart_type=hollow&interval=${oneTickInterval}`;
expect(getTradeURLParams()).toMatchObject({
chartType: areaChartType.value,
granularity: 0,
});
});
it('should return an object with symbol based on the URL query param when active_symbols is passed', () => {
location.search = `?symbol=${symbol}`;
expect(getTradeURLParams({ active_symbols: activeSymbols })).toMatchObject({
symbol,
});
});
it('should return an object with showModal & without symbol if symbol in the URL is incorrect and when called with active_symbols', () => {
location.search = `?symbol=BLA&chart_type=${candleChartType.text}&interval=${oneMinuteInterval}`;
location.search = `?symbol=BLA&chart_type=${areaChartType.text}&interval=${oneTickInterval}`;
expect(getTradeURLParams({ active_symbols: activeSymbols })).toMatchObject({
chartType: candleChartType.value,
granularity: 60,
chartType: areaChartType.value,
granularity: 0,
showModal: true,
});
});
Expand All @@ -97,10 +102,10 @@ describe('getTradeURLParams', () => {
});
});
it('should return an object with showModal & without contractType if trade_type in the URL is incorrect', () => {
location.search = `?trade_type=BLA&chart_type=${candleChartType.text}&interval=${oneMinuteInterval}`;
location.search = `?trade_type=BLA&chart_type=${areaChartType.text}&interval=${oneTickInterval}`;
expect(getTradeURLParams({ contract_types_list: contractTypesList })).toMatchObject({
chartType: candleChartType.value,
granularity: 60,
chartType: areaChartType.value,
granularity: 0,
showModal: true,
});
});
Expand Down
2 changes: 0 additions & 2 deletions packages/shared/src/utils/contract/contract.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,6 @@ export const isResetContract = (contract_type = '') => /RESET/i.test(contract_ty

export const isCryptoContract = (underlying = '') => underlying.startsWith('cry');

export const isUpDownContract = (contract_type = '') => /rise_fall|high_low/i.test(contract_type);

export const getAccuBarriersDefaultTimeout = (symbol: string) => {
return symbols_2s.includes(symbol) ? DELAY_TIME_1S_SYMBOL * 2 : DELAY_TIME_1S_SYMBOL;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export const getTradeURLParams = ({ active_symbols = [], contract_types_list = {
}>((acc, [key, value]) => ({ ...acc, [key]: value }), {});
const validInterval = tradeURLParamsConfig.interval.find(item => item.text === interval);
const validChartType = tradeURLParamsConfig.chartType.find(item => item.text === chart_type);
const chartTypeParam = Number(validInterval?.value) === 0 ? 'candles' : validChartType?.value;
const chartTypeParam = Number(validInterval?.value) === 0 ? 'line' : validChartType?.value;
const isSymbolValid = active_symbols.some(item => item.symbol === symbol);
const contractList = Object.keys(contract_types_list).reduce<string[]>((acc, key) => {
const categories: TTradeTypesCategories['Ups & Downs']['categories'] =
Expand Down
8 changes: 3 additions & 5 deletions packages/stores/src/mockStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -660,13 +660,11 @@ const mock = (): TStores & { is_mock: boolean } => {
last_contract: {},
markers_array: [],
onUnmount: jest.fn(),
prev_chart_type: '',
prev_contract: {},
prev_granularity: null,
removeContract: jest.fn(),
saveChartType: jest.fn(),
saved_chart_type: '',
saved_granularity: null,
saveGranularity: jest.fn(),
setChartTypeAndGranularity: jest.fn(),
savePreviousChartMode: jest.fn(),
setNewAccumulatorBarriersData: jest.fn(),
updateAccumulatorBarriersData: jest.fn(),
updateChartType: jest.fn(),
Expand Down
8 changes: 3 additions & 5 deletions packages/stores/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -986,13 +986,11 @@ type TContractTradeStore = {
epoch_array: [number];
}>;
onUnmount: () => void;
prev_chart_type: string;
prev_contract: TContractStore | Record<string, never>;
prev_granularity: number | null;
removeContract: (data: { contract_id: string }) => void;
saveChartType: (chart_type: string) => void;
saved_chart_type: string;
saved_granularity: number | null;
saveGranularity: (granularity: number | null) => void;
setChartTypeAndGranularity: any;
savePreviousChartMode: (chart_type: string, granularity: number | null) => void;
setNewAccumulatorBarriersData: (
new_barriers_data: TAccumulatorBarriersData,
should_update_contract_barriers?: boolean
Expand Down
Loading

0 comments on commit 057d822

Please sign in to comment.