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

Kate / DTRA-269 / [Package 2] Tech debt TS + refactoring of Trader package #9284

Merged
Show file tree
Hide file tree
Changes from 48 commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
1de859f
fix: ts-migrate screen small
henry-deriv Jul 6, 2023
28a3538
fix: sass was unable to be found
henry-deriv Jul 6, 2023
49e9d7a
chore: add key files from prev branch
kate-deriv Jul 7, 2023
37ed414
Merge branch 'master' into kate/dtra-269/ts_migration_trader_package_2
kate-deriv Jul 7, 2023
8c1c8b5
fix: merge feature branch
henry-deriv Jul 7, 2023
77528de
chore: empty commit
kate-deriv Jul 7, 2023
d4a4ddf
Merge branch 'master' into kate/dtra-269/ts_migration_trader_package_2
akmal-deriv Jul 10, 2023
4b92603
Merge pull request #15 from henry-deriv/henry/dtra-271/ts-migration-s…
akmal-deriv Jul 10, 2023
d4bd1f7
Maryia/dtra-279/TS migration [Trader]: TradeModals, MarketUnavailable…
maryia-deriv Jul 10, 2023
1a3a8ca
maryia/WEBREL-323/feat: ts migration of base-store (#18)
maryia-deriv Jul 25, 2023
fd8882c
Maryia/webrel-483/TS migration of ContractType function (#17)
maryia-deriv Jul 25, 2023
ee7b167
Merge branch master into kate/dtra-269/ts_migration_trader_package_2
kate-deriv Jul 25, 2023
7d655a3
fix: sonarcloud issues (#19)
maryia-deriv Jul 25, 2023
94af4d5
Merge branch 'master' into kate/dtra-269/ts_migration_trader_package_2
kate-deriv Jul 25, 2023
4749d20
chore: update reg exp
kate-deriv Jul 25, 2023
756b998
chore: remove code smell
kate-deriv Jul 25, 2023
2ae1c3e
chore: remove security hotspot
kate-deriv Jul 25, 2023
c6dee71
chore: update reg exp
kate-deriv Jul 26, 2023
cbee742
chore: update reg exp to prev version
kate-deriv Jul 26, 2023
119af73
Merge branch master into kate/dtra-269/ts_migration_trader_package_2
kate-deriv Aug 3, 2023
548c578
Merge branch master into kate/dtra-269/ts_migration_trader_package_2
kate-deriv Aug 7, 2023
e82b1a2
fix: conflicts
kate-deriv Aug 9, 2023
53eb24c
fix: conflict
kate-deriv Aug 9, 2023
0de9447
fix: conflicts
kate-deriv Aug 10, 2023
ffe7635
Merge branch 'master' into kate/dtra-269/ts_migration_trader_package_2
kate-deriv Aug 10, 2023
19c60d4
Merge branch 'master' of github.com:binary-com/deriv-app into kate/dt…
kate-deriv Aug 10, 2023
3b77a42
fix: ts error
kate-deriv Aug 10, 2023
8debc85
refactor: apply suggestions
kate-deriv Aug 11, 2023
7f91274
Merge branch master into kate/dtra-269/ts_migration_trader_package_2
kate-deriv Sep 7, 2023
815d62f
fix: resolve more conflicts
kate-deriv Sep 7, 2023
ee24dc1
Merge branch 'master' into kate/dtra-269/ts_migration_trader_package_2
kate-deriv Sep 7, 2023
de27282
fix: conflicts in start date
kate-deriv Sep 7, 2023
2e1f82f
fix: type of onchangestartdate
kate-deriv Sep 7, 2023
d451cf5
fix: type of contract cat list in usetraderstore
kate-deriv Sep 7, 2023
b7dc70b
fix: types in contract type and allow equals
kate-deriv Sep 7, 2023
c0ccbac
Merge branch 'master' into kate/dtra-269/ts_migration_trader_package_2
kate-deriv Sep 7, 2023
9ba8ef6
refactor: aplly part of suggestions
kate-deriv Sep 8, 2023
9b7bafc
refactor: remove unused type
kate-deriv Sep 8, 2023
9d24ce4
refactor: remove wrong types
kate-deriv Sep 8, 2023
5b65cde
refactor: types of time
kate-deriv Sep 8, 2023
4ea9d24
refactor: revert changes
kate-deriv Sep 9, 2023
ec5a35b
Merge branch master into kate/dtra-269/ts_migration_trader_package_2
kate-deriv Sep 21, 2023
178abea
chore: empty commit
kate-deriv Sep 21, 2023
07d9e09
Merge branch 'master' into kate/dtra-269/ts_migration_trader_package_2
kate-deriv Sep 21, 2023
1598c02
Merge branch 'master' into kate/dtra-269/ts_migration_trader_package_2
kate-deriv Sep 21, 2023
804859a
Merge branch master into kate/dtra-269/ts_migration_trader_package_2
kate-deriv Sep 26, 2023
c2f05f5
Merge branch 'master' into kate/dtra-269/ts_migration_trader_package_2
kate-deriv Sep 26, 2023
881750e
fix: more conflicts
kate-deriv Sep 26, 2023
9dbd926
Merge branch master into kate/dtra-269/ts_migration_trader_package_2
kate-deriv Sep 26, 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
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import { useSwipeable } from 'react-swipeable';
import ArrowButton from './arrow-button';

type TCollapsible = {
as: React.ElementType;
as?: React.ElementType;
is_collapsed?: boolean;
position?: 'top' | 'bottom';
onClick: (state: boolean) => void;
title: string;
title?: string;
};

const swipe_config = {
Expand Down
2 changes: 1 addition & 1 deletion packages/components/src/components/dialog/dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ const Dialog = ({
}
};

const validateClickOutside = () => dismissable || !!(has_close_icon && is_visible && is_closed_on_cancel);
const validateClickOutside = () => !!(dismissable || (has_close_icon && is_visible && is_closed_on_cancel));

useOnClickOutside(wrapper_ref, handleClose, validateClickOutside);

Expand Down
6 changes: 4 additions & 2 deletions packages/shared/src/utils/helpers/__tests__/start-date.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { ContractsFor } from '@deriv/api-types';
import { buildForwardStartingConfig } from '../start-date';

describe('start_date', () => {
describe('buildForwardStartingConfig', () => {
it('Returns empty object when forward_starting_options and forward_starting_dates are both empties', () => {
const contract = {
const contract: ContractsFor['available'][number] = {
barrier_category: 'euro_atm',
barriers: 0,
contract_category: 'callput',
Expand All @@ -19,7 +20,8 @@ describe('start_date', () => {
start_type: 'spot',
submarket: 'major_pairs',
underlying_symbol: 'frxAUDJPY',
forward_starting_options: [],
forward_starting_options:
[] as unknown as ContractsFor['available'][number]['forward_starting_options'],
jim-deriv marked this conversation as resolved.
Show resolved Hide resolved
};
/* eslint-disable no-unused-expressions */
expect(buildForwardStartingConfig(contract, [])).toHaveLength(0);
Expand Down
23 changes: 8 additions & 15 deletions packages/shared/src/utils/helpers/start-date.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,6 @@
import moment from 'moment';
import { toMoment } from '../date';

type TForwardStartingDates = {
blackouts?: unknown[];
close?: string;
date: string;
open?: string;
};

type TContract = {
forward_starting_options: TForwardStartingDates[];
};
import { ContractsFor } from '@deriv/api-types';

type TConfig = {
text: string;
Expand All @@ -21,19 +11,22 @@ type TConfig = {
}[];
}[];

export const buildForwardStartingConfig = (contract: TContract, forward_starting_dates: TForwardStartingDates[]) => {
export const buildForwardStartingConfig = (
contract: ContractsFor['available'][number],
forward_starting_dates?: TConfig
) => {
const forward_starting_config: TConfig = [];

if ((contract.forward_starting_options || []).length) {
contract.forward_starting_options.forEach(option => {
const duplicated_option = forward_starting_config.find(opt => opt.value === parseInt(option.date));
(contract.forward_starting_options ?? []).forEach(option => {
const duplicated_option = forward_starting_config.find(opt => opt.value === parseInt(option.date ?? ''));
const current_session = { open: toMoment(option.open), close: toMoment(option.close) };
if (duplicated_option) {
duplicated_option.sessions.push(current_session);
} else {
forward_starting_config.push({
text: toMoment(option.date).format('ddd - DD MMM, YYYY'),
value: parseInt(option.date),
value: parseInt(option.date ?? ''),
sessions: [current_session],
});
}
Expand Down
40 changes: 23 additions & 17 deletions packages/stores/src/mockStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@ import merge from 'lodash.merge';
import type { TStores } from '../types';

const mock = (): TStores & { is_mock: boolean } => {
const common_store_error = {
app_routing_history: [],
header: '',
message: '',
type: '',
redirect_label: '',
redirect_to: '',
should_clear_error_on_click: false,
should_show_refresh: false,
redirectOnClick: jest.fn(),
setError: jest.fn(),
};
const services_error = { code: '', message: '', type: '' };
return {
is_mock: true,
client: {
Expand Down Expand Up @@ -255,19 +268,7 @@ const mock = (): TStores & { is_mock: boolean } => {
setPrevAccountType: jest.fn(),
},
common: {
error: {
app_routing_history: [],
header: '',
message: '',
type: '',
redirect_label: '',
redirect_to: '',
should_clear_error_on_click: false,
should_show_refresh: false,
redirectOnClick: jest.fn(),
setError: jest.fn(),
},
services_error: {},
error: common_store_error,
current_language: 'EN',
isCurrentLanguage: jest.fn(),
is_from_derivgo: false,
Expand All @@ -280,6 +281,7 @@ const mock = (): TStores & { is_mock: boolean } => {
is_network_online: false,
server_time: undefined,
is_language_changing: false,
services_error: {},
is_socket_opened: false,
setAppstorePlatform: jest.fn(),
app_routing_history: [],
Expand All @@ -299,15 +301,14 @@ const mock = (): TStores & { is_mock: boolean } => {
is_closing_create_real_account_modal: false,
is_dark_mode_on: false,
is_language_settings_modal_on: false,
is_unsupported_contract_modal_visible: false,
has_only_forward_starting_contracts: false,
header_extension: null,
is_link_expired_modal_visible: false,
is_mobile: false,
is_positions_drawer_on: false,
is_reports_visible: false,
is_route_modal_on: false,
is_services_error_visible: false,
is_unsupported_contract_modal_visible: false,
disableApp: jest.fn(),
enableApp: jest.fn(),
setCurrentFocus: jest.fn(),
Expand All @@ -317,18 +318,19 @@ const mock = (): TStores & { is_mock: boolean } => {
togglePositionsDrawer: jest.fn(),
setDarkMode: jest.fn(),
setReportsTabIndex: jest.fn(),
has_only_forward_starting_contracts: false,
has_real_account_signup_ended: false,
notification_messages_ui: jest.fn(),
openRealAccountSignup: jest.fn(),
setHasOnlyForwardingContracts: jest.fn(),
setIsClosingCreateRealAccountModal: jest.fn(),
setRealAccountSignupEnd: jest.fn(),
setPurchaseState: jest.fn(),
setHasOnlyForwardingContracts: jest.fn(),
shouldNavigateAfterChooseCrypto: jest.fn(),
toggleLanguageSettingsModal: jest.fn(),
toggleServicesErrorModal: jest.fn(),
toggleLinkExpiredModal: jest.fn(),
toggleSetCurrencyModal: jest.fn(),
toggleServicesErrorModal: jest.fn(),
addToast: jest.fn(),
removeToast: jest.fn(),
reports_route_tab_index: 1,
Expand Down Expand Up @@ -510,6 +512,10 @@ const mock = (): TStores & { is_mock: boolean } => {
eventHandler: jest.fn(),
setLoginFlag: jest.fn(),
},
pushwoosh: {},
contract_replay: {},
chart_barrier_store: {},
active_symbols: {},
};
};

Expand Down
17 changes: 13 additions & 4 deletions packages/stores/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -438,11 +438,15 @@ type TCommonStoreError = {
should_show_refresh: boolean;
type?: string;
};
type TCommonStoreServicesError = {
code?: string;
message?: string;
type?: string;
};

type TCommonStore = {
isCurrentLanguage(language_code: string): boolean;
error: TCommonStoreError;
services_error: { code: string; message: string; type: string } | Record<string, never>;
has_error: boolean;
is_from_derivgo: boolean;
is_network_online: boolean;
Expand All @@ -454,6 +458,7 @@ type TCommonStore = {
changeSelectedLanguage: (key: string) => void;
current_language: string;
is_language_changing: boolean;
services_error: TCommonStoreServicesError;
is_socket_opened: boolean;
setAppstorePlatform: (value: string) => void;
app_routing_history: TAppRoutingHistory[];
Expand All @@ -468,13 +473,12 @@ type TUiStore = {
current_focus: string | null;
disableApp: () => void;
enableApp: () => void;
has_only_forward_starting_contracts: boolean;
has_real_account_signup_ended: boolean;
is_account_settings_visible: boolean;
is_loading: boolean;
is_cashier_visible: boolean;
is_closing_create_real_account_modal: boolean;
is_unsupported_contract_modal_visible: boolean;
has_only_forward_starting_contracts: boolean;
header_extension: JSX.Element | null;
is_dark_mode_on: boolean;
is_reports_visible: boolean;
Expand All @@ -485,6 +489,7 @@ type TUiStore = {
is_mobile: boolean;
is_positions_drawer_on: boolean;
is_services_error_visible: boolean;
is_unsupported_contract_modal_visible: boolean;
openRealAccountSignup: (
value: 'maltainvest' | 'svg' | 'add_crypto' | 'choose' | 'add_fiat' | 'set_currency' | 'manage'
) => void;
Expand All @@ -506,9 +511,9 @@ type TUiStore = {
toggleLinkExpiredModal: (state_change: boolean) => void;
togglePositionsDrawer: () => void;
toggleReadyToDepositModal: () => void;
toggleServicesErrorModal: (is_visible: boolean) => void;
toggleSetCurrencyModal: () => void;
toggleShouldShowRealAccountsList: (value: boolean) => void;
toggleServicesErrorModal: () => void;
is_tablet: boolean;
removeToast: (key: string) => void;
is_ready_to_deposit_modal_visible: boolean;
Expand Down Expand Up @@ -712,6 +717,10 @@ export type TCoreStores = {
notifications: TNotificationStore;
traders_hub: TTradersHubStore;
gtm: TGtmStore;
pushwoosh: Record<string, unknown>;
contract_replay: Record<string, unknown>;
chart_barrier_store: Record<string, unknown>;
active_symbols: Record<string, unknown>;
};

export type TStores = TCoreStores & {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import MarketUnavailableModal from './market-unavailable';

export default MarketUnavailableModal;
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
import PropTypes from 'prop-types';
import React from 'react';
import { Dialog } from '@deriv/components';
import { getPlatformSettings } from '@deriv/shared';
import { localize, Localize } from '@deriv/translations';
import { observer, useStore } from '@deriv/stores';

const MarketUnavailableModal = observer(({ onCancel, onConfirm }) => {
type TMarketUnavailableModalProps = {
is_loading?: boolean;
onCancel: () => void;
onConfirm: () => void;
};

const MarketUnavailableModal = observer(({ is_loading, onCancel, onConfirm }: TMarketUnavailableModalProps) => {
const { ui } = useStore();
const { disableApp, enableApp, is_loading, has_only_forward_starting_contracts: is_visible } = ui;
const { disableApp, enableApp, has_only_forward_starting_contracts: is_visible } = ui;

return (
<Dialog
Expand Down Expand Up @@ -38,9 +43,4 @@ const MarketUnavailableModal = observer(({ onCancel, onConfirm }) => {
);
});

MarketUnavailableModal.propTypes = {
onCancel: PropTypes.func,
onConfirm: PropTypes.func,
};

export default MarketUnavailableModal;
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { localize } from '@deriv/translations';

export const getTitle = (type: string) => {
export const getTitle = (type?: string) => {
switch (type) {
case 'buy':
return localize('Purchase Error');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import CompanyWideLimitExceededModal from './company-wide-limit-exceeded-modal';
import AccountVerificationRequiredModal from './account-verification-required-modal';

type TServicesError = {
code: string;
message: string;
type: string;
code?: string;
message?: string;
type?: string;
};

type TPropServicesErrorModel = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import UnsupportedContractModal from './unsupported-contract-modal.jsx';
import UnsupportedContractModal from './unsupported-contract-modal';

export default UnsupportedContractModal;

This file was deleted.

Loading