Skip to content

Commit

Permalink
Fasih/COJ-1247/Added lazy loading for some section (deriv-com#15839)
Browse files Browse the repository at this point in the history
* chore: added lazy loading for some section

* chore: worked in close account section

* chore: added lazy load on close account

* chore: fixed css formating

* chore: removed unused code

---------

Co-authored-by: Muhammad Fasih Ali Naqvi <[email protected]>
  • Loading branch information
fasihali-deriv and Muhammad Fasih Ali Naqvi authored Jul 11, 2024
1 parent a4875e4 commit 0b66e02
Show file tree
Hide file tree
Showing 19 changed files with 56 additions and 46 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import { Localize } from '@deriv/translations';
import AccountArticle from 'Components/article';
import AccountArticle from '../article';

const ApiTokenArticle = () => (
<AccountArticle
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import { useIsMounted } from '@deriv/shared';
import { Button, Icon, Modal, Text, Popover, useCopyToClipboard } from '@deriv/components';
import { Localize } from '@deriv/translations';
import { TPopoverAlignment } from 'Types';
import { TPopoverAlignment } from '../../Types';

type TApiTokenClipboard = {
scopes?: string[];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { TApiContext } from 'Types';
import { TApiContext } from '../../Types';

const ApiTokenContext = React.createContext<TApiContext>({
api_tokens: [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Button, Icon, Modal, Text, Popover } from '@deriv/components';
import { useIsMounted } from '@deriv/shared';
import { Localize } from '@deriv/translations';
import ApiTokenContext from './api-token-context';
import { TPopoverAlignment, TFormattedToken, TApiContext } from 'Types';
import { TPopoverAlignment, TFormattedToken, TApiContext } from '../../Types';
import { useDevice } from '@deriv-com/ui';

type TApiTokenDeleteButton = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import ApiTokenDeleteButton from './api-token-delete-button';
import ApiTokenTableRowCell from './api-token-table-row-cell';
import ApiTokenTableRowScopesCell from './api-token-table-row-scopes-cell';
import ApiTokenTableRowTokenCell from './api-token-table-row-token-cell';
import { TFormattedToken } from 'Types';
import { TFormattedToken } from '../../Types';

type TApiTokenTableRow = {
token: TFormattedToken;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import ApiTokenTableRow from './api-token-table-row';
import ApiTokenTableRowHeader from './api-token-table-row-header';
import ApiTokenTableRowScopesCell from './api-token-table-row-scopes-cell';
import ApiTokenTableRowTokenCell from './api-token-table-row-token-cell';
import { TApiContext, TToken } from 'Types';
import { TApiContext, TToken } from '../../Types';

const ApiTokenTable = () => {
const { api_tokens } = React.useContext<TApiContext>(ApiTokenContext);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import { StaticUrl } from '@deriv/components';
import { Localize, localize } from '@deriv/translations';
import { getBrandWebsiteName, getPlatformSettings } from '@deriv/shared';
import AccountArticle from 'Components/article';
import AccountArticle from '../article';
import SelfExclusionContext from './self-exclusion-context';
import { observer } from '@deriv/stores';

Expand Down
22 changes: 18 additions & 4 deletions packages/account/src/Constants/routes-config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@ import {
ProofOfIdentity,
ProofOfAddress,
ProofOfOwnership,
ApiToken,
TwoFactorAuthentication,
SelfExclusion,
Account,
ClosingAccount,
DeactivateAccount,
ProofOfIncome,
} from '../Sections';
Expand Down Expand Up @@ -58,6 +54,24 @@ const ConnectedApps = makeLazyLoader(
() => <Loading />
)();

const ApiToken = makeLazyLoader(
() => moduleLoader(() => import('../Sections/Security/ApiToken')),
() => <Loading />
)();

const TwoFactorAuthentication = makeLazyLoader(
() => moduleLoader(() => import('../Sections/Security/TwoFactorAuthentication')),
() => <Loading />
)();
const SelfExclusion = makeLazyLoader(
() => moduleLoader(() => import('../Sections/Security/SelfExclusion')),
() => <Loading />
)();
const ClosingAccount = makeLazyLoader(
() => moduleLoader(() => import('../Sections/Security/ClosingAccount')),
() => <Loading />
)();

export type TPage404 = typeof Page404;

// Order matters
Expand Down
12 changes: 6 additions & 6 deletions packages/account/src/Sections/Security/ApiToken/api-token.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import { useDevice } from '@deriv-com/ui';
import { getPropertyValue, WS } from '@deriv/shared';
import { observer, useStore } from '@deriv/stores';
import { Localize, localize } from '@deriv/translations';
import { TToken } from 'Types';
import { ApiTokenContext, ApiTokenArticle, ApiTokenCard, ApiTokenTable } from 'Components/api-token';
import InlineNoteWithIcon from 'Components/inline-note-with-icon';
import LoadErrorMessage from 'Components/load-error-message';
import { API_TOKEN_CARD_DETAILS, TOKEN_LIMITS, TOKEN_NAME_REGEX } from 'Constants/api-token-card-details';
import { TToken } from '../../../Types';
import { ApiTokenContext, ApiTokenArticle, ApiTokenCard, ApiTokenTable } from '../../../Components/api-token';
import InlineNoteWithIcon from '../../../Components/inline-note-with-icon';
import LoadErrorMessage from '../../../Components/load-error-message';
import { API_TOKEN_CARD_DETAILS, TOKEN_LIMITS, TOKEN_NAME_REGEX } from '../../../Constants/api-token-card-details';
import './api-token.scss';

type AptTokenState = {
Expand Down Expand Up @@ -248,7 +248,7 @@ const ApiToken = observer(() => {
className='da-api-token__input dc-input__input-group'
label={localize('Token name')}
value={values.token_name}
onChange={e => {
onChange={(e: React.ChangeEvent<HTMLInputElement>) => {
setFieldTouched('token_name', true);
handleChange(e);
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
TDetailsOfDerivXAccount,
TDetailsOfMT5Account,
TDetailsOfCtraderAccount,
} from 'Types';
} from '../../../../Types';
import ClosingAccountPendingContent from './closing-account-pending-content';
import ClosingAccountPendingWrapper from './closing-account-pending-wrapper';
import ClosingAccountPendingBalance from './closing-account-pending-balance';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
} from '@deriv/shared';
import { observer, useStore } from '@deriv/stores';
import { Localize } from '@deriv/translations';
import { TCFDPlatform, TDetailsOfDerivXAccount, TDetailsOfMT5Account } from 'Types';
import { TCFDPlatform, TDetailsOfDerivXAccount, TDetailsOfMT5Account } from '../../../../Types';
import ClosingAccountPendingWrapper from './closing-account-pending-wrapper';
import ClosingAccountPendingContent from './closing-account-pending-content';

Expand All @@ -19,7 +19,7 @@ type TClosingAccountPendingBalanceProps = {
account_balance: TDetailsOfMT5Account[] | TDetailsOfDerivXAccount[];
};

type TShortcode = Parameters<typeof getCFDAccountDisplay>[0]['shortcode'];
type TShortcode = Exclude<TDetailsOfMT5Account['landing_company_short'], 'seychelles'>;

const ClosingAccountPendingBalance = observer(({ platform, account_balance }: TClosingAccountPendingBalanceProps) => {
const { traders_hub } = useStore();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import { CFD_PLATFORMS, getCFDAccount, getCFDAccountDisplay, getCFDPlatformLabel, getMT5Icon } from '@deriv/shared';
import { observer, useStore } from '@deriv/stores';
import { Localize } from '@deriv/translations';
import { TCFDPlatform, TDetailsOfDerivXAccount, TDetailsOfMT5Account } from 'Types';
import { TCFDPlatform, TDetailsOfDerivXAccount, TDetailsOfMT5Account } from '../../../../Types';
import ClosingAccountPendingWrapper from './closing-account-pending-wrapper';
import ClosingAccountPendingContent from './closing-account-pending-content';

Expand All @@ -11,7 +11,7 @@ type TClosingAccountPendingPositionsProps = {
open_positions: Array<TDetailsOfMT5Account | TDetailsOfDerivXAccount>; //ctrader
};

type TShortcode = Parameters<typeof getCFDAccountDisplay>[0]['shortcode'];
type TShortcode = Exclude<TDetailsOfMT5Account['landing_company_short'], 'seychelles'>;

const ClosingAccountPendingPositions = observer(
({ platform, open_positions }: TClosingAccountPendingPositionsProps) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import { Field, Form, Formik, FormikErrors, FieldProps, FormikValues } from 'formik';
import { Checkbox, FormSubmitButton, Input, Text } from '@deriv/components';
import { localize, Localize } from '@deriv/translations';
import { TClosingAccountFormValues } from 'Types';
import { TClosingAccountFormValues } from '../../../Types';
import {
CHARACTER_LIMIT_FOR_CLOSING_ACCOUNT,
MAX_ALLOWED_REASONS_FOR_CLOSING_ACCOUNT,
Expand All @@ -11,7 +11,7 @@ import {
SET_TOTAL_ACCUMULATED_CHARACTERS,
SET_TOTAL_CHECKBOX_CHECKED,
getCloseAccountReasonsList,
} from 'Constants/closing-account-config';
} from '../../../Constants/closing-account-config';

type TClosingAccountReasonFormProps = {
onBackClick: () => void;
Expand Down Expand Up @@ -208,7 +208,9 @@ const ClosingAccountReasonForm = ({ onBackClick, onConfirmClick }: TClosingAccou
name='other_trading_platforms'
value={values.other_trading_platforms}
max_characters={CHARACTER_LIMIT_FOR_CLOSING_ACCOUNT}
onChange={e => handleInputChange(e, values.other_trading_platforms, handleChange)}
onChange={(e: React.ChangeEvent<HTMLInputElement>) =>
handleInputChange(e, values.other_trading_platforms, handleChange)
}
onPaste={handleInputPaste}
/>
)}
Expand All @@ -225,7 +227,9 @@ const ClosingAccountReasonForm = ({ onBackClick, onConfirmClick }: TClosingAccou
name='do_to_improve'
value={values.do_to_improve}
max_characters={CHARACTER_LIMIT_FOR_CLOSING_ACCOUNT}
onChange={e => handleInputChange(e, values.do_to_improve, handleChange)}
onChange={(e: React.ChangeEvent<HTMLInputElement>) =>
handleInputChange(e, values.do_to_improve, handleChange)
}
onPaste={handleInputPaste}
/>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Loading, Modal, Text } from '@deriv/components';
import { routes } from '@deriv/shared';
import { useCloseDerivAccount } from '@deriv/api';
import { Localize } from '@deriv/translations';
import { MAX_ALLOWED_REASONS_FOR_CLOSING_ACCOUNT } from 'Constants/closing-account-config';
import { MAX_ALLOWED_REASONS_FOR_CLOSING_ACCOUNT } from '../../../Constants/closing-account-config';
import ClosingAccountHasPendingConditions from './closing-account-pending-conditions/closing-account-has-pending-conditions';
import ClosingAccountReasonForm from './closing-account-reason-form';
import ClosingAccountWarningModal from './closing-account-warning-modal';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ import {
WS,
} from '@deriv/shared';
import { localize } from '@deriv/translations';
import DemoMessage from 'Components/demo-message';
import 'Components/self-exclusion/self-exclusion.scss';
import LoadErrorMessage from 'Components/load-error-message';
import SelfExclusionArticleContent from 'Components/self-exclusion/self-exclusion-article-content';
import SelfExclusionContext from 'Components/self-exclusion/self-exclusion-context';
import SelfExclusionModal from 'Components/self-exclusion/self-exclusion-modal';
import SelfExclusionWrapper from 'Components/self-exclusion/self-exclusion-wrapper';
import SelfExclusionForm from 'Components/self-exclusion/self-exclusion-form';
import DemoMessage from '../../../Components/demo-message';
import '../../../Components/self-exclusion/self-exclusion.scss';
import LoadErrorMessage from '../../../Components/load-error-message';
import SelfExclusionArticleContent from '../../../Components/self-exclusion/self-exclusion-article-content';
import SelfExclusionContext from '../../../Components/self-exclusion/self-exclusion-context';
import SelfExclusionModal from '../../../Components/self-exclusion/self-exclusion-modal';
import SelfExclusionWrapper from '../../../Components/self-exclusion/self-exclusion-wrapper';
import SelfExclusionForm from '../../../Components/self-exclusion/self-exclusion-form';
import { FormikHelpers, FormikValues } from 'formik';
import { observer, useStore } from '@deriv/stores';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ const DigitForm = observer(() => {
className='two-factor__input'
label={localize('Authentication code')}
value={values.digit_code}
onChange={e => {
onChange={(e: React.ChangeEvent<HTMLInputElement>) => {
handleChange(e);
setReadyForVerification(false);
}}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import { localize, Localize } from '@deriv/translations';
import AccountArticle from 'Components/article';
import AccountArticle from '../../../Components/article';

const TwoFactorAuthenticationArticle = () => (
<AccountArticle
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import { getPropertyValue, WS } from '@deriv/shared';
import LoadErrorMessage from 'Components/load-error-message';
import LoadErrorMessage from '../../../Components/load-error-message';
import { observer, useStore } from '@deriv/stores';
import { Loading } from '@deriv/components';
import TwoFactorEnabled from './two-factor-enabled';
Expand Down
8 changes: 0 additions & 8 deletions packages/account/src/Sections/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@ import { ProofOfIdentityContainer, ProofOfIdentity } from 'Sections/Verification
import ProofOfAddress from 'Sections/Verification/ProofOfAddress';
import ProofOfOwnership from 'Sections/Verification/ProofOfOwnership';
import ProofOfIncome from 'Sections/Verification/ProofOfIncome';
import TwoFactorAuthentication from 'Sections/Security/TwoFactorAuthentication';
import ApiToken from 'Sections/Security/ApiToken';
import SelfExclusion from 'Sections/Security/SelfExclusion';
import Account from 'Containers/Account/account';
import ClosingAccount from 'Sections/Security/ClosingAccount';
import DeactivateAccount from 'Sections/Security/DeactivateAccount'; // TODO: Remove once mobile team has changed this link

export {
Expand All @@ -23,10 +19,6 @@ export {
ProofOfAddress,
ProofOfOwnership,
ProofOfIncome,
TwoFactorAuthentication,
ApiToken,
SelfExclusion,
Account,
ClosingAccount,
DeactivateAccount,
};

0 comments on commit 0b66e02

Please sign in to comment.