Skip to content

Commit

Permalink
Merge branch 'develop' into farzin/79040/replace_connect_method_with_…
Browse files Browse the repository at this point in the history
…useStore_hook_for_cashierlocked_component
  • Loading branch information
Farzin Mirzaie committed Oct 19, 2022
2 parents 004a0e8 + 79e5182 commit 8f85898
Show file tree
Hide file tree
Showing 100 changed files with 2,127 additions and 2,625 deletions.
5 changes: 4 additions & 1 deletion packages/account/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,7 @@ module.exports = {
webpack: { config: webpackConfig({}) },
},
},
};
rules: {
'import/no-extraneous-dependencies': ['off', { devDependencies: ['**/*.spec.*'] }],
},
};
1 change: 1 addition & 0 deletions packages/account/build/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const ALIASES = {
Services: path.resolve(__dirname, '../src/Services'),
Stores: path.resolve(__dirname, '../src/Stores'),
Styles: path.resolve(__dirname, '../src/Styles'),
Types: path.resolve(__dirname, '../src/Types'),
};

const rules = (is_test_env = false, is_mocha_only = false) => [
Expand Down
1 change: 1 addition & 0 deletions packages/account/build/global.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
declare module '@binary-com/binary-document-uploader';
1 change: 1 addition & 0 deletions packages/account/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
},
"dependencies": {
"@binary-com/binary-document-uploader": "^2.4.7",
"@deriv/api-types": "^1.0.54",
"@deriv/components": "^1.0.0",
"@deriv/shared": "^1.0.0",
"@deriv/translations": "^1.0.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const PasswordsPlatform = ({ email, has_dxtrade_accounts, has_mt5_accounts }) =>
const getPlatformTitle = () => {
let title = '';
if (has_mt5_accounts) {
title = localize('DMT5 Password');
title = localize('Deriv MT5 Password');
} else if (has_dxtrade_accounts) {
title = localize('{{platform_name_dxtrade}} Password', { platform_name_dxtrade });
}
Expand Down Expand Up @@ -44,16 +44,16 @@ const PasswordsPlatform = ({ email, has_dxtrade_accounts, has_mt5_accounts }) =>
{has_mt5_accounts && (
<React.Fragment>
<Text as='p' className='passwords-platform__desc' color='prominent' size='xs' weight='lighter'>
<Localize i18n_default_text='Your DMT5 password is for logging in to your Deriv MT5 accounts on the desktop, web, and mobile apps.' />
<Localize i18n_default_text='Your Deriv MT5 password is for logging in to your Deriv MT5 accounts on the desktop, web, and mobile apps.' />
</Text>
<Text as='p' className='passwords-platform__desc' color='prominent' size='xs' weight='lighter'>
<Localize
i18n_default_text='Click the <0>Change password</0> button to change your DMT5 password.'
i18n_default_text='Click the <0>Change password</0> button to change your Deriv MT5 password.'
components={[<strong key={0} />]}
/>
</Text>
<div className='passwords-platform__content'>
<Popover alignment='bottom' message='DMT5'>
<Popover alignment='bottom' message='Deriv MT5'>
<Icon icon='IcBrandDmt5' size={32} />
</Popover>
<Button
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const OnfidoSdkView = ({ country_code, documents_supported, handleViewComplete,
const [missing_personal_details, setMissingPersonalDetails] = React.useState(false);
const [is_status_loading, setStatusLoading] = React.useState(true);
const [retry_count, setRetryCount] = React.useState(0);
const token_timeout_ref = React.useRef();

// IDV country code - Alpha ISO2. Onfido country code - Alpha ISO3
// Ensures that any form of country code passed here is supported.
Expand Down Expand Up @@ -145,8 +146,7 @@ const OnfidoSdkView = ({ country_code, documents_supported, handleViewComplete,
}
};

React.useEffect(() => {
// retry state will re-run the token fetching
const fetchServiceToken = () => {
getOnfidoServiceToken().then(response_token => {
if (response_token.error) {
handleError(response_token.error);
Expand All @@ -158,7 +158,20 @@ const OnfidoSdkView = ({ country_code, documents_supported, handleViewComplete,
setStatusLoading(false);
});
}
if (token_timeout_ref.current) clearTimeout(token_timeout_ref.current);
});
};

React.useEffect(() => {
// retry state will re-run the token fetching
if (retry_count === 0) {
fetchServiceToken();
} else if (retry_count !== 0 && retry_count < 3) {
// Incorporating Exponential_backoff algo to prevent immediate throttling
token_timeout_ref.current = setTimeout(() => {
fetchServiceToken();
}, Math.pow(2, retry_count) + Math.random() * 1000);
}
}, [getOnfidoServiceToken, initOnfido, retry_count]);

let component_to_load;
Expand Down
11 changes: 11 additions & 0 deletions packages/account/src/Types/common-prop.type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export type TFormValidation = {
warnings: { [key: string]: string };
errors: { [key: string]: string };
};

export type TToken = {
display_name: string;
last_used: string;
scopes: string[];
token: string;
};
18 changes: 18 additions & 0 deletions packages/account/src/Types/context.type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { TToken } from './common-prop.type';

export type TPlatformContext = {
is_appstore: boolean;
displayName: string;
};

export type TApiContext = {
api_tokens: NonNullable<TToken[]> | undefined;
deleteToken: (token: string) => Promise<void>;
footer_ref: Element | DocumentFragment | undefined;
overlay_ref:
| ((...args: unknown[]) => unknown)
| import('prop-types').InferProps<{
current: import('prop-types').Requireable<unknown>;
}>;
toggleOverlay: () => void;
};
2 changes: 2 additions & 0 deletions packages/account/src/Types/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './common-prop.type';
export * from './context.type';
3 changes: 2 additions & 1 deletion packages/account/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@
"Sections/*": ["src/Sections/*"],
"Stores/*": ["src/Stores/*"],
"Styles/*": ["src/Styles/*"],
"Types": ["src/Types"],
"@deriv/*": ["../*/src"]
}
},
"include": ["src"]
"include": ["src","globals.d.ts"]
}
5 changes: 0 additions & 5 deletions packages/bot-web-ui/globals.d.ts

This file was deleted.

3 changes: 3 additions & 0 deletions packages/bot-web-ui/src/components/chart/chart.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import React from 'react';
// TODO Remove this after smartcharts is replaced
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
import { ChartTitle, SmartChart } from '@deriv/deriv-charts';
import RootStore from 'Stores/index';
import { connect } from 'Stores/connect';
Expand Down
6 changes: 3 additions & 3 deletions packages/bot-web-ui/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "./dist",
"rootDir": "./src",
"baseUrl": "./",
"paths": {
"Components/*": ["src/components/*"],
"Constants/*": ["src/constants/*"],
"Stores/*": ["src/stores/*"],
"Utils/*": ["src/utils/*"]
"Utils/*": ["src/utils/*"],
"@deriv/*": ["../*/src"]
}
},
"include": ["./src", "./src/**/*.ts", "./src/**/*.tsx", "globals.d.ts"]
"include": ["src"]
}
153 changes: 153 additions & 0 deletions packages/cashier/src/hooks/__tests__/useDepositLocked.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
import * as React from 'react';
// Todo: After upgrading to react 18 we should use @testing-library/react-hooks instead.
import { render, screen } from '@testing-library/react';
import { StoreProvider } from '../useStore';
import useDepositLocked from '../useDepositLocked';
import { TRootStore, DeepPartial } from '../../types';

const UseDepositLockedExample = () => {
const is_deposit_locked = useDepositLocked();

return (
<>
<p data-testid={'dt_is_deposit_locked'}>{is_deposit_locked ? 'true' : 'false'}</p>
</>
);
};

describe('useDepositLocked', () => {
test('should be false if none of the conditions are met', () => {
const mockRootStore: DeepPartial<TRootStore> = {
client: {
is_deposit_lock: false,
is_authentication_needed: false,
is_tnc_needed: false,
is_eu: false,
is_financial_account: false,
is_financial_information_incomplete: false,
is_trading_experience_incomplete: false,
mt5_login_list: [
{
account_type: 'demo',
sub_account_type: 'financial',
},
],
},
};

render(<UseDepositLockedExample />, {
wrapper: ({ children }) => <StoreProvider store={mockRootStore}>{children}</StoreProvider>,
});

const is_deposit_locked = screen.getByTestId('dt_is_deposit_locked');
expect(is_deposit_locked).toHaveTextContent('false');
});

test('should be true if is_deposit_lock is true', async () => {
const mockRootStore: DeepPartial<TRootStore> = {
client: {
is_deposit_lock: true,
is_authentication_needed: false,
is_tnc_needed: false,
is_eu: false,
is_financial_account: false,
is_financial_information_incomplete: false,
is_trading_experience_incomplete: false,
mt5_login_list: [
{
account_type: 'demo',
sub_account_type: 'financial',
},
],
},
};

render(<UseDepositLockedExample />, {
wrapper: ({ children }) => <StoreProvider store={mockRootStore}>{children}</StoreProvider>,
});

const is_deposit_locked = screen.getByTestId('dt_is_deposit_locked');
expect(is_deposit_locked).toHaveTextContent('true');
});

test('should be true if is_need_tnc is true', async () => {
const mockRootStore: DeepPartial<TRootStore> = {
client: {
is_deposit_lock: false,
is_authentication_needed: false,
is_tnc_needed: true,
is_eu: true,
is_financial_account: false,
is_financial_information_incomplete: false,
is_trading_experience_incomplete: false,
mt5_login_list: [
{
account_type: 'real',
sub_account_type: 'financial_stp',
},
],
},
};

render(<UseDepositLockedExample />, {
wrapper: ({ children }) => <StoreProvider store={mockRootStore}>{children}</StoreProvider>,
});

const is_deposit_locked = screen.getByTestId('dt_is_deposit_locked');
expect(is_deposit_locked).toHaveTextContent('true');
});

test('should be true if is_need_financial_assessment is true', async () => {
const mockRootStore: DeepPartial<TRootStore> = {
client: {
is_deposit_lock: false,
is_authentication_needed: false,
is_tnc_needed: false,
is_eu: false,
is_financial_account: true,
is_financial_information_incomplete: true,
is_trading_experience_incomplete: false,
mt5_login_list: [
{
account_type: 'demo',
sub_account_type: 'financial',
},
],
},
};

render(<UseDepositLockedExample />, {
wrapper: ({ children }) => <StoreProvider store={mockRootStore}>{children}</StoreProvider>,
});

const is_deposit_locked = screen.getByTestId('dt_is_deposit_locked');
expect(is_deposit_locked).toHaveTextContent('true');
});

test('should be true if is_need_authentication is true', async () => {
const mockRootStore: DeepPartial<TRootStore> = {
client: {
is_deposit_lock: false,
is_authentication_needed: true,
is_tnc_needed: false,
is_eu: true,
is_financial_account: false,
is_financial_information_incomplete: false,
is_trading_experience_incomplete: false,
mt5_login_list: [
{
account_type: 'real',
sub_account_type: 'financial_stp',
},
],
},
};

render(<UseDepositLockedExample />, {
wrapper: ({ children }) => <StoreProvider store={mockRootStore}>{children}</StoreProvider>,
});

const is_deposit_locked = screen.getByTestId('dt_is_deposit_locked');
expect(is_deposit_locked).toHaveTextContent('true');
});
});
Loading

0 comments on commit 8f85898

Please sign in to comment.