diff --git a/src/external/bot-skeleton/scratch/dbot.js b/src/external/bot-skeleton/scratch/dbot.js
index 9f3ea3ad..9c2f911d 100644
--- a/src/external/bot-skeleton/scratch/dbot.js
+++ b/src/external/bot-skeleton/scratch/dbot.js
@@ -402,15 +402,12 @@ class DBot {
* Disable blocks outside of any main or independent blocks.
*/
disableStrayBlocks() {
- const isMainBlock = block_type => config().mainBlocks.indexOf(block_type) >= 0;
const top_blocks = this.workspace.getTopBlocks();
-
top_blocks.forEach(block => {
- if (!isMainBlock() && !block.isIndependentBlock()) {
+ if (!block.isMainBlock() && !block.isIndependentBlock()) {
this.disableBlocksRecursively(block);
}
});
-
return true;
}
@@ -418,6 +415,7 @@ class DBot {
* Disable blocks and their optional children.
*/
disableBlocksRecursively(block) {
+ block.setDisabled(true);
if (block.nextConnection?.targetConnection) {
this.disableBlocksRecursively(block.nextConnection.targetConnection.sourceBlock_);
}
diff --git a/src/external/bot-skeleton/scratch/utils/index.js b/src/external/bot-skeleton/scratch/utils/index.js
index 9d83f9c0..a7a194f5 100644
--- a/src/external/bot-skeleton/scratch/utils/index.js
+++ b/src/external/bot-skeleton/scratch/utils/index.js
@@ -84,7 +84,7 @@ export const validateErrorOnBlockDelete = () => {
blockX >= translate_X - translate_offset &&
blockX <= translate_X + translate_offset
) {
- globalObserver.emit('ui.log.error', error_message_map[window.Blockly?.getSelected()?.type]?.default);
+ globalObserver.emit('ui.log.error', error_message_map?.()?.[window.Blockly?.getSelected()?.type]?.default);
}
}
};
@@ -412,17 +412,18 @@ const getDisabledBlocks = required_blocks_check => {
const throwNewErrorMessage = (error_blocks, key) => {
return error_blocks.forEach(block => {
- if (key === 'misplaced' && block) globalObserver.emit('ui.log.error', error_message_map[block?.type]?.[key]);
- else if (key === 'missing' && block) globalObserver.emit('ui.log.error', error_message_map[block]?.[key]);
+ if (key === 'misplaced' && block)
+ globalObserver.emit('ui.log.error', error_message_map?.()?.[block?.type]?.[key]);
+ else if (key === 'missing' && block) globalObserver.emit('ui.log.error', error_message_map?.()?.[block]?.[key]);
else if (key === 'disabled' && block) {
let parent_block_error = false;
- const parent_error_message = error_message_map[block.type]?.[key];
+ const parent_error_message = error_message_map?.()?.[block.type]?.[key];
if (block.disabled && parent_error_message) {
globalObserver.emit('ui.log.error', parent_error_message);
parent_block_error = true;
} else if (!parent_block_error && block.childBlocks_) {
block.childBlocks_.forEach(childBlock => {
- const child_error_message = error_message_map[childBlock.type]?.[key];
+ const child_error_message = error_message_map?.()?.[childBlock.type]?.[key];
if (child_error_message) globalObserver.emit('ui.log.error', child_error_message);
});
}
@@ -624,11 +625,11 @@ const downloadBlock = () => {
saveAs({ data: xml_text, type: 'text/xml;charset=utf-8', filename: 'block.xml' });
};
-const download_option = {
+const download_option = () => ({
text: localize('Download Block'),
enabled: true,
callback: downloadBlock,
-};
+});
export const excludeOptionFromContextMenu = (menu, exclude_items) => {
for (let i = 0; i <= menu.length - 1; i++) {
@@ -641,9 +642,7 @@ export const excludeOptionFromContextMenu = (menu, exclude_items) => {
}
};
-const common_included_items = [download_option];
-
-const all_context_menu_options = [
+const all_context_menu_options = () => [
localize('Duplicate'),
localize('Add Comment'),
localize('Remove Comment'),
@@ -654,10 +653,11 @@ const all_context_menu_options = [
localize('Download Block'),
];
-const deleteBlocksLocaleText = localize('Delete Block');
-const deleteAllBlocksLocaleText = localize('Delete All Blocks');
+const deleteBlocksLocaleText = () => localize('Delete Block');
+const deleteAllBlocksLocaleText = () => localize('Delete All Blocks');
export const modifyContextMenu = (menu, add_new_items = []) => {
+ const common_included_items = [download_option()];
const include_items = [...common_included_items, ...add_new_items];
include_items.forEach(item => {
menu.push({
@@ -671,13 +671,13 @@ export const modifyContextMenu = (menu, add_new_items = []) => {
const menu_text = menu[i]?.text?.toLowerCase();
if (menu_text?.includes('delete')) {
if (menu_text.includes('block') && !menu_text.includes('blocks')) {
- menu[i].text = deleteBlocksLocaleText;
+ menu[i].text = deleteBlocksLocaleText();
} else {
- menu[i].text = deleteAllBlocksLocaleText;
+ menu[i].text = deleteAllBlocksLocaleText();
}
} else {
const localized_text = localize(menu[i].text);
- if (all_context_menu_options.includes(localized_text)) {
+ if (all_context_menu_options().includes(localized_text)) {
menu[i].text = localized_text;
}
}
diff --git a/src/external/bot-skeleton/utils/error-config.js b/src/external/bot-skeleton/utils/error-config.js
index 5e9ab581..c8a8a030 100644
--- a/src/external/bot-skeleton/utils/error-config.js
+++ b/src/external/bot-skeleton/utils/error-config.js
@@ -1,45 +1,24 @@
-import { Localize } from '@deriv-com/translations';
+import { localize } from '@deriv-com/translations';
const generateErrorMessage = (block_type, missing_space = 'workspace') => {
return {
- missing: (
-
- ),
- misplaced: (
-
- ),
-
- disabled: (
-
- ),
- default: (
-
- ),
+ missing: localize('The {{block_type}} block is mandatory and cannot be deleted/disabled.', {
+ block_type,
+ }),
+ misplaced: localize('The {{block_type}} block is misplaced from {{missing_space}}.', {
+ block_type,
+ missing_space,
+ }),
+ disabled: localize('The {{block_type}} block is mandatory and cannot be deleted/disabled.', {
+ block_type,
+ }),
+ default: localize('The {{block_type}} block is mandatory and cannot be deleted/disabled.', {
+ block_type,
+ }),
};
};
-export const error_message_map = {
+export const error_message_map = () => ({
trade_definition: generateErrorMessage('Trade parameters'),
trade_parameters: generateErrorMessage('Trade parameters'),
before_purchase: generateErrorMessage('Purchase conditions'),
@@ -48,4 +27,4 @@ export const error_message_map = {
trade_definition_tradeoptions: generateErrorMessage('Trade options', 'trade parameters'),
trade_definition_multiplier: generateErrorMessage('Trade options multipliers', 'trade parameters'),
trade_definition_accumulator: generateErrorMessage('Trade options accumulators', 'trade parameters'),
-};
+});
diff --git a/src/external/bot-skeleton/utils/error-handling.js b/src/external/bot-skeleton/utils/error-handling.js
index 4ede7f8c..c566ca76 100644
--- a/src/external/bot-skeleton/utils/error-handling.js
+++ b/src/external/bot-skeleton/utils/error-handling.js
@@ -20,8 +20,8 @@ export const initErrorHandlingListener = (type = 'keydown') => {
export const handleError = (errorCode, observer) => {
switch (errorCode) {
case 'BLOCK_DELETION':
- if (error_message_map[window.Blockly.getSelected().type]) {
- observer.emit('ui.log.error', error_message_map[window.Blockly.getSelected().type]?.default);
+ if (error_message_map?.()?.[window.Blockly.getSelected().type]) {
+ observer.emit('ui.log.error', error_message_map?.()?.[window.Blockly.getSelected().type]?.default);
}
break;
default: