Skip to content

Commit 8e1bca2

Browse files
authored
[DTRA] Maryia/DTRA-1032/fix: payload for actions of 'ce_contracts_set_up_form' Rudderstack event (deriv-com#14280)
* test: switchers * fix: prevent localization of duration in analytics + extra check for null * fix: duration_type * test: sendTradeParamsAnalytics * refactor: address comments * refactor: address comments * fix: send track when this.duration_units_list has 1 duration
1 parent 8ad0ed8 commit 8e1bca2

File tree

4 files changed

+28
-16
lines changed

4 files changed

+28
-16
lines changed

packages/trader/src/Modules/Trading/Components/Form/TradeParams/Duration/duration.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,9 @@ const Duration = ({
108108
if (name === 'advanced_duration_unit') {
109109
sendTradeParamsAnalytics({
110110
action: 'change_parameter_value',
111-
parameter_type: 'duration_type',
111+
durationUnit: value,
112112
parameter_field_type: 'dropdown',
113-
duration_type: duration_units_list.find(unit => unit.value === value)?.text?.toLowerCase() ?? '',
113+
parameter_type: 'duration_type',
114114
});
115115
}
116116
};

packages/trader/src/Modules/Trading/Components/Form/TradeParams/Duration/simple-duration.tsx

+3-2
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,14 @@ const SimpleDuration = observer(
5151
return filtered_arr;
5252
};
5353
const has_label = !duration_units_list.some(du => du.value === 't');
54+
const filteredMinutesAndTicksList = filterMinutesAndTicks(duration_units_list);
5455

5556
return (
5657
<>
57-
{duration_units_list.length > 1 && (
58+
{filteredMinutesAndTicksList.length > 1 && (
5859
<ButtonToggle
5960
id='dt_simple_duration_toggle'
60-
buttons_arr={filterMinutesAndTicks(duration_units_list)}
61+
buttons_arr={filteredMinutesAndTicksList}
6162
is_animated={true}
6263
name='simple_duration_unit'
6364
onChange={changeDurationUnit}

packages/trader/src/Stores/Modules/Trading/__tests__/trade-store.spec.ts

+7-5
Original file line numberDiff line numberDiff line change
@@ -257,12 +257,12 @@ beforeAll(async () => {
257257
describe('TradeStore', () => {
258258
describe('sendTradeParamsAnalytics', () => {
259259
const action = 'change_parameter_value';
260-
const payload = {
260+
const passThrough = {
261261
action,
262-
parameter_type: 'duration_type',
263262
parameter_field_type: 'dropdown',
264-
duration_type: 'minutes',
263+
parameter_type: 'duration_type',
265264
} as Partial<TEvents['ce_contracts_set_up_form']>;
265+
const payload = { ...passThrough, durationUnit: 'm' };
266266

267267
it('should send form_name, trade type & provided payload with ce_contracts_set_up_form event', async () => {
268268
const spyTrackEvent = jest.spyOn(Analytics, 'trackEvent');
@@ -271,9 +271,10 @@ describe('TradeStore', () => {
271271
mockedTradeStore.sendTradeParamsAnalytics(payload);
272272
await waitFor(() => {
273273
expect(spyTrackEvent).toHaveBeenCalledWith('ce_contracts_set_up_form', {
274+
...passThrough,
274275
form_name: 'default',
275276
trade_type_name: 'Rise/Fall',
276-
...payload,
277+
duration_type: 'minutes',
277278
});
278279
expect(spyDebouncedFunction).not.toHaveBeenCalled();
279280
});
@@ -285,9 +286,10 @@ describe('TradeStore', () => {
285286
mockedTradeStore.sendTradeParamsAnalytics(payload, true);
286287
await waitFor(() => {
287288
expect(spyTrackEvent).toHaveBeenCalledWith('ce_contracts_set_up_form', {
289+
...passThrough,
288290
form_name: 'default',
289291
trade_type_name: 'Rise/Fall',
290-
...payload,
292+
duration_type: 'minutes',
291293
});
292294
expect(spyDebouncedFunction).toHaveBeenCalled();
293295
});

packages/trader/src/Stores/Modules/Trading/trade-store.ts

+16-7
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ type TBarriersData = Record<string, never> | { barrier: string; barrier_choices:
179179

180180
const store_name = 'trade_store';
181181
const g_subscribers_map: Partial<Record<string, ReturnType<typeof WS.subscribeTicksHistory>>> = {}; // blame amin.m
182+
const ANALYTICS_DURATIONS = ['ticks', 'seconds', 'minutes', 'hours', 'days'];
182183

183184
export default class TradeStore extends BaseStore {
184185
// Control values
@@ -1020,14 +1021,13 @@ export default class TradeStore extends BaseStore {
10201021
const durationMode =
10211022
this.root_store.ui.is_advanced_duration && this.expiry_type
10221023
? this.expiry_type
1023-
: this.duration_units_list.find(({ value }) => value === this.duration_unit)
1024-
?.text ?? '';
1024+
: ANALYTICS_DURATIONS.find(value => value.startsWith(this.duration_unit)) ?? '';
10251025
this.sendTradeParamsAnalytics({
10261026
action: 'run_contract',
1027-
...(this.duration_units_list.length > 1
1028-
? { switcher_duration_mode_name: durationMode.toLowerCase() }
1027+
...(this.duration_units_list.length && durationMode
1028+
? { switcher_duration_mode_name: durationMode }
10291029
: {}),
1030-
...(this.basis_list.length > 1
1030+
...(this.basis_list.length > 1 && this.basis
10311031
? { switcher_stakepayout_mode_name: this.basis }
10321032
: {}),
10331033
});
@@ -1063,11 +1063,20 @@ export default class TradeStore extends BaseStore {
10631063
})();
10641064
};
10651065

1066-
sendTradeParamsAnalytics = (options: Partial<TEvents['ce_contracts_set_up_form']>, isDebounced?: boolean) => {
1066+
sendTradeParamsAnalytics = (
1067+
options: Partial<TEvents['ce_contracts_set_up_form']> & { durationUnit?: string },
1068+
isDebounced?: boolean
1069+
) => {
1070+
const { durationUnit, ...passThrough } = options;
10671071
const payload = {
1072+
...passThrough,
10681073
form_name: 'default',
10691074
trade_type_name: getContractTypesConfig()[this.contract_type]?.title,
1070-
...options,
1075+
...(durationUnit
1076+
? {
1077+
duration_type: ANALYTICS_DURATIONS.find(value => value.startsWith(durationUnit ?? '')) ?? '',
1078+
}
1079+
: {}),
10711080
} as TEvents['ce_contracts_set_up_form'];
10721081
if (isDebounced) {
10731082
this.debouncedSendTradeParamsAnalytics(payload);

0 commit comments

Comments
 (0)