Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rupato/BOT-2436/fix: for currency on trade definition block #169

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/constants/quick-strategies/d_alembert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export const D_ALEMBERT = (): TDescriptionItem[] => [
{
type: 'media',
src: getImageLocation('dalembert.svg'),
alt: localize("An example of D’Alembert's Grind strategy"),
alt: localize('An example of D’Alembert strategy'),
},
{
type: 'text',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { getCurrencyDisplayCode } from '@/components/shared';
import { localize } from '@deriv-com/translations';
import { config } from '../../../../constants/config';
import { excludeOptionFromContextMenu, modifyContextMenu } from '../../../utils';
import { excludeOptionFromContextMenu, modifyContextMenu, setCurrency } from '../../../utils';

const description = localize(
'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.'
Expand Down Expand Up @@ -50,9 +50,10 @@ window.Blockly.Blocks.accumulator_take_profit = {
}
if (
(event.type === window.Blockly.Events.BLOCK_CREATE && event.ids.includes(this.id)) ||
(event.type === window.Blockly.Events.BLOCK_DRAG && !event.isStart)
(event.type === window.Blockly.Events.BLOCK_DRAG && !event.isStart) ||
(event.type === window.Blockly.Events.BLOCK_CHANGE && !event.isStart)
) {
this.setCurrency();
setCurrency(this);
}
},
customContextMenu(menu) {
Expand All @@ -61,7 +62,6 @@ window.Blockly.Blocks.accumulator_take_profit = {
modifyContextMenu(menu);
},
restricted_parents: ['trade_definition_accumulator'],
setCurrency: window.Blockly.Blocks.trade_definition_tradeoptions.setCurrency,
getRequiredValueInputs() {
const field_input = this.getInput('AMOUNT');
if (field_input.connection.targetBlock()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { getCurrencyDisplayCode } from '@/components/shared';
import { localize } from '@deriv-com/translations';
import { config } from '../../../../constants/config';
import { modifyContextMenu } from '../../../utils';
import { modifyContextMenu, setCurrency } from '../../../utils';

const description = localize(
'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.'
Expand Down Expand Up @@ -53,13 +53,13 @@ window.Blockly.Blocks.multiplier_stop_loss = {
}
if (
(event.type === window.Blockly.Events.BLOCK_CREATE && event.ids.includes(this.id)) ||
(event.type === window.Blockly.Events.BLOCK_DRAG && !event.isStart)
(event.type === window.Blockly.Events.BLOCK_DRAG && !event.isStart) ||
(event.type === window.Blockly.Events.BLOCK_CHANGE && !event.isStart)
) {
this.setCurrency();
setCurrency(this);
}
},
restricted_parents: ['trade_definition_multiplier'],
setCurrency: window.Blockly.Blocks.trade_definition_tradeoptions.setCurrency,
getRequiredValueInputs() {
const field_input = this.getInput('AMOUNT');
if (field_input.connection.targetBlock()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { getCurrencyDisplayCode } from '@/components/shared';
import { localize } from '@deriv-com/translations';
import { config } from '../../../../constants/config';
import { modifyContextMenu } from '../../../utils';
import { modifyContextMenu, setCurrency } from '../../../utils';

const description = localize(
'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.'
Expand Down Expand Up @@ -53,13 +53,13 @@ window.Blockly.Blocks.multiplier_take_profit = {
}
if (
(event.type === window.Blockly.Events.BLOCK_CREATE && event.ids.includes(this.id)) ||
(event.type === window.Blockly.Events.BLOCK_DRAG && !event.isStart)
(event.type === window.Blockly.Events.BLOCK_DRAG && !event.isStart) ||
(event.type === window.Blockly.Events.BLOCK_CHANGE && !event.isStart)
) {
this.setCurrency();
setCurrency(this);
}
},
restricted_parents: ['trade_definition_multiplier'],
setCurrency: window.Blockly.Blocks.trade_definition_tradeoptions.setCurrency,
getRequiredValueInputs() {
const field_input = this.getInput('AMOUNT');
if (field_input.connection.targetBlock()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { config } from '../../../../constants/config';
import ApiHelpers from '../../../../services/api/api-helpers';
import { handleProposalRequestForAccumulators } from '../../../accumulators-proposal-handler';
import DBotStore from '../../../dbot-store';
import { modifyContextMenu, runGroupedEvents, runIrreversibleEvents } from '../../../utils';
import { modifyContextMenu, runGroupedEvents, runIrreversibleEvents, setCurrency } from '../../../utils';

window.Blockly.Blocks.trade_definition_accumulator = {
init() {
Expand Down Expand Up @@ -127,7 +127,7 @@ window.Blockly.Blocks.trade_definition_accumulator = {
const is_load_event = /^dbot-load/.test(event.group);

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

if (event.type === window.Blockly.Events.BLOCK_CHANGE) {
setCurrency(this);
this.validateBlocksInStatement();
if (is_load_event) {
if (event.name === 'TRADETYPE_LIST') {
Expand All @@ -159,7 +160,6 @@ window.Blockly.Blocks.trade_definition_accumulator = {
}

if (event.type === window.Blockly.Events.BLOCK_DRAG && !event.isStart) {
this.setCurrency();
this.validateBlocksInStatement();
if (event.blockId === this.id) {
// Ensure this block is populated after initial drag from flyout.
Expand Down Expand Up @@ -238,7 +238,6 @@ window.Blockly.Blocks.trade_definition_accumulator = {
customContextMenu(menu) {
modifyContextMenu(menu);
},
setCurrency: window.Blockly.Blocks.trade_definition_tradeoptions.setCurrency,
restricted_parents: ['trade_definition'],
getRequiredValueInputs() {
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { localize } from '@deriv-com/translations';
import { config } from '../../../../constants/config';
import ApiHelpers from '../../../../services/api/api-helpers';
import DBotStore from '../../../dbot-store';
import { modifyContextMenu, runGroupedEvents, runIrreversibleEvents } from '../../../utils';
import { modifyContextMenu, runGroupedEvents, runIrreversibleEvents, setCurrency } from '../../../utils';

window.Blockly.Blocks.trade_definition_multiplier = {
init() {
Expand Down Expand Up @@ -134,7 +134,7 @@ window.Blockly.Blocks.trade_definition_multiplier = {
const is_load_event = /^dbot-load/.test(event.group);

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

if (event.type === window.Blockly.Events.BLOCK_CHANGE) {
setCurrency(this);
this.validateBlocksInStatement();
if (is_load_event) {
if (event.name === 'TRADETYPE_LIST') {
Expand All @@ -166,7 +167,6 @@ window.Blockly.Blocks.trade_definition_multiplier = {
}

if (event.type === window.Blockly.Events.BLOCK_DRAG && !event.isStart) {
this.setCurrency();
this.validateBlocksInStatement();
if (event.blockId === this.id) {
// Ensure this block is populated after initial drag from flyout.
Expand Down Expand Up @@ -245,7 +245,6 @@ window.Blockly.Blocks.trade_definition_multiplier = {
customContextMenu(menu) {
modifyContextMenu(menu);
},
setCurrency: window.Blockly.Blocks.trade_definition_tradeoptions.setCurrency,
restricted_parents: ['trade_definition'],
getRequiredValueInputs() {
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { localize } from '@deriv-com/translations';
import { config } from '../../../../constants/config';
import ApiHelpers from '../../../../services/api/api-helpers';
import DBotStore from '../../../dbot-store';
import { modifyContextMenu, runGroupedEvents, runIrreversibleEvents } from '../../../utils';
import { modifyContextMenu, runGroupedEvents, runIrreversibleEvents, setCurrency } from '../../../utils';

window.Blockly.Blocks.trade_definition_tradeoptions = {
durations: [],
Expand Down Expand Up @@ -119,7 +119,7 @@ window.Blockly.Blocks.trade_definition_tradeoptions = {
(event.type === window.Blockly.Events.BLOCK_CREATE && event.ids.includes(this.id)) ||
(event.type === window.Blockly.Events.BLOCK_DRAG && !event.isStart)
) {
this.setCurrency();
setCurrency(this);
this.updateAmountLimits();
}

Expand Down Expand Up @@ -524,11 +524,6 @@ window.Blockly.Blocks.trade_definition_tradeoptions = {

return container;
},
setCurrency() {
const currency_field = this.getField('CURRENCY_LIST');
const { currency } = DBotStore.instance.client;
currency_field?.setText(getCurrencyDisplayCode(currency));
},
restricted_parents: ['trade_definition'],
getRequiredValueInputs() {
return {
Expand Down
7 changes: 7 additions & 0 deletions src/external/bot-skeleton/scratch/utils/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { botNotification } from '@/components/bot-notification/bot-notification';
import { notification_message } from '@/components/bot-notification/bot-notification-utils';
import { getCurrencyDisplayCode } from '@/components/shared';
import { localize } from '@deriv-com/translations';
import { config } from '../../constants/config';
import { LogTypes } from '../../constants/messages';
Expand Down Expand Up @@ -751,3 +752,9 @@ export const appendCollapsedProcedureBlocksFields = instance => {
remove_last_input(collapsed_input);
}
};

export const setCurrency = block_instance => {
const currency_field = block_instance.getField('CURRENCY_LIST');
const { currency } = DBotStore.instance.client;
currency_field?.setValue(getCurrencyDisplayCode(currency));
};
5 changes: 3 additions & 2 deletions src/stores/app-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
standalone_routes,
} from '@/components/shared';
import { api_base, ApiHelpers, DBot, runIrreversibleEvents } from '@/external/bot-skeleton';
import { setCurrency } from '@/external/bot-skeleton/scratch/utils';
import { TApiHelpersStore } from '@/types/stores.types';
import { localize } from '@deriv-com/translations';
import RootStore from './root-store';
Expand Down Expand Up @@ -224,7 +225,7 @@ export default class AppStore {
// Syncs all trade options blocks' currency with the client's active currency.
this.disposeCurrencyReaction = reaction(
() => this.core.client.currency,
currency => {
() => {
if (!window.Blockly?.derivWorkspace) return;

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

trade_options_blocks.forEach(trade_options_block => trade_options_block.setCurrency(currency));
trade_options_blocks.forEach(trade_options_block => setCurrency(trade_options_block));
}
);
};
Expand Down
Loading