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

Vinu/fix: fixed minor code smells in bot-web-ui #9822

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
11e789d
fix: fixed minor code smells in bot-web-ui
vinu-deriv Aug 25, 2023
4092ac0
fix: added types for gtm in TCoreStores
vinu-deriv Aug 25, 2023
faa5125
fix: removed unnnecessary comments
vinu-deriv Aug 28, 2023
655f2c7
Farzin/WALL-1628/Side Note issue on staging environment (#9820)
farzin-deriv Aug 25, 2023
11a5f9b
farhan/feat: add useSettings hook to @deriv/api (#9805)
farhan-nurzi-deriv Aug 28, 2023
141f833
translations: 📚 sync translations with crowdin (#9836)
github-actions[bot] Aug 28, 2023
7154833
fix: add optional chaining to prevent error (#9838)
ali-hosseini-deriv Aug 28, 2023
d9fb90f
farzin/feat(wallets): :package: add `@deriv/wallets` workspace (#9756)
farzin-deriv Aug 28, 2023
c48cebd
farhan/WALL-1583/Add useLandingCompany hook to @deriv/api (#9785)
farhan-nurzi-deriv Aug 28, 2023
16dfc3e
adrienne/feat: added use-get-status-account hook (#9808)
adrienne-deriv Aug 28, 2023
b514db1
farzin/feat: add `useTradingAccountsList`, `useActiveTradingAccount`,…
farzin-deriv Aug 28, 2023
0b16b3d
Shafin/bot 368/feat draggable transaction modal (#9137)
shafin-deriv Aug 29, 2023
e86aed3
farabi/bot-385/embed hotjar attribution (#9419)
farabi-deriv Aug 29, 2023
591ddea
Arshad/ WALL-833/ show correct platform on trader's hub onboarding (#…
arshad-rao-deriv Aug 29, 2023
7187596
chore: use sass instead of node-sass (#8916)
hamid-deriv Aug 29, 2023
54f3d39
Kate / OPT-347 / Opening the Duration Tab for the first time will sho…
kate-deriv Aug 29, 2023
a36fd9c
likhith/fix: sending empty payload to non idv countries (#9739)
likhith-deriv Aug 29, 2023
0fe8c92
Farabi/bot 399/hide bot too risky modal (#9542)
farabi-deriv Aug 29, 2023
feaa31d
translations: 📚 sync translations with crowdin (#9856)
github-actions[bot] Aug 29, 2023
61ac169
FarhanNurzi/feat: WALL-1574/Add useAvailableAccounts hook to @deriv/a…
farhan-nurzi-deriv Aug 29, 2023
79fe755
thisyahlen/chore: add useTradingPlatformAvailableAccounts to deriv ap…
thisyahlen-deriv Aug 29, 2023
cef2671
thisyahlen/feat: wallet-list-desktop (#9829)
thisyahlen-deriv Aug 29, 2023
506cd3b
farhan/feat: Added Wallet Carousel to @deriv/wallets (#9847)
farhan-nurzi-deriv Aug 29, 2023
a61cdc9
thisyahlen/chore: update wallet loginids (#9866)
thisyahlen-deriv Aug 30, 2023
4f71e18
farzin/refactor(api): :recycle: clean-up (#9864)
farzin-deriv Aug 30, 2023
0dc92cf
adrienne/feat: added svg bundling for wallets (#9871)
adrienne-deriv Aug 30, 2023
13c47b6
henry/webrel-1160/hotfix: space issue dropdown (#9898)
henry-deriv Aug 30, 2023
6a81465
fix: overwritten styles (#9899)
hamid-deriv Aug 30, 2023
7da5cb6
Ameerul /WEBREL-1159 Sort by column alignment in P2P Buy/Sell page is…
ameerul-deriv Aug 31, 2023
2231593
george / PRODQA-1316 / Transfer from Tradershub validation (#9908)
heorhi-deriv Aug 31, 2023
c141151
translations: 📚 sync translations with crowdin (#9912)
github-actions[bot] Sep 1, 2023
75cb1d2
translations: 📚 sync translations with crowdin (#9917)
github-actions[bot] Sep 1, 2023
ba852f2
Hirad-Hamza-ShonTzu/Feature revamp compare account re-deployment (#9611)
hirad-deriv Sep 1, 2023
f776e85
adrienne/chore: added eslint and stylelint for wallets and renamed cs…
adrienne-deriv Sep 1, 2023
3fce0e7
Arshad/Matin/WALL-1226/Dynamic leverage for MT5 financial accounts (#…
matin-deriv Sep 1, 2023
a7603b7
translations: 📚 sync translations with crowdin (#9924)
github-actions[bot] Sep 1, 2023
76f5fdf
translations: 📚 sync translations with crowdin (#9925)
github-actions[bot] Sep 1, 2023
0bc3cf9
Merge remote-tracking branch 'upstream/master' into Vinu/304/fix-mino…
vinu-deriv Sep 1, 2023
e8138e7
Merge remote-tracking branch 'upstream/master' into Vinu/304/fix-mino…
vinu-deriv Sep 19, 2023
303311b
fix: removed unecessary comments
vinu-deriv Sep 19, 2023
84a2029
fix: removed unecessary comments
vinu-deriv Sep 19, 2023
da6855b
fix: removed unecessary comments got added by eslint
vinu-deriv Sep 19, 2023
231f307
fix: removed unecessary comments got added by eslint
vinu-deriv Sep 19, 2023
906b691
fix: remove comments added while commiting
vinu-deriv Sep 19, 2023
1599de7
Merge remote-tracking branch 'upstream/master' into Vinu/304/fix-mino…
vinu-deriv Sep 21, 2023
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
7 changes: 4 additions & 3 deletions packages/bot-web-ui/src/app/app.tsx
Original file line number Diff line number Diff line change
@@ -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;
};
};

Expand Down
5 changes: 3 additions & 2 deletions packages/bot-web-ui/src/app/dbot-providers.tsx
Original file line number Diff line number Diff line change
@@ -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 (
<StoreProvider store={store}>
<DBotStoreProvider ws={WS}>{children}</DBotStoreProvider>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ const Toolbox = observer(() => {
/>
<div className='db-toolbox__category-menu'>
{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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,18 +82,18 @@ 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'
| 'quick-strategy__trade-type'
| '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'
Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
38 changes: 17 additions & 21 deletions packages/bot-web-ui/src/stores/load-modal-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]
);
}
Expand Down Expand Up @@ -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) {
Expand All @@ -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.
Expand Down
24 changes: 12 additions & 12 deletions packages/bot-web-ui/src/stores/quick-strategy-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
Expand All @@ -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
);

Expand Down
5 changes: 3 additions & 2 deletions packages/bot-web-ui/src/stores/root-store.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion packages/bot-web-ui/src/stores/save-modal-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
9 changes: 0 additions & 9 deletions packages/bot-web-ui/src/types/root-stores.types.ts

This file was deleted.

10 changes: 5 additions & 5 deletions packages/hooks/src/__tests__/useCFDAllAccounts.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand All @@ -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 () => {
Expand All @@ -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 () => {
Expand All @@ -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 () => {
Expand Down Expand Up @@ -110,6 +110,6 @@ describe('useCFDAllAccounts', () => {
);
const { result } = renderHook(() => useCFDAllAccounts(), { wrapper });

expect(result.current.length).toBe(3);
expect(result.current).toHaveLength(3);
});
});
15 changes: 15 additions & 0 deletions packages/stores/src/mockStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
},
};
};

Expand Down
22 changes: 22 additions & 0 deletions packages/stores/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -645,6 +646,26 @@ type TTradersHubStore = {
showTopUpModal: () => void;
};

type TGtmStore = {
is_gtm_applicable: boolean;
visitorId: Readonly<string>;
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<Record<string, unknown>>;
pushDataLayer: (data: Record<string, unknown>) => void;
pushTransactionData: (response: Transaction, extra_data: Record<string, unknown>) => void;
eventHandler: (get_settings: GetSettings) => void;
setLoginFlag: (event_name: string) => void;
};

/**
* This is the type that contains all the `core` package stores
*/
Expand All @@ -660,6 +681,7 @@ export type TCoreStores = {
modules: Record<string, any>;
notifications: TNotificationStore;
traders_hub: TTradersHubStore;
gtm: TGtmStore;
};

export type TStores = TCoreStores & {
Expand Down