Skip to content

Commit

Permalink
[DTRA] Maryia/DTRA-1276/fix: update limit order barriers language wit…
Browse files Browse the repository at this point in the history
…hout reload + hide them for closed contracts (binary-com#15436)

* fix: limit order barriers translation on language change

* chore: keep setLimitOrderBarriers & ChartBarrierStore in trader consistent with those in core

* fix: types

* fix: hide limit order barriers for ended contract

* refactor: place barriers.ts, chart-barrier-store, limit-orders in shared as they are reused

* test: ChartBarrierStore + address sonarcloud

* fix: update/show/hide relevant limit order barriers without page reload

* test: fix failing test
  • Loading branch information
maryia-deriv committed Jun 11, 2024
1 parent 15cb9b0 commit f0ec370
Show file tree
Hide file tree
Showing 18 changed files with 281 additions and 328 deletions.
98 changes: 0 additions & 98 deletions packages/core/src/Stores/Helpers/limit-orders.js

This file was deleted.

96 changes: 0 additions & 96 deletions packages/core/src/Stores/chart-barrier-store.js

This file was deleted.

7 changes: 4 additions & 3 deletions packages/core/src/Stores/contract-store.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { action, extendObservable, observable, makeObservable, runInAction } from 'mobx';
import {
ChartBarrierStore,
isAccumulatorContract,
isDigitContract,
isEnded,
Expand All @@ -10,6 +11,7 @@ import {
isTurbosContract,
getDigitInfo,
getDisplayStatus,
getLimitOrder,
WS,
getContractUpdateConfig,
getContractValidationRules,
Expand All @@ -21,10 +23,9 @@ import {
getEndTime,
BARRIER_COLORS,
getContractStatus,
setLimitOrderBarriers,
} from '@deriv/shared';
import { getChartConfig } from './Helpers/logic';
import { setLimitOrderBarriers, getLimitOrder } from './Helpers/limit-orders';
import { ChartBarrierStore } from './chart-barrier-store';
import { createChartMarkers, calculateMarker, getAccumulatorMarkers } from './Helpers/chart-markers';
import BaseStore from './base-store';

Expand Down Expand Up @@ -292,7 +293,7 @@ export default class ContractStore extends BaseStore {
barriers: this.barriers_array,
contract_info,
contract_type,
is_over: true,
is_over: !contract_info.sell_time,
});
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/Stores/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { ChartBarrierStore } from '@deriv/shared';
import ClientStore from './client-store';
import CommonStore from './common-store';
import GTMStore from './gtm-store';
Expand All @@ -8,7 +9,6 @@ import ActiveSymbolsStore from './active-symbols-store';
import PortfolioStore from './portfolio-store';
import ContractReplayStore from './contract-replay-store';
import ContractTradeStore from './contract-trade-store';
import { ChartBarrierStore } from './chart-barrier-store';
import TradersHubStore from './traders-hub-store';

export default class RootStore {
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/Stores/portfolio-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import throttle from 'lodash.throttle';
import { action, computed, observable, reaction, makeObservable, override } from 'mobx';
import { computedFn } from 'mobx-utils';
import {
ChartBarrierStore,
isAccumulatorContract,
isEmptyObject,
isEnded,
Expand All @@ -21,11 +22,10 @@ import {
TRADE_TYPES,
removeBarrier,
routes,
setLimitOrderBarriers,
} from '@deriv/shared';
import { Money } from '@deriv/components';
import { Analytics } from '@deriv-com/analytics';
import { ChartBarrierStore } from './chart-barrier-store';
import { setLimitOrderBarriers } from './Helpers/limit-orders';

import BaseStore from './base-store';

Expand Down
33 changes: 33 additions & 0 deletions packages/shared/src/utils/helpers/__tests__/barriers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,37 @@ describe('Barriers', () => {
expect(Barriers.barriersToString(true, +11, +15)).toEqual(['+11', '+15']);
});
});

describe('removeBarrier', () => {
let barriers: Barriers.TBarrier[];
const BARRIERS_KEYS = {
PURCHASE_SPOT_BARRIER: 'PURCHASE_SPOT_BARRIER',
TAKE_PROFIT: 'take_profit',
STOP_LOSS: 'stop_loss',
STOP_OUT: 'stop_out',
};
beforeEach(() => {
barriers = [
{ key: BARRIERS_KEYS.PURCHASE_SPOT_BARRIER, high: '1111.11' },
{ key: BARRIERS_KEYS.TAKE_PROFIT, high: '2222.22' },
{ key: BARRIERS_KEYS.STOP_OUT, high: '3333.33' },
] as Barriers.TBarrier[];
});
it('should remove the barrier with a specified key from initial barriers array', () => {
const keyToRemove = BARRIERS_KEYS.TAKE_PROFIT;
Barriers.removeBarrier(barriers, keyToRemove);
expect(barriers.find(barrier => barrier.key === keyToRemove)).toBeUndefined();
expect(barriers).toHaveLength(2);
});
it('should not remove any barriers if the key is not found', () => {
Barriers.removeBarrier(barriers, BARRIERS_KEYS.STOP_LOSS);
expect(barriers).toHaveLength(3);
});
it('should not modify the barriers array if it is empty', () => {
const keyToRemove = BARRIERS_KEYS.STOP_OUT;
const emptyBarriers = [] as Barriers.TBarrier[];
Barriers.removeBarrier(emptyBarriers, keyToRemove);
expect(emptyBarriers).toHaveLength(0);
});
});
});
Loading

0 comments on commit f0ec370

Please sign in to comment.