From 11d85fa4fcab9c3fe08b8f18a9cde39918057394 Mon Sep 17 00:00:00 2001 From: Farabi <102643568+farabi-deriv@users.noreply.github.com> Date: Mon, 26 Aug 2024 17:56:34 +0800 Subject: [PATCH] [BOT] Farabi/bot-2133/show-proper-message-on-loading-invalid-strategy (#16527) * fix: show invalid xml message when ivalid strategy is imported * chore: updated error message for invalid file * fix: invalid error for specific strategies --- packages/bot-skeleton/src/scratch/utils/index.js | 6 ++++++ .../components/bot-notification/bot-notification-utils.ts | 1 + 2 files changed, 7 insertions(+) diff --git a/packages/bot-skeleton/src/scratch/utils/index.js b/packages/bot-skeleton/src/scratch/utils/index.js index 417385190728..cc387be70ecf 100644 --- a/packages/bot-skeleton/src/scratch/utils/index.js +++ b/packages/bot-skeleton/src/scratch/utils/index.js @@ -8,6 +8,8 @@ import { saveWorkspaceToRecent } from '../../utils/local-storage'; import DBotStore from '../dbot-store'; import { LogTypes } from '../../constants/messages'; import { error_message_map } from '../../utils/error-config'; +import { botNotification } from '../../../../bot-web-ui/src/components/bot-notification/bot-notification'; +import { notification_message } from '../../../../bot-web-ui/src/components/bot-notification/bot-notification-utils'; export const getSelectedTradeType = (workspace = Blockly.derivWorkspace) => { const trade_type_block = workspace.getAllBlocks(true).find(block => block.type === 'trade_definition_tradetype'); @@ -121,10 +123,14 @@ export const load = async ({ }) => { if (!DBotStore?.instance || !workspace) return; const { setLoading } = DBotStore.instance; + const { load_modal } = DBotStore.instance; + const { setLoadedLocalFile } = load_modal; setLoading(true); // Delay execution to allow fully previewing previous strategy if users quickly switch between strategies. await delayExecution(100); const showInvalidStrategyError = () => { + setLoadedLocalFile(null); + botNotification(notification_message.invalid_xml); setLoading(false); const error_message = localize('XML file contains unsupported elements. Please check or modify file.'); globalObserver.emit('ui.log.error', error_message); diff --git a/packages/bot-web-ui/src/components/bot-notification/bot-notification-utils.ts b/packages/bot-web-ui/src/components/bot-notification/bot-notification-utils.ts index 1a972c41d0d6..6f699880a4c3 100644 --- a/packages/bot-web-ui/src/components/bot-notification/bot-notification-utils.ts +++ b/packages/bot-web-ui/src/components/bot-notification/bot-notification-utils.ts @@ -39,6 +39,7 @@ export const notification_message = { bot_stop: localize('You’ve just stopped the bot. Any open contracts can be viewed on the Reports page.'), workspace_change: localize('Changes you make will not affect your running bot.'), block_delete: localize('You’ve just deleted a block.'), + invalid_xml: localize('Your import failed due to an invalid file. Upload a complete file in XML format.'), [NOTIFICATION_TYPE.BOT_IMPORT]: localize('You’ve successfully imported a bot.'), [NOTIFICATION_TYPE.BOT_DELETE]: localize('You’ve successfully deleted a bot.'), strategy_conversion: localize('Save this strategy as an XML file from Deriv Bot for faster re-imports.'),