Skip to content

Commit

Permalink
farrah/ fixed cfd lint errors (#5607)
Browse files Browse the repository at this point in the history
* ci/ exclude dist files from eslint scan

* ci/ disable spaced-comment

* ci/ exclude lib dir from eslint scan

* fixed cfd eslint errors

* renamed variables and fixed types

* fixed missing return function

* refactor code

* fixed cleanup function

* fixed invalid property document_file on submit

Co-authored-by: Ali(Ako) Hosseini <ali.hosseini@firstsource.tech>
  • Loading branch information
farrah-deriv and Ali(Ako) Hosseini committed Jul 13, 2022
1 parent 6f133b7 commit 1860575
Show file tree
Hide file tree
Showing 19 changed files with 85 additions and 31 deletions.
2 changes: 1 addition & 1 deletion packages/cfd/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"build": "f () { webpack --config \"./build/webpack.config.js\" --env base=$1;}; f",
"build:travis": "echo \"No build:travis specified\"",
"test": "echo \"No mocha:test specified\"",
"test:eslint": "eslint \"./src/**/*.?(js|jsx)\"",
"test:eslint": "eslint \"./src/**/*.?(js|jsx|ts|tsx)\"",
"test:mocha": "mochapack -r babel-polyfill -r jsdom-global/register -r mock-local-storage --webpack-config \"./build/webpack.config-test.js\" \"src/**/__tests__/*.js\" --webpack-env.mocha_only --require ignore-styles",
"deploy": "echo \"No deploy specified\"",
"deploy:clean": "echo \"No deploy:clean specified\"",
Expand Down
5 changes: 5 additions & 0 deletions packages/cfd/src/Components/Errors/error-component.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,12 @@ const ErrorComponent = ({
};

ErrorComponent.propTypes = {
header: PropTypes.string,
is_dialog: PropTypes.bool,
message: PropTypes.oneOfType([PropTypes.node, PropTypes.string, PropTypes.object]),
redirect_label: PropTypes.string,
redirectOnClick: PropTypes.func,
should_show_refresh: PropTypes.bool,
type: PropTypes.string,
};

Expand Down
2 changes: 1 addition & 1 deletion packages/cfd/src/Components/Routes/binary-routes.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Switch } from 'react-router-dom';
import { PlatformContext } from '@deriv/shared';
import { Localize } from '@deriv/translations';
import getRoutesConfig from '../../Constants/routes-config';
import RouteWithSubRoutes from './route-with-sub-routes';
import RouteWithSubRoutes from './route-with-sub-routes.jsx';

const BinaryRoutes = props => {
const { is_dashboard } = React.useContext(PlatformContext);
Expand Down
4 changes: 3 additions & 1 deletion packages/cfd/src/Components/cfd-account-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,9 @@ const CFDAccountCardComponent = ({
toggleShouldShowRealAccountsList,
}: TCFDAccountCard) => {
const platform_icon = is_eu ? 'cfd' : type.type;
const icon: any = type.type ? <Icon icon={account_icons[type.platform][platform_icon]} size={64} /> : null;
const icon: React.ReactElement | null = type.type ? (
<Icon icon={account_icons[type.platform][platform_icon]} size={64} />
) : null;
const has_popular_banner: boolean =
type.type === 'synthetic' &&
type.category === 'real' &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Modal, Button } from '@deriv/components';
import { Localize, localize } from '@deriv/translations';
import { connect } from 'Stores/connect';
import { TCFDFinancialStpPendingDialog } from './props.types';
import RootStore from 'Stores/index';

const CFDFinancialStpPendingDialog = ({
enableApp,
Expand Down Expand Up @@ -34,7 +35,7 @@ const CFDFinancialStpPendingDialog = ({
</Modal>
);

export default connect(({ ui, client, modules: { cfd } }: any) => ({
export default connect(({ ui, client, modules: { cfd } }: RootStore) => ({
is_fully_authenticated: client.is_fully_authenticated,
enableApp: ui.enableApp,
disableApp: ui.disableApp,
Expand Down
17 changes: 9 additions & 8 deletions packages/cfd/src/Components/cfd-poa.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ type TFormValuesInputs = {
};

type TDocumentFile = {
document_file: Array<TObjDocumentFile>;
document_file?: Array<TObjDocumentFile>;
files?: Array<TObjDocumentFile>;
};

Expand Down Expand Up @@ -182,7 +182,7 @@ const CFDPOA = ({ onSave, onCancel, index, onSubmit, refreshNotifications, ...pr
files: TObjDocumentFile,
error_message: string,
setFieldTouched: (field: string, isTouched?: boolean, shouldValidate?: boolean) => void,
setFieldValue: (field: string, files: TObjDocumentFile) => void,
setFieldValue: (field: string, value: TObjDocumentFile) => void,
values: TFormValues
) => {
setFieldTouched('document_file', true);
Expand All @@ -206,7 +206,8 @@ const CFDPOA = ({ onSave, onCancel, index, onSubmit, refreshNotifications, ...pr
};

const onSubmitValues = async (values: TFormValues, actions: FormikHelpers<TFormValues>) => {
const { document_file, ...uploadables } = values;
const uploadables = { ...values };
delete uploadables.document_file;

actions.setSubmitting(true);
const data = await WS.setSettings(uploadables);
Expand Down Expand Up @@ -249,8 +250,8 @@ const CFDPOA = ({ onSave, onCancel, index, onSubmit, refreshNotifications, ...pr
return;
}
const { identity } = get_account_status.authentication;
const _has_poi = !(identity && identity.status === 'none');
if (_has_poi) {
const has_poi = !(identity && identity.status === 'none');
if (has_poi) {
onProceed();
} else {
setFormState({
Expand Down Expand Up @@ -278,9 +279,9 @@ const CFDPOA = ({ onSave, onCancel, index, onSubmit, refreshNotifications, ...pr
WS.authorized.getAccountStatus().then((response: AccountStatusResponse) => {
WS.wait('states_list').then(() => {
const { get_account_status } = response;
const { document, identity } = get_account_status?.authentication!;
const __has_poi = !!(identity && identity.status === 'none');
setFormState({ ...form_state, ...{ poa_status: document?.status, __has_poi } }, () => {
const { document, identity } = get_account_status?.authentication || {};
const has_poi = !!(identity && identity.status === 'none');
setFormState({ ...form_state, ...{ poa_status: document?.status, has_poi } }, () => {
setIsLoading(false);
refreshNotifications();
});
Expand Down
2 changes: 1 addition & 1 deletion packages/cfd/src/Components/cfd-real-account-display.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import specifications, { TSpecifications } from '../Constants/cfd-specifications
import { CFDAccountCard } from './cfd-account-card';
import { general_messages } from '../Constants/cfd-shared-strings';
import { DetailsOfEachMT5Loginid, ResidenceList, LandingCompany, GetSettings } from '@deriv/api-types';
import { TExistingData, TTradingPlatformAccounts } from './props.types.js';
import { TExistingData, TTradingPlatformAccounts } from './props.types';

type TStandPoint = {
financial_company: string;
Expand Down
3 changes: 3 additions & 0 deletions packages/cfd/src/Components/success-dialog.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,18 +89,21 @@ SuccessDialog.defaultProps = {
SuccessDialog.propTypes = {
classNameMessage: PropTypes.string,
has_cancel: PropTypes.bool,
has_close_icon: PropTypes.bool,
has_submit: PropTypes.bool,
heading: PropTypes.oneOfType([PropTypes.string, PropTypes.object]),
icon: PropTypes.object,
icon_size: PropTypes.string,
icon_type: PropTypes.string,
is_medium_button: PropTypes.bool,
is_open: PropTypes.bool,
message: PropTypes.oneOfType([PropTypes.string, PropTypes.object]),
onCancel: PropTypes.func,
onSubmit: PropTypes.func,
text_cancel: PropTypes.string,
text_submit: PropTypes.string,
title: PropTypes.string,
toggleModal: PropTypes.func,
width: PropTypes.string,
};

Expand Down
6 changes: 2 additions & 4 deletions packages/cfd/src/Containers/cfd-dashboard.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { withRouter } from 'react-router';
import { RouteComponentProps, withRouter } from 'react-router';
import { Redirect } from 'react-router-dom';
import { DesktopWrapper, Icon, MobileWrapper, Tabs, PageError, Loading, Text } from '@deriv/components';
import {
Expand Down Expand Up @@ -32,7 +32,6 @@ import { getPlatformMt5DownloadLink, getPlatformDXTradeDownloadLink } from '../H
import 'Sass/cfd-dashboard.scss';
import RootStore from 'Stores/index';
import { DetailsOfEachMT5Loginid, LandingCompany, ResidenceList } from '@deriv/api-types';
import { History } from 'history';

declare module 'react' {
interface HTMLAttributes<T> extends React.AriaAttributes, React.DOMAttributes<T> {
Expand Down Expand Up @@ -84,7 +83,7 @@ type TMt5StatusServerType = {

type TMt5StatusServer = Record<'demo' | 'real', TMt5StatusServerType[]>;

type TCFDDashboardProps = {
type TCFDDashboardProps = RouteComponentProps & {
account_settings: { residence: string };
account_status: object;
beginRealSignupForMt5: () => void;
Expand Down Expand Up @@ -156,7 +155,6 @@ type TCFDDashboardProps = {
disableCFDPasswordModal: () => void;
openPasswordModal: (account_type?: TOpenAccountTransferMeta) => void;
openTopUpModal: () => void;
history: History;
setCurrentAccount: (data: DetailsOfEachMT5Loginid, meta: TOpenAccountTransferMeta) => void;
setAccountType: (account_type: TOpenAccountTransferMeta) => void;
mt5_status_server: TMt5StatusServer;
Expand Down
18 changes: 14 additions & 4 deletions packages/cfd/src/Containers/cfd-password-manager-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,20 @@ const CountdownComponent = ({ count_from = 60, onTimeout }: TCountdownComponent)
const [count, setCount] = React.useState<number>(count_from);

React.useEffect(() => {
let interval: ReturnType<typeof setTimeout>;

if (count !== 0) {
const interval = setTimeout(() => {
interval = setTimeout(() => {
setCount(count - 1);
}, 1000);

return () => clearTimeout(interval);
} else {
onTimeout();
}

onTimeout();
return () => {
clearTimeout(interval);
};

// eslint-disable-next-line react-hooks/exhaustive-deps
}, [count]);
return <span className='countdown'>{count}</span>;
Expand Down Expand Up @@ -396,11 +401,16 @@ const CFDPasswordManagerModal = ({
};

CFDPasswordManagerModal.propTypes = {
disableApp: PropTypes.func,
enableApp: PropTypes.func,
email: PropTypes.string,
is_visible: PropTypes.bool,
selected_account: PropTypes.string,
selected_account_type: PropTypes.string,
selected_account_group: PropTypes.string,
selected_server: PropTypes.string,
selected_login: PropTypes.string,
sendVerifyEmail: PropTypes.func,
toggleModal: PropTypes.func,
platform: PropTypes.string,
};
Expand Down
2 changes: 1 addition & 1 deletion packages/cfd/src/Containers/cfd-password-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,7 @@ const CFDServerForm = ({ ...props }: TCFDServerFormProps) => {
},
};
})
.sort((a, _b) => (a.recommended ? -1 : 1))
.sort(a => (a.recommended ? -1 : 1))
.sort((a, b) => (a.disabled ? a.disabled : 0) - (b.disabled ? b.disabled : 0));
}, [props.mt5_trading_servers]);

Expand Down
12 changes: 12 additions & 0 deletions packages/cfd/src/Containers/cfd-reset-password-modal.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import PropTypes from 'prop-types';
import { Formik, FormikHelpers } from 'formik';
import RootStore from 'Stores/index';
import React from 'react';
Expand Down Expand Up @@ -276,6 +277,17 @@ const CFDResetPasswordModal = ({
);
};

CFDResetPasswordModal.propTypes = {
current_list: PropTypes.oneOfType([PropTypes.array, PropTypes.object]),
email: PropTypes.string,
is_cfd_reset_password_modal_enabled: PropTypes.bool,
is_eu: PropTypes.bool,
is_logged_in: PropTypes.bool,
platform: PropTypes.string,
setCFDPasswordResetModal: PropTypes.func,
history: PropTypes.object,
};

export default React.memo(
withRouter(
connect(({ modules: { cfd }, client }: RootStore) => ({
Expand Down
3 changes: 1 addition & 2 deletions packages/cfd/src/Containers/compare-accounts-content.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import { Table, Text, ThemedScrollbars, Div100vhContainer } from '@deriv/components';
import { localize, Localize } from '@deriv/translations';
import { isDesktop, CFD_PLATFORMS, isLandingCompanyEnabled, PlatformContext } from '@deriv/shared';
import { isDesktop, CFD_PLATFORMS, isLandingCompanyEnabled } from '@deriv/shared';
import { LandingCompany } from '@deriv/api-types';

type TCFDAttributeDescriberProps = {
Expand Down Expand Up @@ -592,7 +592,6 @@ const ModalContent = ({
platform,
show_eu_related,
residence,
is_uk,
]);

const show_risk_message = platform === CFD_PLATFORMS.MT5 || !show_eu_related;
Expand Down
11 changes: 11 additions & 0 deletions packages/cfd/src/Containers/investor-password-manager.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import PropTypes from 'prop-types';
import React from 'react';
import { Field, Form, Formik, FieldProps } from 'formik';
import { PasswordInput, PasswordMeter, Text, Button, Icon } from '@deriv/components';
Expand Down Expand Up @@ -128,4 +129,14 @@ const InvestorPasswordManager = ({
);
};

InvestorPasswordManager.propTypes = {
error_message_investor: PropTypes.string,
is_submit_success_investor: PropTypes.bool,
multi_step_ref: PropTypes.object,
onSubmit: PropTypes.func,
setPasswordType: PropTypes.func,
toggleModal: PropTypes.func,
validatePassword: PropTypes.func,
};

export default InvestorPasswordManager;
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { localize } from '@deriv/translations';
import { connect } from 'Stores/connect';
import CFDFinancialStpRealAccountSignup from 'Containers/cfd-financial-stp-real-account-signup';
import { TMT5AccountOpeningRealFinancialStpModal } from './props.types';
import RootStore from 'Stores/index';

const MT5AccountOpeningRealFinancialStpModal = ({
disableApp,
Expand Down Expand Up @@ -42,7 +43,7 @@ const MT5AccountOpeningRealFinancialStpModal = ({
</React.Fragment>
);

export default connect(({ ui, modules }: any) => ({
export default connect(({ ui, modules }: RootStore) => ({
disableApp: ui.disableApp,
disableMt5FinancialStpModal: modules.cfd.disableMt5FinancialStpModal,
enableApp: ui.enableApp,
Expand Down
5 changes: 2 additions & 3 deletions packages/cfd/src/Containers/props.types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { History } from 'history';
import { RouteComponentProps } from 'react-router';
import { DetailsOfEachMT5Loginid, VerifyEmailResponse } from '@deriv/api-types';
import { FormikHelpers as FormikActions } from 'formik';
import { TCFDPasswordFormValues } from './cfd-password-modal';
Expand Down Expand Up @@ -58,15 +58,14 @@ export type TError = {
message: string;
};

export type TCFDResetPasswordModal = {
export type TCFDResetPasswordModal = RouteComponentProps & {
current_list: Array<DetailsOfEachMT5Loginid> & Record<string, DetailsOfEachMT5Loginid>;
email: string;
is_cfd_reset_password_modal_enabled: boolean;
is_eu: boolean;
is_logged_in: boolean;
platform: CFD_Platform;
setCFDPasswordResetModal: (value: boolean) => void;
history: History;
};

export type TCFDPasswordSuccessMessage = {
Expand Down
4 changes: 3 additions & 1 deletion packages/cfd/src/Containers/routes.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import React from 'react';
import { withRouter } from 'react-router';
import BinaryRoutes from '../Components/Routes';
import { connect } from '../Stores/connect';
import ErrorComponent from '../Components/Errors/error-component';
import ErrorComponent from '../Components/Errors/error-component.jsx';

const Routes = props => {
if (props.has_error) {
Expand All @@ -24,7 +24,9 @@ Routes.propTypes = {
error: MobxPropTypes.objectOrObservableObject,
has_error: PropTypes.bool,
is_logged_in: PropTypes.bool,
is_logging_in: PropTypes.bool,
is_virtual: PropTypes.bool,
passthrough: PropTypes.object,
};

// need to wrap withRouter around connect
Expand Down
12 changes: 10 additions & 2 deletions packages/cfd/src/app.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import PropTypes from 'prop-types';
import React from 'react';
import Routes from './Containers/routes';
import Routes from './Containers/routes.jsx';
import { MobxContentProvider } from './Stores/connect';
import initStore from './init-store'; // eslint-disable-line import/extensions

const App = ({ passthrough }: any) => {
type TAppProps = {
passthrough: {
root_store: any;
WS: any;
};
};

const App = ({ passthrough }: TAppProps) => {
const [root_store] = React.useState(initStore(passthrough.root_store, passthrough.WS));

return (
Expand Down
2 changes: 2 additions & 0 deletions packages/cfd/src/templates/app/components/loading.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ const Loading = ({ className, id, is_fullscreen = true, is_slow_loading, status,
};

Loading.propTypes = {
className: PropTypes.string,
id: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
is_fullscreen: PropTypes.bool,
is_slow_loading: PropTypes.bool,
status: PropTypes.array,
theme: PropTypes.string,
Expand Down

1 comment on commit 1860575

@vercel
Copy link

@vercel vercel bot commented on 1860575 Jul 13, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

deriv-app – ./

binary.sx
deriv-app-git-master.binary.sx
deriv-app.vercel.app
deriv-app.binary.sx

Please sign in to comment.