forked from binary-com/deriv-app
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
maryia/DTRA-260/TS migration of /Constants files & SmartChart/Helpers…
… files in Trader (#6) * feat: validation-rules and ui.js to ts * chore: squash merge maryia/WEBREL-321/actions-to-TS changes * chore: added types to validation-rules.ts * chore: remove unused ui.js, migrate used ui.js and index.js to ts * chore: remove unused ui.js * chore: remove unused markers.js, and migrate barriers.js to ts * chore: added types to barriers.js and its test * test: add missing test for removeBarrier to barriers * Revert "chore: squash merge maryia/WEBREL-321/actions-to-TS changes" * feat: migrated chart-barrier-store.js to ts * feat: remove unused ChartMarkerStore * build: trigger build * fix: address review comments
- Loading branch information
1 parent
b2695eb
commit 4269754
Showing
14 changed files
with
352 additions
and
399 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 0 additions & 59 deletions
59
packages/trader/src/Stores/Modules/SmartChart/Constants/markers.js
This file was deleted.
Oops, something went wrong.
58 changes: 0 additions & 58 deletions
58
packages/trader/src/Stores/Modules/SmartChart/Helpers/__tests__/barriers.js
This file was deleted.
Oops, something went wrong.
50 changes: 50 additions & 0 deletions
50
packages/trader/src/Stores/Modules/SmartChart/Helpers/__tests__/barriers.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import * as Barriers from '../barriers'; | ||
|
||
describe('Barriers', () => { | ||
describe('barriersToString', () => { | ||
it('should convert non-zero barriers which do not have +/- to string consisting of them without +/- while is_relative is false', () => { | ||
expect(Barriers.barriersToString(false, 10, 15)).toEqual(['10', '15']); | ||
}); | ||
it('should convert values without +/- and zero to string consisting of them without +/- while is_relative is false', () => { | ||
expect(Barriers.barriersToString(false, 0, 15)).toEqual(['0', '15']); | ||
}); | ||
it('should convert barriers which have +/- to string consisting of them without +/- while is_relative is false', () => { | ||
expect(Barriers.barriersToString(false, +11, 15)).toEqual(['11', '15']); | ||
}); | ||
it('should convert barriers which have +/- to string consisting of them with +/- while is_relative is true', () => { | ||
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 key_to_remove = BARRIERS_KEYS.TAKE_PROFIT; | ||
Barriers.removeBarrier(barriers, key_to_remove); | ||
expect(barriers.find(barrier => barrier.key === key_to_remove)).toBeUndefined(); | ||
expect(barriers.length).toEqual(2); | ||
}); | ||
it('should not remove any barriers if the key is not found', () => { | ||
Barriers.removeBarrier(barriers, BARRIERS_KEYS.STOP_LOSS); | ||
expect(barriers.length).toEqual(3); | ||
}); | ||
it('should not modify the barriers array if it is empty', () => { | ||
const key_to_remove = BARRIERS_KEYS.STOP_OUT; | ||
const empty_barriers = [] as Barriers.TBarrier[]; | ||
Barriers.removeBarrier(empty_barriers, key_to_remove); | ||
expect(empty_barriers.length).toEqual(0); | ||
}); | ||
}); | ||
}); |
28 changes: 0 additions & 28 deletions
28
packages/trader/src/Stores/Modules/SmartChart/Helpers/barriers.js
This file was deleted.
Oops, something went wrong.
18 changes: 18 additions & 0 deletions
18
packages/trader/src/Stores/Modules/SmartChart/Helpers/barriers.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import type { ChartBarrierStore } from '../chart-barrier-store'; | ||
|
||
export type TBarrier = ChartBarrierStore & { key?: string }; | ||
|
||
export const barriersToString = ( | ||
is_relative: boolean, | ||
...barriers_list: Array<string | number | undefined> | ||
): Array<string | undefined> => | ||
barriers_list | ||
.filter(barrier => barrier !== undefined && barrier !== null) | ||
.map(barrier => `${is_relative && !/^[+-]/.test(`${barrier}`) ? '+' : ''}${barrier}`); | ||
|
||
export const removeBarrier = (barriers: TBarrier[], key: string) => { | ||
const index = barriers.findIndex(b => b.key === key); | ||
if (index > -1) { | ||
barriers.splice(index, 1); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 0 additions & 16 deletions
16
packages/trader/src/Stores/Modules/SmartChart/chart-marker-store.js
This file was deleted.
Oops, something went wrong.
11 changes: 0 additions & 11 deletions
11
packages/trader/src/Stores/Modules/Trading/Constants/ui.js
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.