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

[DTRA] / Kate / DTRA-420 / [Package 7] Tech debt: TS migration + Refactoring #10848

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
81130e7
chore: empty commit
kate-deriv Oct 20, 2023
3c97d7a
Kate / DTRA-325 / TS migration: Form/TradeParams/Duration files in Tr…
kate-deriv Oct 25, 2023
9330ffd
Merge branch 'master' into kate/DTRA-420/ts_migration_7
kate-deriv Oct 25, 2023
8343d73
refactor: remove code smells
kate-deriv Oct 25, 2023
d9dabeb
Merge branch master into kate/DTRA-420/ts_migration_7
kate-deriv Oct 25, 2023
7dcb6f3
Kate / DTRA-421 / TS migration: Contract + ContractReplay in Trader p…
kate-deriv Oct 30, 2023
48fca5f
refactor: remove code smells
kate-deriv Oct 30, 2023
e7dc4e8
Merge branch 'binary-com:master' into kate/DTRA-420/ts_migration_7
kate-deriv Oct 30, 2023
a126c22
Merge branch master into kate/DTRA-420/ts_migration_7
kate-deriv Nov 3, 2023
0804476
Maryia/DTRA-324/refactor: TS migration of trade.jsx and refactoring (…
maryia-deriv Nov 9, 2023
af732f3
Merge branch master into kate/DTRA-420/ts_migration_7
kate-deriv Nov 9, 2023
9e8b8ef
chore: remove code smells
kate-deriv Nov 9, 2023
976e0c5
Merge branch 'master' into kate/DTRA-420/ts_migration_7
kate-deriv Nov 9, 2023
1c22dbb
Merge branch master into kate/DTRA-420/ts_migration_7
kate-deriv Nov 9, 2023
bb906ac
chore: change type
kate-deriv Nov 9, 2023
c541906
Merge branch 'master' into kate/DTRA-420/ts_migration_7
kate-deriv Nov 10, 2023
359c33c
refactor: apply suggestions
kate-deriv Nov 10, 2023
4b803f8
fix: add missing string
kate-deriv Nov 10, 2023
978f4a4
Merge branch 'binary-com:master' into kate/DTRA-420/ts_migration_7
kate-deriv Nov 14, 2023
e3c39b5
Merge branch 'master' into kate/DTRA-420/ts_migration_7
kate-deriv Nov 16, 2023
87f5fc8
refactor: apply suggestions
kate-deriv Nov 16, 2023
d5ddb94
chore: add math trunc method
kate-deriv Nov 16, 2023
d6e8c63
Merge branch 'binary-com:master' into kate/DTRA-420/ts_migration_7
kate-deriv Nov 17, 2023
61dd537
Merge branch master into kate/DTRA-420/ts_migration_7
kate-deriv Nov 20, 2023
4ebcfc0
Merge branch master into kate/DTRA-420/ts_migration_7
kate-deriv Nov 21, 2023
1d33d8e
Merge branch master into kate/DTRA-420/ts_migration_7
kate-deriv Nov 29, 2023
682099e
Merge branch master into kate/DTRA-420/ts_migration_7
kate-deriv Nov 30, 2023
8bca8f7
Merge branch master of github.com:binary-com/deriv-app into kate/DTRA…
kate-deriv Dec 6, 2023
3cf4c4b
Merge branch master into kate/DTRA-420/ts_migration_7
kate-deriv Dec 11, 2023
0af3108
chore: remove extra ui mocked prop
kate-deriv Dec 11, 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
2 changes: 1 addition & 1 deletion packages/components/src/components/numpad/numpad.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { useLongPress } from '../../hooks';

type TNumpad = {
className?: string;
currency: string;
currency?: string;
is_regular?: boolean;
is_currency?: boolean;
is_submit_disabled?: boolean;
Expand Down
2 changes: 1 addition & 1 deletion packages/components/src/components/numpad/step-input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type TStepInput = {
onChange: (increment_value: string | number, pip_size: number) => void;
render?: (props: { value: string; className: string }) => React.ReactNode;
pip_size: number;
currency: string;
currency?: string;
label?: string;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type TTickPicker = {
min_value: number;
max_value: number;
onSubmit: (props: { target: { value: number; name: string } }) => void;
submit_label: React.ReactElement;
submit_label: React.ReactElement | string;
balakrishna-deriv marked this conversation as resolved.
Show resolved Hide resolved
singular_label: string;
plural_label: string;
onValueChange: (tick_value: number) => void;
Expand Down
10 changes: 1 addition & 9 deletions packages/shared/src/utils/contract/contract-types.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
import {
ContractUpdate,
ContractUpdateHistory,
Portfolio1,
ProposalOpenContract,
TickSpotData,
} from '@deriv/api-types';
import { ContractUpdate, ContractUpdateHistory, Portfolio1, ProposalOpenContract } from '@deriv/api-types';

export type TContractStore = {
clearContractUpdateConfigValues: () => void;
Expand Down Expand Up @@ -44,5 +38,3 @@ type TLimitProperty = {
};

export type TLimitOrder = Partial<Record<'stop_loss' | 'stop_out' | 'take_profit', TLimitProperty>>;

export type TTickSpotData = TickSpotData;
8 changes: 7 additions & 1 deletion packages/shared/src/utils/helpers/details.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ import { localize } from '@deriv/translations';
import moment from 'moment';
import { TContractInfo } from '../contract';

type TUnitMap = {
name_plural?: string;
name_singular?: string;
name?: string;
};

export const getDurationUnitValue = (obj_duration: moment.Duration) => {
const duration_ms = obj_duration.asMilliseconds() / 1000;
// Check with isEndTime to find out if value of duration has decimals
Expand Down Expand Up @@ -40,7 +46,7 @@ export const getUnitMap = () => {
m: { name_plural: localize('minutes'), name_singular: localize('minute') },
s: { name: localize('seconds') },
t: { name_plural: localize('ticks'), name_singular: localize('tick') },
};
} as { [key: string]: TUnitMap };
};

const TIME = {
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/src/utils/helpers/logic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ type TIsSoldBeforeStart = Required<Pick<TContractInfo, 'sell_time' | 'date_start

type TIsStarted = Required<Pick<TContractInfo, 'is_forward_starting' | 'current_spot_time' | 'date_start'>>;

export const isContractElapsed = (contract_info: TContractInfo, tick?: TickSpotData) => {
export const isContractElapsed = (contract_info: TContractInfo, tick?: null | TickSpotData) => {
if (isEmptyObject(tick) || isEmptyObject(contract_info)) return false;
const end_time = getEndTime(contract_info) || 0;
if (end_time && tick && tick.epoch) {
Expand Down
38 changes: 33 additions & 5 deletions packages/stores/src/mockStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ const mock = (): TStores & { is_mock: boolean } => {
residence_list: [],
should_restrict_bvi_account_creation: false,
should_restrict_vanuatu_account_creation: false,
should_show_eu_content: false,
fetchAccountSettings: jest.fn(),
setAccountSettings: jest.fn(),
upgradeable_landing_companies: [],
Expand Down Expand Up @@ -326,6 +327,7 @@ const mock = (): TStores & { is_mock: boolean } => {
is_cashier_visible: false,
is_wallet_modal_visible: false,
is_chart_layout_default: false,
is_chart_countdown_visible: false,
is_closing_create_real_account_modal: false,
is_dark_mode_on: false,
is_language_settings_modal_on: false,
Expand Down Expand Up @@ -361,9 +363,9 @@ const mock = (): TStores & { is_mock: boolean } => {
},
resetRealAccountSignupParams: jest.fn(),
notification_messages_ui: jest.fn(),
onChangeUiStore: jest.fn(),
openPositionsDrawer: jest.fn(),
openRealAccountSignup: jest.fn(),
onChangeUiStore: jest.fn(),
setChartCountdown: jest.fn(),
setIsWalletModalVisible: jest.fn(),
setHasOnlyForwardingContracts: jest.fn(),
Expand All @@ -374,6 +376,8 @@ const mock = (): TStores & { is_mock: boolean } => {
setPurchaseState: jest.fn(),
setAppContentsScrollRef: jest.fn(),
shouldNavigateAfterChooseCrypto: jest.fn(),
simple_duration_unit: 't',
toggleHistoryTab: jest.fn(),
toggleLanguageSettingsModal: jest.fn(),
togglePositionsDrawer: jest.fn(),
toggleLinkExpiredModal: jest.fn(),
Expand Down Expand Up @@ -420,9 +424,7 @@ const mock = (): TStores & { is_mock: boolean } => {
setMT5MigrationModalEnabled: jest.fn(),
toggleMT5MigrationModal: jest.fn(),
vanilla_trade_type: 'VANILLALONGCALL',
is_chart_countdown_visible: false,
is_additional_kyc_info_modal_open: false,
simple_duration_unit: 't',
toggleAdditionalKycInfoModal: jest.fn(),
is_kyc_information_submitted_modal_open: false,
toggleKycInformationSubmittedModal: jest.fn(),
Expand Down Expand Up @@ -694,16 +696,42 @@ const mock = (): TStores & { is_mock: boolean } => {
pushwoosh: {},
contract_replay: {
contract_store: {
accumulator_previous_spot_time: null,
barriers_array: [],
contract_config: {},
contract_info: {},
contract_update: {},
contract_update_history: [],
digits_info: {},
display_status: '',
getContractsArray: jest.fn(),
is_digit_contract: false,
is_ended: false,
marker: {
contract_info: {},
epoch_array: [],
key: '',
price_array: [],
type: '',
},
markers_array: [],
},
chart_state: '',
chartStateChange: jest.fn(),
has_error: false,
is_chart_loading: true,
is_forward_starting: false,
is_market_closed: false,
is_sell_requested: false,
onClickCancel: jest.fn(),
onClickSell: jest.fn(),
onMount: jest.fn(),
onUnmount: jest.fn(),
removeErrorMessage: jest.fn(),
error_message: '',
removeAccountSwitcherListener: jest.fn(),
setAccountSwitcherListener: jest.fn(),
},
chart_barrier_store: {},
chart_barrier_store: {} as TCoreStores['chart_barrier_store'],
active_symbols: {
active_symbols: [],
setActiveSymbols: jest.fn(),
Expand Down
82 changes: 78 additions & 4 deletions packages/stores/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,20 @@ type TActionProps = TButtonProps & {
route?: string;
};

type TChartStateChangeOption = {
indicator_type_name?: string;
indicators_category_name?: string;
isClosed?: boolean;
is_favorite?: boolean;
is_info_open?: boolean;
is_open?: boolean;
chart_type_name?: string;
search_string?: string;
symbol?: string;
symbol_category?: string;
time_interval_name?: string;
};

type TNotificationMessage = {
action?: TActionProps;
className?: string;
Expand Down Expand Up @@ -467,6 +481,7 @@ type TClientStore = {
residence_list: ResidenceList;
should_restrict_bvi_account_creation: boolean;
should_restrict_vanuatu_account_creation: boolean;
should_show_eu_content: boolean;
updateMT5Status: () => Promise<void>;
fetchAccountSettings: () => Promise<void>;
setAccountSettings: (get_settings_response: GetSettings) => void;
Expand Down Expand Up @@ -603,11 +618,11 @@ type TUiStore = {
is_positions_drawer_on: boolean;
is_services_error_visible: boolean;
is_unsupported_contract_modal_visible: boolean;
onChangeUiStore: ({ name, value }: { name: string; value: unknown }) => void;
openPositionsDrawer: () => void;
openRealAccountSignup: (
value: 'maltainvest' | 'svg' | 'add_crypto' | 'choose' | 'add_fiat' | 'set_currency' | 'manage'
) => void;
onChangeUiStore: ({ name, value }: { name: string; value: number | null }) => void;
notification_messages_ui: React.ElementType;
setChartCountdown: (value: boolean) => void;
populateFooterExtensions: (
Expand Down Expand Up @@ -643,6 +658,7 @@ type TUiStore = {
toggleAccountsDialog: () => void;
toggleAccountSettings: (props?: boolean) => void;
toggleCashier: () => void;
toggleHistoryTab: (state_change?: boolean) => void;
toggleLanguageSettingsModal: () => void;
toggleLinkExpiredModal: (state_change: boolean) => void;
togglePositionsDrawer: () => void;
Expand Down Expand Up @@ -815,7 +831,7 @@ type TContractTradeStore = {
underlying,
}: Partial<TAccumulatorContractBarriersData & { underlying: string }>) => void;
updateChartType: (type: string) => void;
updateGranularity: (granularity: number) => void;
updateGranularity: (granularity: number | null) => void;
updateProposal: (response: ProposalOpenContract) => void;
};

Expand Down Expand Up @@ -968,14 +984,72 @@ type TTradersHubStore = {

type TContractReplay = {
contract_store: {
accumulator_previous_spot_time: number | null;
barriers_array: Array<TCoreStores['chart_barrier_store']> | [];
contract_config:
| Record<string, never>
| {
chart_type: string;
granularity?: number;
end_epoch?: number;
start_epoch: number;
scroll_to_epoch: number;
}
| null;
contract_info: TPortfolioPosition['contract_info'];
contract_update: ProposalOpenContract['limit_order'];
contract_update_history: TContractStore['contract_update_history'];
digits_info: { [key: number]: { digit: number; spot: string } };
display_status: string;
getContractsArray: () => {
type: string;
markers: Array<{
color: string;
epoch: number;
quote?: number;
text?: string;
type: string;
}>;
props: {
hasPersistentBorders: boolean;
};
}[];
is_digit_contract: boolean;
is_ended: boolean;
marker: {
contract_info: TPortfolioPosition['contract_info'];
epoch_array: Array<number> | [];
key: string;
price_array: Array<number> | [];
type: string;
};
markers_array:
| []
| Array<{
content_config: { className: string };
marker_config: { ContentComponent: 'div'; x: string | number; y: string | number };
react_key: string;
type: string;
}>;
};
chart_state: string;
chartStateChange: (state: string, option?: TChartStateChangeOption) => void;
error_code?: string;
error_message?: string;
has_error: boolean;
indicative_status?: string;
is_chart_loading: boolean;
is_forward_starting: boolean;
is_market_closed: boolean;
is_sell_requested: boolean;
margin?: number;
onClickCancel: (contract_id?: number) => void;
onClickSell: (contract_id?: number) => void;
onMount: (contract_id?: number) => void;
onUnmount: () => void;
removeErrorMessage: () => void;
error_message: string;
removeAccountSwitcherListener: () => void;
setAccountSwitcherListener: (contract_id: string | number, history: Array<string>) => void;
};
type TGtmStore = {
is_gtm_applicable: boolean;
Expand Down Expand Up @@ -1014,7 +1088,7 @@ export type TCoreStores = {
gtm: TGtmStore;
pushwoosh: Record<string, unknown>;
contract_replay: TContractReplay;
chart_barrier_store: Record<string, unknown>;
chart_barrier_store: TBarriers[number];
active_symbols: TActiveSymbolsStore;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ const ContractDrawer = observer(
contract_end_time={getEndTime(contract_info)}
contract_info={contract_info}
contract_update_history={contract_update_history}
duration_unit={getDurationUnitText(getDurationPeriod(contract_info))}
duration_unit={getDurationUnitText(getDurationPeriod(contract_info)) ?? ''}
duration={getDurationTime(contract_info)}
exit_spot={exit_spot}
has_result={
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import Loading from '_common/components/loading';

type TChartLoader = {
is_dark: boolean;
is_dark?: boolean;
is_visible: boolean;
};

Expand Down
3 changes: 2 additions & 1 deletion packages/trader/src/App/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import TradeHeaderExtensions from 'App/Containers/trade-header-extensions';
import TradeFooterExtensions from 'App/Containers/trade-footer-extensions';
import TradeSettingsExtensions from 'App/Containers/trade-settings-extensions';
import { NetworkStatusToastErrorPopup } from 'Modules/Trading/Containers/toast-popup';
import type { TWebSocket } from 'Types';
import initStore from './init-store';
import 'Sass/app.scss';
import type { TCoreStores } from '@deriv/stores/types';
Expand All @@ -13,7 +14,7 @@ import TraderProviders from '../trader-providers';
type Apptypes = {
passthrough: {
root_store: TCoreStores;
WS: unknown;
WS: TWebSocket;
};
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
import { configure } from 'mobx';
import RootStore from 'Stores';
import { setWebsocket } from '@deriv/shared';
import ServerTime from '_common/base/server_time';
import { TCoreStores } from '@deriv/stores/types';
import type { TWebSocket } from 'Types';
import RootStore from '../Stores';

configure({ enforceActions: 'observed' });

let root_store;
let root_store: TCoreStores;

const initStore = (core_store, websocket) => {
const initStore = (core_store: TCoreStores, websocket: TWebSocket) => {
if (root_store) return root_store;

ServerTime.init(core_store.common);
setWebsocket(websocket);
root_store = new RootStore(core_store);
root_store = new RootStore(core_store) as unknown as TCoreStores;

return root_store;
};
Expand Down
Loading