Skip to content

Commit e244c10

Browse files
authored
Merge pull request #169 from rupato-deriv/Rupato/BOT-2436/Fix-for-currency-on-trade-definition-block
Rupato/BOT-2436/fix: for currency on trade definition block
2 parents 0e33c48 + 4ee7571 commit e244c10

File tree

9 files changed

+31
-30
lines changed

9 files changed

+31
-30
lines changed

src/constants/quick-strategies/d_alembert.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export const D_ALEMBERT = (): TDescriptionItem[] => [
6464
{
6565
type: 'media',
6666
src: getImageLocation('dalembert.svg'),
67-
alt: localize("An example of D’Alembert's Grind strategy"),
67+
alt: localize('An example of D’Alembert strategy'),
6868
},
6969
{
7070
type: 'text',

src/external/bot-skeleton/scratch/blocks/Binary/Trade Definition/accumulator_take_profit.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { getCurrencyDisplayCode } from '@/components/shared';
22
import { localize } from '@deriv-com/translations';
33
import { config } from '../../../../constants/config';
4-
import { excludeOptionFromContextMenu, modifyContextMenu } from '../../../utils';
4+
import { excludeOptionFromContextMenu, modifyContextMenu, setCurrency } from '../../../utils';
55

66
const description = localize(
77
'Your contract is closed automatically when your profit is more than or equals to this amount. This block can only be used with the accumulator trade type.'
@@ -50,9 +50,10 @@ window.Blockly.Blocks.accumulator_take_profit = {
5050
}
5151
if (
5252
(event.type === window.Blockly.Events.BLOCK_CREATE && event.ids.includes(this.id)) ||
53-
(event.type === window.Blockly.Events.BLOCK_DRAG && !event.isStart)
53+
(event.type === window.Blockly.Events.BLOCK_DRAG && !event.isStart) ||
54+
(event.type === window.Blockly.Events.BLOCK_CHANGE && !event.isStart)
5455
) {
55-
this.setCurrency();
56+
setCurrency(this);
5657
}
5758
},
5859
customContextMenu(menu) {
@@ -61,7 +62,6 @@ window.Blockly.Blocks.accumulator_take_profit = {
6162
modifyContextMenu(menu);
6263
},
6364
restricted_parents: ['trade_definition_accumulator'],
64-
setCurrency: window.Blockly.Blocks.trade_definition_tradeoptions.setCurrency,
6565
getRequiredValueInputs() {
6666
const field_input = this.getInput('AMOUNT');
6767
if (field_input.connection.targetBlock()) {

src/external/bot-skeleton/scratch/blocks/Binary/Trade Definition/multiplier_stop_loss.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { getCurrencyDisplayCode } from '@/components/shared';
22
import { localize } from '@deriv-com/translations';
33
import { config } from '../../../../constants/config';
4-
import { modifyContextMenu } from '../../../utils';
4+
import { modifyContextMenu, setCurrency } from '../../../utils';
55

66
const description = localize(
77
'Your contract is closed automatically when your loss is more than or equals to this amount. This block can only be used with the multipliers trade type.'
@@ -53,13 +53,13 @@ window.Blockly.Blocks.multiplier_stop_loss = {
5353
}
5454
if (
5555
(event.type === window.Blockly.Events.BLOCK_CREATE && event.ids.includes(this.id)) ||
56-
(event.type === window.Blockly.Events.BLOCK_DRAG && !event.isStart)
56+
(event.type === window.Blockly.Events.BLOCK_DRAG && !event.isStart) ||
57+
(event.type === window.Blockly.Events.BLOCK_CHANGE && !event.isStart)
5758
) {
58-
this.setCurrency();
59+
setCurrency(this);
5960
}
6061
},
6162
restricted_parents: ['trade_definition_multiplier'],
62-
setCurrency: window.Blockly.Blocks.trade_definition_tradeoptions.setCurrency,
6363
getRequiredValueInputs() {
6464
const field_input = this.getInput('AMOUNT');
6565
if (field_input.connection.targetBlock()) {

src/external/bot-skeleton/scratch/blocks/Binary/Trade Definition/multiplier_take_profit.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { getCurrencyDisplayCode } from '@/components/shared';
22
import { localize } from '@deriv-com/translations';
33
import { config } from '../../../../constants/config';
4-
import { modifyContextMenu } from '../../../utils';
4+
import { modifyContextMenu, setCurrency } from '../../../utils';
55

66
const description = localize(
77
'Your contract is closed automatically when your profit is more than or equals to this amount. This block can only be used with the multipliers trade type.'
@@ -53,13 +53,13 @@ window.Blockly.Blocks.multiplier_take_profit = {
5353
}
5454
if (
5555
(event.type === window.Blockly.Events.BLOCK_CREATE && event.ids.includes(this.id)) ||
56-
(event.type === window.Blockly.Events.BLOCK_DRAG && !event.isStart)
56+
(event.type === window.Blockly.Events.BLOCK_DRAG && !event.isStart) ||
57+
(event.type === window.Blockly.Events.BLOCK_CHANGE && !event.isStart)
5758
) {
58-
this.setCurrency();
59+
setCurrency(this);
5960
}
6061
},
6162
restricted_parents: ['trade_definition_multiplier'],
62-
setCurrency: window.Blockly.Blocks.trade_definition_tradeoptions.setCurrency,
6363
getRequiredValueInputs() {
6464
const field_input = this.getInput('AMOUNT');
6565
if (field_input.connection.targetBlock()) {

src/external/bot-skeleton/scratch/blocks/Binary/Trade Definition/trade_definition_accumulator.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { config } from '../../../../constants/config';
44
import ApiHelpers from '../../../../services/api/api-helpers';
55
import { handleProposalRequestForAccumulators } from '../../../accumulators-proposal-handler';
66
import DBotStore from '../../../dbot-store';
7-
import { modifyContextMenu, runGroupedEvents, runIrreversibleEvents } from '../../../utils';
7+
import { modifyContextMenu, runGroupedEvents, runIrreversibleEvents, setCurrency } from '../../../utils';
88

99
window.Blockly.Blocks.trade_definition_accumulator = {
1010
init() {
@@ -127,7 +127,7 @@ window.Blockly.Blocks.trade_definition_accumulator = {
127127
const is_load_event = /^dbot-load/.test(event.group);
128128

129129
if (event.type === window.Blockly.Events.BLOCK_CREATE && event.ids.includes(this.id)) {
130-
this.setCurrency();
130+
setCurrency(this);
131131
if (is_load_event) {
132132
// Do NOT touch any values when a strategy is being loaded.
133133
this.updateAccumulatorInput(false);
@@ -138,6 +138,7 @@ window.Blockly.Blocks.trade_definition_accumulator = {
138138
}
139139

140140
if (event.type === window.Blockly.Events.BLOCK_CHANGE) {
141+
setCurrency(this);
141142
this.validateBlocksInStatement();
142143
if (is_load_event) {
143144
if (event.name === 'TRADETYPE_LIST') {
@@ -159,7 +160,6 @@ window.Blockly.Blocks.trade_definition_accumulator = {
159160
}
160161

161162
if (event.type === window.Blockly.Events.BLOCK_DRAG && !event.isStart) {
162-
this.setCurrency();
163163
this.validateBlocksInStatement();
164164
if (event.blockId === this.id) {
165165
// Ensure this block is populated after initial drag from flyout.
@@ -238,7 +238,6 @@ window.Blockly.Blocks.trade_definition_accumulator = {
238238
customContextMenu(menu) {
239239
modifyContextMenu(menu);
240240
},
241-
setCurrency: window.Blockly.Blocks.trade_definition_tradeoptions.setCurrency,
242241
restricted_parents: ['trade_definition'],
243242
getRequiredValueInputs() {
244243
return {

src/external/bot-skeleton/scratch/blocks/Binary/Trade Definition/trade_definition_multiplier.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { localize } from '@deriv-com/translations';
33
import { config } from '../../../../constants/config';
44
import ApiHelpers from '../../../../services/api/api-helpers';
55
import DBotStore from '../../../dbot-store';
6-
import { modifyContextMenu, runGroupedEvents, runIrreversibleEvents } from '../../../utils';
6+
import { modifyContextMenu, runGroupedEvents, runIrreversibleEvents, setCurrency } from '../../../utils';
77

88
window.Blockly.Blocks.trade_definition_multiplier = {
99
init() {
@@ -134,7 +134,7 @@ window.Blockly.Blocks.trade_definition_multiplier = {
134134
const is_load_event = /^dbot-load/.test(event.group);
135135

136136
if (event.type === window.Blockly.Events.BLOCK_CREATE && event.ids.includes(this.id)) {
137-
this.setCurrency();
137+
setCurrency(this);
138138
if (is_load_event) {
139139
// Do NOT touch any values when a strategy is being loaded.
140140
this.updateMultiplierInput(false);
@@ -145,6 +145,7 @@ window.Blockly.Blocks.trade_definition_multiplier = {
145145
}
146146

147147
if (event.type === window.Blockly.Events.BLOCK_CHANGE) {
148+
setCurrency(this);
148149
this.validateBlocksInStatement();
149150
if (is_load_event) {
150151
if (event.name === 'TRADETYPE_LIST') {
@@ -166,7 +167,6 @@ window.Blockly.Blocks.trade_definition_multiplier = {
166167
}
167168

168169
if (event.type === window.Blockly.Events.BLOCK_DRAG && !event.isStart) {
169-
this.setCurrency();
170170
this.validateBlocksInStatement();
171171
if (event.blockId === this.id) {
172172
// Ensure this block is populated after initial drag from flyout.
@@ -245,7 +245,6 @@ window.Blockly.Blocks.trade_definition_multiplier = {
245245
customContextMenu(menu) {
246246
modifyContextMenu(menu);
247247
},
248-
setCurrency: window.Blockly.Blocks.trade_definition_tradeoptions.setCurrency,
249248
restricted_parents: ['trade_definition'],
250249
getRequiredValueInputs() {
251250
return {

src/external/bot-skeleton/scratch/blocks/Binary/Trade Definition/trade_definition_tradeoptions.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { localize } from '@deriv-com/translations';
44
import { config } from '../../../../constants/config';
55
import ApiHelpers from '../../../../services/api/api-helpers';
66
import DBotStore from '../../../dbot-store';
7-
import { modifyContextMenu, runGroupedEvents, runIrreversibleEvents } from '../../../utils';
7+
import { modifyContextMenu, runGroupedEvents, runIrreversibleEvents, setCurrency } from '../../../utils';
88

99
window.Blockly.Blocks.trade_definition_tradeoptions = {
1010
durations: [],
@@ -119,7 +119,7 @@ window.Blockly.Blocks.trade_definition_tradeoptions = {
119119
(event.type === window.Blockly.Events.BLOCK_CREATE && event.ids.includes(this.id)) ||
120120
(event.type === window.Blockly.Events.BLOCK_DRAG && !event.isStart)
121121
) {
122-
this.setCurrency();
122+
setCurrency(this);
123123
this.updateAmountLimits();
124124
}
125125

@@ -524,11 +524,6 @@ window.Blockly.Blocks.trade_definition_tradeoptions = {
524524

525525
return container;
526526
},
527-
setCurrency() {
528-
const currency_field = this.getField('CURRENCY_LIST');
529-
const { currency } = DBotStore.instance.client;
530-
currency_field?.setText(getCurrencyDisplayCode(currency));
531-
},
532527
restricted_parents: ['trade_definition'],
533528
getRequiredValueInputs() {
534529
return {

src/external/bot-skeleton/scratch/utils/index.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { botNotification } from '@/components/bot-notification/bot-notification';
22
import { notification_message } from '@/components/bot-notification/bot-notification-utils';
3+
import { getCurrencyDisplayCode } from '@/components/shared';
34
import { localize } from '@deriv-com/translations';
45
import { config } from '../../constants/config';
56
import { LogTypes } from '../../constants/messages';
@@ -751,3 +752,9 @@ export const appendCollapsedProcedureBlocksFields = instance => {
751752
remove_last_input(collapsed_input);
752753
}
753754
};
755+
756+
export const setCurrency = block_instance => {
757+
const currency_field = block_instance.getField('CURRENCY_LIST');
758+
const { currency } = DBotStore.instance.client;
759+
currency_field?.setValue(getCurrencyDisplayCode(currency));
760+
};

src/stores/app-store.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
standalone_routes,
88
} from '@/components/shared';
99
import { api_base, ApiHelpers, DBot, runIrreversibleEvents } from '@/external/bot-skeleton';
10+
import { setCurrency } from '@/external/bot-skeleton/scratch/utils';
1011
import { TApiHelpersStore } from '@/types/stores.types';
1112
import { localize } from '@deriv-com/translations';
1213
import RootStore from './root-store';
@@ -224,7 +225,7 @@ export default class AppStore {
224225
// Syncs all trade options blocks' currency with the client's active currency.
225226
this.disposeCurrencyReaction = reaction(
226227
() => this.core.client.currency,
227-
currency => {
228+
() => {
228229
if (!window.Blockly?.derivWorkspace) return;
229230

230231
const trade_options_blocks = window.Blockly?.derivWorkspace
@@ -237,7 +238,7 @@ export default class AppStore {
237238
(b.isDescendantOf('trade_definition_multiplier') && b.category_ === 'trade_parameters')
238239
);
239240

240-
trade_options_blocks.forEach(trade_options_block => trade_options_block.setCurrency(currency));
241+
trade_options_blocks.forEach(trade_options_block => setCurrency(trade_options_block));
241242
}
242243
);
243244
};

0 commit comments

Comments
 (0)