From 68bacf322ec0cdd1012765f9ca4294cf6a71dffb Mon Sep 17 00:00:00 2001 From: vinu-deriv <100689171+vinu-deriv@users.noreply.github.com> Date: Thu, 21 Sep 2023 11:58:09 +0400 Subject: [PATCH] Vinu/fix: fixed minor code smells in bot-web-ui (#9822) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: fixed minor code smells in bot-web-ui * fix: added types for gtm in TCoreStores * fix: removed unnnecessary comments * Farzin/WALL-1628/Side Note issue on staging environment (#9820) * fix(cashier): :bug: fix * fix(cashier): :bug: fix * fix(cashier): :bug: fix * fix(cashier): :bug: fix * fix(cashier): :bug: fix * fix: don't show side note in FIAT withdrawal page --------- Co-authored-by: Farzin Mirzaie Co-authored-by: Nijil Nirmal * farhan/feat: add useSettings hook to @deriv/api (#9805) * chore: added useSettings to @deriv/api * chore: combine get_settings with set_settings * refactor: change function name * chore: return all mutation data * chore: export hook * refactor: types and mutation function name * translations: 📚 sync translations with crowdin (#9836) Co-authored-by: DerivFE <80095553+DerivFE@users.noreply.github.com> * fix: add optional chaining to prevent error (#9838) * farzin/feat(wallets): :package: add `@deriv/wallets` workspace (#9756) * fix(cashier): :bug: fix unable to access CFD-DerivX transfer * feat(wallets): :package: add `@deriv/wallets` workspace * fix(wallets): :green_heart: fix CI build * feat(api): :sparkles: share a single instance of `QueryClient` in `APIProvider` * Merge branch 'master' into farzin/next --------- Co-authored-by: Farzin Mirzaie * farhan/WALL-1583/Add useLandingCompany hook to @deriv/api (#9785) * feat: added use-authorize hook taken from sergei pr Co-authored-by: Sergei Baranovski <120570511+sergei-deriv@users.noreply.github.com> * chore: sorted imports for use-authorize Co-authored-by: Sergei Baranovski <120570511+sergei-deriv@users.noreply.github.com> * chore: moved default empty string in use-authorize * chore: incorporated code reviews * chore: added useLandingCompany into api package * chore: added useSettings to @deriv/api * chore: get country_code from user settings instead of authorize * chore: combine get_settings with set_settings * fix: change request type for landing_company * chore: combine get_settings with set_settings * refactor: change function name * chore: add missing dependencies for useLandingCompany return data * chore: return all mutation data * chore: export hook * refactor: types and mutation function name * refactor: use-landing-company-hook * fix: remove dependency --------- Co-authored-by: adrienne-rio Co-authored-by: Sergei Baranovski <120570511+sergei-deriv@users.noreply.github.com> * adrienne/feat: added use-get-status-account hook (#9808) * feat: added use-get-status-account hook * chore: updated comments * fix: make use-accounts-list dependent on use-get-account-status hook * chore: incorporated review changes * fix: fixed typescript issue in wallets * farzin/feat: add `useTradingAccountsList`, `useActiveTradingAccount`, and `useActiveAccount` hooks (#9824) * refactor(api): :recycle: clean-up * feat(api): :sparkles: add `useTradingAccountsList`, `useActiveTradingAccount`, and `useActiveAccount` hooks --------- Co-authored-by: Farzin Mirzaie * Shafin/bot 368/feat draggable transaction modal (#9137) * feat: transaction details modal * feat: complete test cases for TransactionDetails modal * chore: fix code smells * chore: fix code smells * chore: remove code smells * chore: redeploy * chore: move transaction details types to types folder * feat: add draggable modal component * chore: finish test cases for draggable component * chore: add header props to draggable * chore: show enrty and exit tick if available * fix: transaction scroll css issue fix * fix: update key with data for divider inside transaction details modal * fix: update buy price to have decimal value * fix: css issue on modal height and fixed decimal profit/loss * fix: fix style for modal getting cut * fix: modal css issue after build * fix: decrease the modal height for edge cutting issue * fix: test case * Merge branch 'master' into shafin/BOT-368/feat--draggable-transaction-modal * fix: not closing on responsive view issue * fix: test case * fix: reduce preview workspace control z-index * farabi/bot-385/embed hotjar attribution (#9419) * fix: added new attributes for hotjar * refactor: separated hotjar script to a function in utils * fix: updated attribute * fix: added optional for client login id * chore: added comment for attribution code * Arshad/ WALL-833/ show correct platform on trader's hub onboarding (#9680) * fix: show correct platform on trader's hub onboarding * test: :white_check_mark: added onboarding test for financial restricted countries * fix: fixed cfd restricted countries * chore: use sass instead of node-sass (#8916) * chore: use sass instead of node-sass * docs: remove node-sass from readme file * docs: fix typo in readme file * chore: retrigger ci tests * fix: ci test failed --------- Co-authored-by: Ali(Ako) Hosseini * Kate / OPT-347 / Opening the Duration Tab for the first time will show incorrect expiry time (#9732) * chore: draft * feat: expant function and hardcoded date * refactor: add usage moment library * chore: remove extra space * likhith/fix: sending empty payload to non idv countries (#9739) * fix: sending empty payload to non idv countries * fix: sending empty payload to non idv countries * Farabi/bot 399/hide bot too risky modal (#9542) * fix: removed bot too risky modal and updated stop icon * fix: added toast notification when user stops bot * fix: fixed snack bar for quick strategy run * fix: added close function on snackbar * fix: added clear and reset timeout on hovering on toast * fix: added test case for bot-stop-notification * fix: stop bot snack bar appearing with no trade again * translations: 📚 sync translations with crowdin (#9856) Co-authored-by: DerivFE <80095553+DerivFE@users.noreply.github.com> * FarhanNurzi/feat: WALL-1574/Add useAvailableAccounts hook to @deriv/api (#9786) * feat: added use-authorize hook taken from sergei pr Co-authored-by: Sergei Baranovski <120570511+sergei-deriv@users.noreply.github.com> * chore: sorted imports for use-authorize Co-authored-by: Sergei Baranovski <120570511+sergei-deriv@users.noreply.github.com> * chore: moved default empty string in use-authorize * chore: incorporated code reviews * chore: added useLandingCompany into api package * chore: added useLandingCompany into api package * chore: added useAvailableAccounts and useAccountTypes hooks into api package * chore: added useSettings to @deriv/api * chore: get country_code from user settings instead of authorize * chore: combine get_settings with set_settings * fix: change request type for landing_company * chore: combine get_settings with set_settings * refactor: change function name * chore: add landing_company field to each account types * chore: add missing dependencies for useLandingCompany return data * chore: return all mutation data * chore: export hook * refactor: types and mutation function name * refactor: use-landing-company-hook * fix: remove dependency * fix: remove dependency * refactor: use-available-accounts hook * fix: review comments, remove gaming accounts * refactor: separate accounts usememo --------- Co-authored-by: adrienne-rio Co-authored-by: Sergei Baranovski <120570511+sergei-deriv@users.noreply.github.com> * thisyahlen/chore: add useTradingPlatformAvailableAccounts to deriv api (#9810) * chore: add useTradingPlatformAvailableAccounts to deriv api * fix: type repetition annd fallback * refactor: repetition * fix: empty commit * fix: empty commit * fix: comment * thisyahlen/feat: wallet-list-desktop (#9829) * fix(cashier): :bug: fix unable to access CFD-DerivX transfer * feat(wallets): :package: add `@deriv/wallets` workspace * fix(wallets): :green_heart: fix CI build * feat(api): :sparkles: share a single instance of `QueryClient` in `APIProvider` * Merge branch 'master' into farzin/next * chore: add wallet header list data for desktop --------- Co-authored-by: Farzin Mirzaie * farhan/feat: Added Wallet Carousel to @deriv/wallets (#9847) * fix(cashier): :bug: fix unable to access CFD-DerivX transfer * feat(wallets): :package: add `@deriv/wallets` workspace * fix(wallets): :green_heart: fix CI build * feat(api): :sparkles: share a single instance of `QueryClient` in `APIProvider` * Merge branch 'master' into farzin/next * chore: created mobile wallets carousel Co-authored-by: Sergei Baranovski <120570511+sergei-deriv@users.noreply.github.com> --------- Co-authored-by: Farzin Mirzaie Co-authored-by: Sergei Baranovski <120570511+sergei-deriv@users.noreply.github.com> * thisyahlen/chore: update wallet loginids (#9866) * farzin/refactor(api): :recycle: clean-up (#9864) Co-authored-by: Farzin Mirzaie * adrienne/feat: added svg bundling for wallets (#9871) * feat: added svg bundling for wallets * chore: removed assets folder in wallets * henry/webrel-1160/hotfix: space issue dropdown (#9898) * fix: space issue dropdown * fix: resolve comment * fix: comment * Update packages/components/src/components/dropdown/dropdown.scss * fix: empty commit --------- Co-authored-by: Maryia <103177211+maryia-deriv@users.noreply.github.com> * fix: overwritten styles (#9899) * fix: overwritten styles * fix: overwritten styles * Ameerul /WEBREL-1159 Sort by column alignment in P2P Buy/Sell page is off (#9876) * chore: fixed sort dropdown alignment * chore: changed styling for dropdown * george / PRODQA-1316 / Transfer from Tradershub validation (#9908) * fix: :ambulance: fix active container for TH transfer, fix insufficient balance check * test: :bug: fix tests * fix: :ambulance: fix 'Insufficient balance' condition * translations: 📚 sync translations with crowdin (#9912) Co-authored-by: DerivFE <80095553+DerivFE@users.noreply.github.com> * translations: 📚 sync translations with crowdin (#9917) Co-authored-by: DerivFE <80095553+DerivFE@users.noreply.github.com> * Hirad-Hamza-ShonTzu/Feature revamp compare account re-deployment (#9611) * feat: initializing the compare account implementation * feat: icon reusable component v1.0 * feat: icon reusable component v1.1 * feat: icon reusable component v1.1.1 * feat: initialize compare cfd account page (todo:css) * feat: blank compare cfd accounts page & navi done * feat: mobile view * fix: compare-accounts naming convention * fix: updated path import * fix: reverted icons.js changes * fix: compare-cfds -> compare-accounts * feat: reusable component v1.2 * feat: reusable component v1.2.1 * feat: icon reusable component added v1.3 * feat: reusable component for Icons * feat: reusable component for Icons refactor * feat: reusable component for Icons refactor v1.2 * feat: description div added * feat: description with title +icon is added * feat: platform label + icon component padding added * chore: labuan leverage updated * chore: css issue fixed for Cards * feat: carousel added with sorting o f MT5 accounts * feat: carousel arrow background and container added * chore: added dxtrade in the card for dynamic rendering with type fixes * chore: changes in platform label header with respect to props data * chore: icons updated because of white line issue in icons * chore: change the components css name and other naming convention tweaks * refactor: suggestions implemented * refactor: convert carousel button into one * feat: initial commit for starting collaboration * feat: added the button placeholder * feat: added new banner to cfd cards * refactor: make the banner smaller * fix: added condition to show banner for derivez and ctrader only * refactor: changed the types and applied suggestions * refactor: removed the invalide shortcode for dxtrade * refactor: round up patches based on reviews * fix: round up patch 2 based on review * Update packages/cfd/src/Containers/cfd-compare-accounts/cfd-compare-accounts.scss Co-authored-by: Muhammad Hamza <120543468+hamza-deriv@users.noreply.github.com> * refactor: button width * refactor: button classname * chore: fix css of underline * chore: added redirection to homepage in case of modals * fix: circle ci failed due to wrong type of client function * chore: added the disabled property for the Added accounts * chore: added condition for the dxtrade * chore: rearrange block scoped variables * chore: fix css of labuan tooltip with removal of commented code * chore: responsive view fixes * feat: demo accounts added for low risk * feat: demo accounts label added and swap-free account creation fixed * chore: added derivx account creation flow * refactor: replace ternary operators with if-else * chore: remove unused jurisdiction * feat: demo account compare implemetation tweaks as per design * feat: rectified the Demo title as per design * chore: font weigth of instruments as per design * feat: Eu flow for DIEL * feat: changes in the icons label and correction in EU flow * chore: addded translations demo title and rename baskets * chore: rename icon type * chore: final changes prop drilling instead of observer EU flow finalized * fix: hidding deriv ez * fix: EU flow platform label change * feat: test case for description added * feat: platform label test case added * feat: title icon test case added * feat: title icon test case added * chore: fix test case description + instruments icon test added * refactor: blank spaces removed * chore: cfd-instruments-label test added * chore: test file added cfd-instrument-label * feat: button partial test case added * chore: added more test case for Button component * feat: added test case for compare-account-card * chore: merge conflicts * chore: test for cfd-compare-accounts added * feat: derivX demo * chore: added testcase for dxtrade in button * fix: dxtrade for australian clients * fix: swapfree account creation added * fix: comapre account fixes first round * fix: remove the css because scroll not working * fix: renamed variable + icons * fix: cursor not allowed on instrument icons * fix: fixed the circle ci issue * fix: fixed one of our test issues * refactor: review comments resolved * fix: changing the text of mf accounts to pass the tests * fix: made changes according to suggestions * fix: made changes according to suggestions * fix: fixed the test case issues * chore: added s to spread(s) * chore: fixed capitalization * chore: line split * fix: failing test case * fix: updated markets offerings for MT5 Financial Labuan * fix: Other CFDs --> Other CFDs Platform * fix: removed standard/micro from DerivX Forex label * refactor: optimised code * fix: icon size inconsistencyn mobile VP * refactor: css refactoring to reflect figma as much as possible * refactor: minor css fixes * fix: fixed * style: added bottom padding for mobile * fix: fixed the build issue * chore: re running the tests * fix: subtasks * chore: typo * style: position the tooltip to be center within the card * style: resize width for word-wrap * chore: d and r should be lowercase dispute and resolution * fix: fixing sonar cloud issues * fix: making changes to pass the tests --------- Co-authored-by: hamza-deriv Co-authored-by: shontzu-deriv Co-authored-by: shontzu <108507236+shontzu-deriv@users.noreply.github.com> Co-authored-by: Muhammad Hamza <120543468+hamza-deriv@users.noreply.github.com> * adrienne/chore: added eslint and stylelint for wallets and renamed css variables (#9877) * feat: added stylelint for wallets for bem convention * feat: added stylelint for wallets for bem convention * chore: added import sorts for wallets and bem convention checking * chore: removed unused dependencies in wallets * Arshad/Matin/WALL-1226/Dynamic leverage for MT5 financial accounts (#9314) * chore: Dynamic leverage for MT5 financial accounts initial commit * feat: :construction: dynamic leverage modal * test: unit tests * feat: :white_check_mark: added unit tests and refactoring * feat: :recycle: fixed UI * feat: :recycle: review changes for dynamic leverage * chore: item name update * feat: :bug: passed string to localize instead of a variable * test: :recycle: * refactor: :recycle: refactored column header to new component * refactor: refactored code * fix: fixed styling and refactored code * style: formatted code * test: updated test mock component * refactor: refactored styling and unit tests * fix: fixed text content for dynamic leverage * fix: fixed localize component usage * refactor: used strong instead of span styling * fix: jurisdiction card layout --------- Co-authored-by: arshad-rao-deriv Co-authored-by: mahdiyeh-deriv <82078941+mahdiyeh-deriv@users.noreply.github.com> * translations: 📚 sync translations with crowdin (#9924) Co-authored-by: DerivFE <80095553+DerivFE@users.noreply.github.com> * translations: 📚 sync translations with crowdin (#9925) Co-authored-by: DerivFE <80095553+DerivFE@users.noreply.github.com> * fix: removed unecessary comments * fix: removed unecessary comments * fix: removed unecessary comments got added by eslint * fix: removed unecessary comments got added by eslint * fix: remove comments added while commiting --------- Co-authored-by: Farzin Mirzaie <72082844+farzin-deriv@users.noreply.github.com> Co-authored-by: Farzin Mirzaie Co-authored-by: Nijil Nirmal Co-authored-by: Farhan Ahmad Nurzi <125247833+farhan-nurzi-deriv@users.noreply.github.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: DerivFE <80095553+DerivFE@users.noreply.github.com> Co-authored-by: Ali(Ako) Hosseini Co-authored-by: adrienne-rio Co-authored-by: Sergei Baranovski <120570511+sergei-deriv@users.noreply.github.com> Co-authored-by: adrienne-deriv <103016120+adrienne-deriv@users.noreply.github.com> Co-authored-by: Shafin Al Karim <129021108+shafin-deriv@users.noreply.github.com> Co-authored-by: Farabi <102643568+farabi-deriv@users.noreply.github.com> Co-authored-by: Arshad Rao <135801848+arshad-rao-deriv@users.noreply.github.com> Co-authored-by: Hamid Co-authored-by: kate-deriv <121025168+kate-deriv@users.noreply.github.com> Co-authored-by: Likhith Kolayari <98398322+likhith-deriv@users.noreply.github.com> Co-authored-by: thisyahlen <104053934+thisyahlen-deriv@users.noreply.github.com> Co-authored-by: henry-deriv <118344354+henry-deriv@users.noreply.github.com> Co-authored-by: Maryia <103177211+maryia-deriv@users.noreply.github.com> Co-authored-by: ameerul-deriv <103412909+ameerul-deriv@users.noreply.github.com> Co-authored-by: George Usynin <103181646+heorhi-deriv@users.noreply.github.com> Co-authored-by: hirad-deriv Co-authored-by: hamza-deriv Co-authored-by: shontzu-deriv Co-authored-by: shontzu <108507236+shontzu-deriv@users.noreply.github.com> Co-authored-by: Muhammad Hamza <120543468+hamza-deriv@users.noreply.github.com> Co-authored-by: Matin shafiei Co-authored-by: arshad-rao-deriv Co-authored-by: mahdiyeh-deriv <82078941+mahdiyeh-deriv@users.noreply.github.com> --- packages/bot-web-ui/src/app/app.tsx | 7 ++-- .../bot-web-ui/src/app/dbot-providers.tsx | 5 ++- .../dashboard/bot-builder/toolbox/toolbox.tsx | 2 +- .../quick-strategy/quick-strategy.types.ts | 10 ++--- .../network-toast-popup.tsx | 1 - .../bot-web-ui/src/stores/load-modal-store.ts | 38 +++++++++---------- .../src/stores/quick-strategy-store.ts | 24 ++++++------ packages/bot-web-ui/src/stores/root-store.ts | 5 ++- .../bot-web-ui/src/stores/save-modal-store.ts | 2 +- .../bot-web-ui/src/types/root-stores.types.ts | 9 ----- .../src/__tests__/useCFDAllAccounts.spec.tsx | 10 ++--- packages/stores/src/mockStore.ts | 15 ++++++++ packages/stores/types.ts | 22 +++++++++++ 13 files changed, 88 insertions(+), 62 deletions(-) delete mode 100644 packages/bot-web-ui/src/types/root-stores.types.ts diff --git a/packages/bot-web-ui/src/app/app.tsx b/packages/bot-web-ui/src/app/app.tsx index 1d938f5c0caa..895599515183 100644 --- a/packages/bot-web-ui/src/app/app.tsx +++ b/packages/bot-web-ui/src/app/app.tsx @@ -1,13 +1,14 @@ -import '../public-path'; // Leave this here (at the top)! OK boss! +import '../public-path'; import React from 'react'; -import type { TRootStore, TWebSocket } from 'Types'; +import { TStores } from '@deriv/stores/types'; +import type { TWebSocket } from 'Types'; import AppContent from './app-content'; import DBotProviders from './dbot-providers'; type TAppProps = { passthrough: { WS: TWebSocket; - root_store: TRootStore; + root_store: TStores; }; }; diff --git a/packages/bot-web-ui/src/app/dbot-providers.tsx b/packages/bot-web-ui/src/app/dbot-providers.tsx index 501dbbf47bc7..756b95bf7fd2 100644 --- a/packages/bot-web-ui/src/app/dbot-providers.tsx +++ b/packages/bot-web-ui/src/app/dbot-providers.tsx @@ -1,9 +1,10 @@ import React from 'react'; import { StoreProvider } from '@deriv/stores'; -import type { TRootStore, TWebSocket } from 'Types'; +import { TStores } from '@deriv/stores/types'; +import type { TWebSocket } from 'Types'; import { DBotStoreProvider } from 'Stores/useDBotStore'; -const DBotProviders = ({ children, store, WS }: React.PropsWithChildren<{ store: TRootStore; WS: TWebSocket }>) => { +const DBotProviders = ({ children, store, WS }: React.PropsWithChildren<{ store: TStores; WS: TWebSocket }>) => { return ( {children} diff --git a/packages/bot-web-ui/src/components/dashboard/bot-builder/toolbox/toolbox.tsx b/packages/bot-web-ui/src/components/dashboard/bot-builder/toolbox/toolbox.tsx index 176ae7a8fb92..8fd14c048a77 100644 --- a/packages/bot-web-ui/src/components/dashboard/bot-builder/toolbox/toolbox.tsx +++ b/packages/bot-web-ui/src/components/dashboard/bot-builder/toolbox/toolbox.tsx @@ -80,7 +80,7 @@ const Toolbox = observer(() => { />
{toolbox_dom && - (Array.from(toolbox_dom.childNodes) as HTMLElement[]).map((category, index) => { + Array.from(toolbox_dom.childNodes as HTMLElement[]).map((category, index) => { if (category.tagName.toUpperCase() === 'CATEGORY') { const has_sub_category = hasSubCategory(category.children); const is_sub_category_open = sub_category_index.includes(index); diff --git a/packages/bot-web-ui/src/components/dashboard/quick-strategy/quick-strategy.types.ts b/packages/bot-web-ui/src/components/dashboard/quick-strategy/quick-strategy.types.ts index 26bcc06be1a7..a70f9c950840 100644 --- a/packages/bot-web-ui/src/components/dashboard/quick-strategy/quick-strategy.types.ts +++ b/packages/bot-web-ui/src/components/dashboard/quick-strategy/quick-strategy.types.ts @@ -82,11 +82,6 @@ export type TInputUniqFields = 'input_martingale_size' | 'input_alembert_unit' | export type TInputBaseFields = 'input_duration_value' | 'input_stake' | 'input_loss' | 'input_profit'; export type TInputCommonFields = TInputBaseFields | TInputUniqFields; -export type TSetFieldValue = ( - element: 'button' | 'quick-strategy__duration-unit' | 'quick-strategy__duration-value' | string, - action: 'run' | 'edit' | string | number -) => void; - export type TSelectsFieldNames = | 'quick-strategy__type-strategy' | 'quick-strategy__symbol' @@ -94,6 +89,11 @@ export type TSelectsFieldNames = | 'quick-strategy__duration-unit' | ''; +export type TSetFieldValue = ( + element: 'button' | 'quick-strategy__duration-unit' | 'quick-strategy__duration-value' | TSelectsFieldNames, + action: string | number +) => void; + export type TInputsFieldNames = | 'quick-strategy__duration-value' | 'quick-strategy__stake' diff --git a/packages/bot-web-ui/src/components/network-toast-popup/network-toast-popup.tsx b/packages/bot-web-ui/src/components/network-toast-popup/network-toast-popup.tsx index fc4f8c850098..0130dd1fae7e 100644 --- a/packages/bot-web-ui/src/components/network-toast-popup/network-toast-popup.tsx +++ b/packages/bot-web-ui/src/components/network-toast-popup/network-toast-popup.tsx @@ -1,6 +1,5 @@ import React from 'react'; import classNames from 'classnames'; -import PropTypes from 'prop-types'; import ReactDOM from 'react-dom'; import { MobileWrapper, Toast } from '@deriv/components'; import { observer, useStore } from '@deriv/stores'; diff --git a/packages/bot-web-ui/src/stores/load-modal-store.ts b/packages/bot-web-ui/src/stores/load-modal-store.ts index 0e34f531a8b3..f8c9fa7214ae 100644 --- a/packages/bot-web-ui/src/stores/load-modal-store.ts +++ b/packages/bot-web-ui/src/stores/load-modal-store.ts @@ -146,7 +146,7 @@ export default class LoadModalStore implements ILoadModalStore { get selected_strategy(): TStrategy { return ( - this.dashboard_strategies.find((ws: { id: string }) => ws.id === this.selected_strategy_id) || + this.dashboard_strategies.find((ws: { id: string }) => ws.id === this.selected_strategy_id) ?? this.dashboard_strategies[0] ); } @@ -290,16 +290,13 @@ export default class LoadModalStore implements ILoadModalStore { onActiveIndexChange = (): void => { if (this.tab_name === tabs_title.TAB_RECENT) { this.previewRecentStrategy(this.selected_strategy_id); - } else { - // eslint-disable-next-line no-lonely-if - if (this.recent_workspace) { - setTimeout(() => { - // Dispose of recent workspace when switching away from Recent tab. - // Process in next cycle so user doesn't have to wait. - this.recent_workspace?.dispose(); - this.recent_workspace = null; - }); - } + } else if (this.recent_workspace) { + setTimeout(() => { + // Dispose of recent workspace when switching away from Recent tab. + // Process in next cycle so user doesn't have to wait. + this.recent_workspace?.dispose(); + this.recent_workspace = null; + }); } if (this.tab_name === tabs_title.TAB_LOCAL) { @@ -310,16 +307,15 @@ export default class LoadModalStore implements ILoadModalStore { this.drop_zone.addEventListener('drop', event => this.handleFileChange(event, false)); } } - } else { - // Dispose of local workspace when switching away from Local tab. - // eslint-disable-next-line no-lonely-if - if (this.local_workspace) { - setTimeout(() => { - this.local_workspace?.dispose(); - this.local_workspace = null; - this.setLoadedLocalFile(null); - }, 0); - } + } + + // Dispose of local workspace when switching away from Local tab. + else if (this.local_workspace) { + setTimeout(() => { + this.local_workspace?.dispose(); + this.local_workspace = null; + this.setLoadedLocalFile(null); + }, 0); } // Forget about drop zone when not on Local tab. diff --git a/packages/bot-web-ui/src/stores/quick-strategy-store.ts b/packages/bot-web-ui/src/stores/quick-strategy-store.ts index e813330d173a..b7a6476a685d 100644 --- a/packages/bot-web-ui/src/stores/quick-strategy-store.ts +++ b/packages/bot-web-ui/src/stores/quick-strategy-store.ts @@ -93,15 +93,15 @@ export default class QuickStrategyStore { selected_trade_type: TTradeType = (this.qs_cache.selected_trade_type as TTradeType) || {}; selected_type_strategy: TTypeStrategy = (this.qs_cache.selected_type_strategy as TTypeStrategy) || {}; selected_duration_unit: TDurationOptions = (this.qs_cache.selected_duration_unit as TDurationOptions) || {}; - input_duration_value: string | number = this.qs_cache.input_duration_value || ''; - input_stake: string = this.qs_cache.input_stake || ''; - input_martingale_size: string = this.qs_cache.input_martingale_size || ''; - input_alembert_unit: string = this.qs_cache.input_alembert_unit || ''; - input_oscar_unit: string = this.qs_cache.input_oscar_unit || ''; - input_loss: string = this.qs_cache.input_loss || ''; - input_profit: string = this.qs_cache.input_profit || ''; - active_index: number = this.selected_type_strategy.index || 0; - description: string = this.qs_cache.selected_type_strategy?.description || ''; + input_duration_value: string | number = this.qs_cache.input_duration_value ?? ''; + input_stake: string = this.qs_cache.input_stake ?? ''; + input_martingale_size: string = this.qs_cache.input_martingale_size ?? ''; + input_alembert_unit: string = this.qs_cache.input_alembert_unit ?? ''; + input_oscar_unit: string = this.qs_cache.input_oscar_unit ?? ''; + input_loss: string = this.qs_cache.input_loss ?? ''; + input_profit: string = this.qs_cache.input_profit ?? ''; + active_index: number = this.selected_type_strategy.index ?? 0; + description: string = this.qs_cache.selected_type_strategy?.description ?? ''; types_strategies_dropdown: TTypeStrategiesDropdown = []; symbol_dropdown: TSymbolDropdown = []; trade_type_dropdown: TTradeTypeDropdown = []; @@ -139,7 +139,7 @@ export default class QuickStrategyStore { setDescription(type_strategy: TTypeStrategy): void { this.description = - this.types_strategies_dropdown?.find(strategy => strategy.value === type_strategy.value)?.description || ''; + this.types_strategies_dropdown?.find(strategy => strategy.value === type_strategy.value)?.description ?? ''; } setDurationUnitDropdown(duration_unit_options: TDurationUnitDropdown): void { @@ -485,7 +485,7 @@ export default class QuickStrategyStore { let first_duration_unit: TDurationOptions = duration_options[0]; if (this.selected_duration_unit && duration_options?.some(e => e.value === this.selected_duration_unit.value)) { first_duration_unit = - duration_options?.find(e => e.value === this.selected_duration_unit.value) || + duration_options?.find(e => e.value === this.selected_duration_unit.value) ?? this.selected_duration_unit; runInAction(() => { first_duration_unit.text = this.getFieldValue(duration_options, this.selected_duration_unit.value); @@ -496,7 +496,7 @@ export default class QuickStrategyStore { if (first_duration_unit) { this.setSelectedDurationUnit(first_duration_unit); this.updateDurationValue( - this.qs_cache?.selected_duration_unit?.value || this.selected_duration_unit.value, + this.qs_cache?.selected_duration_unit?.value ?? this.selected_duration_unit.value, setFieldValue ); diff --git a/packages/bot-web-ui/src/stores/root-store.ts b/packages/bot-web-ui/src/stores/root-store.ts index 785f18bdc804..582beb41ea4a 100644 --- a/packages/bot-web-ui/src/stores/root-store.ts +++ b/packages/bot-web-ui/src/stores/root-store.ts @@ -1,4 +1,5 @@ -import type { TDbot, TRootStore, TWebSocket } from 'Types'; +import { TStores } from '@deriv/stores/types'; +import type { TDbot, TWebSocket } from 'Types'; import AppStore from './app-store'; import BlocklyStore from './blockly-store'; import ChartStore from './chart-store'; @@ -48,7 +49,7 @@ export default class RootStore { public blockly_store: BlocklyStore; public data_collection_store: DataCollectionStore; - constructor(core: TRootStore, ws: TWebSocket, dbot: TDbot) { + constructor(core: TStores, ws: TWebSocket, dbot: TDbot) { this.ws = ws; this.dbot = dbot; this.app = new AppStore(this, core); diff --git a/packages/bot-web-ui/src/stores/save-modal-store.ts b/packages/bot-web-ui/src/stores/save-modal-store.ts index 94b1863fc4cc..5ac3581c7163 100644 --- a/packages/bot-web-ui/src/stores/save-modal-store.ts +++ b/packages/bot-web-ui/src/stores/save-modal-store.ts @@ -163,7 +163,7 @@ export default class SaveModalStore implements ISaveModalStore { this.updateBotName(bot_name); if (active_tab === 0) { - const workspace_id = selected_strategy.id || Blockly?.utils?.genUid(); + const workspace_id = selected_strategy.id ?? Blockly?.utils?.genUid(); await this.addStrategyToWorkspace(workspace_id, is_local, save_as_collection, bot_name, xml); if (main_strategy) await loadStrategyToBuilder(main_strategy); } else { diff --git a/packages/bot-web-ui/src/types/root-stores.types.ts b/packages/bot-web-ui/src/types/root-stores.types.ts deleted file mode 100644 index 4473cd37193d..000000000000 --- a/packages/bot-web-ui/src/types/root-stores.types.ts +++ /dev/null @@ -1,9 +0,0 @@ -import type { TCoreStores } from '@deriv/stores/types'; - -/** - * @deprecated - Use `TStores` from `@deriv/stores` instead of this type. - */ -export type TRootStore = TCoreStores & { - gtm?: Record; - portfolio?: Record; -}; diff --git a/packages/hooks/src/__tests__/useCFDAllAccounts.spec.tsx b/packages/hooks/src/__tests__/useCFDAllAccounts.spec.tsx index 1006de314ade..06479e81c4d1 100644 --- a/packages/hooks/src/__tests__/useCFDAllAccounts.spec.tsx +++ b/packages/hooks/src/__tests__/useCFDAllAccounts.spec.tsx @@ -12,7 +12,7 @@ describe('useCFDAllAccounts', () => { ); const { result } = renderHook(() => useCFDAllAccounts(), { wrapper }); - expect(result.current.length).toBe(0); + expect(result.current).toHaveLength(0); }); test('should return proper data when client has MT5 accounts', async () => { @@ -33,7 +33,7 @@ describe('useCFDAllAccounts', () => { ); const { result } = renderHook(() => useCFDAllAccounts(), { wrapper }); - expect(result.current.length).toBe(1); + expect(result.current).toHaveLength(1); }); test('should return proper data when client has dxtrade accounts', async () => { @@ -54,7 +54,7 @@ describe('useCFDAllAccounts', () => { ); const { result } = renderHook(() => useCFDAllAccounts(), { wrapper }); - expect(result.current.length).toBe(1); + expect(result.current).toHaveLength(1); }); test('should return proper data when client has ctrader accounts', async () => { @@ -75,7 +75,7 @@ describe('useCFDAllAccounts', () => { ); const { result } = renderHook(() => useCFDAllAccounts(), { wrapper }); - expect(result.current.length).toBe(1); + expect(result.current).toHaveLength(1); }); test('should return proper data when client has MT5, ctrader and dxtrade accounts', async () => { @@ -110,6 +110,6 @@ describe('useCFDAllAccounts', () => { ); const { result } = renderHook(() => useCFDAllAccounts(), { wrapper }); - expect(result.current.length).toBe(3); + expect(result.current).toHaveLength(3); }); }); diff --git a/packages/stores/src/mockStore.ts b/packages/stores/src/mockStore.ts index fd0839b143e7..626ab29cd729 100644 --- a/packages/stores/src/mockStore.ts +++ b/packages/stores/src/mockStore.ts @@ -470,6 +470,21 @@ const mock = (): TStores & { is_mock: boolean } => { update: jest.fn(), unmount: jest.fn(), }, + gtm: { + is_gtm_applicable: false, + visitorId: 'visitorId', + common_variables: { + language: 'en', + theme: 'dark', + platform: 'DBot', + loggedIn: false, + }, + accountSwitcherListener: jest.fn(), + pushDataLayer: jest.fn(), + pushTransactionData: jest.fn(), + eventHandler: jest.fn(), + setLoginFlag: jest.fn(), + }, }; }; diff --git a/packages/stores/types.ts b/packages/stores/types.ts index 41f3db763cd5..e50854dbd9a2 100644 --- a/packages/stores/types.ts +++ b/packages/stores/types.ts @@ -14,6 +14,7 @@ import type { SetFinancialAssessmentRequest, SetFinancialAssessmentResponse, StatesList, + Transaction, } from '@deriv/api-types'; import type { Moment } from 'moment'; import type { RouteComponentProps } from 'react-router'; @@ -645,6 +646,26 @@ type TTradersHubStore = { showTopUpModal: () => void; }; +type TGtmStore = { + is_gtm_applicable: boolean; + visitorId: Readonly; + common_variables: Readonly<{ + language: string; + visitorId?: string; + currency?: string; + userId?: string; + email?: string; + loggedIn: boolean; + theme: 'dark' | 'light'; + platform: 'DBot' | 'MT5' | 'DTrader' | 'undefined'; + }>; + accountSwitcherListener: () => Promise>; + pushDataLayer: (data: Record) => void; + pushTransactionData: (response: Transaction, extra_data: Record) => void; + eventHandler: (get_settings: GetSettings) => void; + setLoginFlag: (event_name: string) => void; +}; + /** * This is the type that contains all the `core` package stores */ @@ -660,6 +681,7 @@ export type TCoreStores = { modules: Record; notifications: TNotificationStore; traders_hub: TTradersHubStore; + gtm: TGtmStore; }; export type TStores = TCoreStores & {