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

Amina/remove failed verification modals of mt5 #119

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,26 @@ import React from 'react';
import { BrowserRouter } from 'react-router-dom';
import { fireEvent, render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import getStatusBadgeConfig from 'Configs/get-status-badge-config';
import getStatusBadgeConfig from '../get-status-badge-config';
import { AUTH_STATUS_CODES, MT5_ACCOUNT_STATUS, routes } from '@deriv/shared';
import { TMT5AccountStatus } from 'Types';

describe('getStatusBadgeConfig', () => {
let account_status: TMT5AccountStatus;
const openFailedVerificationModal = jest.fn();
const openVerificationDocsListModal = jest.fn();
const setIsVerificationModalVisible = jest.fn();
const selected_account_type = 'test type';

const renderCheck = (
account_status: Parameters<typeof getStatusBadgeConfig>[0],
openFailedVerificationModal: Parameters<typeof getStatusBadgeConfig>[1],
openVerificationDocsListModal: Parameters<typeof getStatusBadgeConfig>[1],
selected_account_type: Parameters<typeof getStatusBadgeConfig>[2],
setIsVerificationModalVisible?: Parameters<typeof getStatusBadgeConfig>[3],
user_account_status?: Parameters<typeof getStatusBadgeConfig>[4]
) => {
const badge = getStatusBadgeConfig(
account_status,
openFailedVerificationModal,
openVerificationDocsListModal,
selected_account_type,
setIsVerificationModalVisible,
user_account_status
Expand All @@ -37,7 +37,7 @@ describe('getStatusBadgeConfig', () => {
it('should render pending status', () => {
account_status = MT5_ACCOUNT_STATUS.PENDING;

renderCheck(account_status, openFailedVerificationModal, selected_account_type);
renderCheck(account_status, openVerificationDocsListModal, selected_account_type);

expect(screen.getByText('Pending verification')).toBeInTheDocument();
expect(screen.getByText('IcAlertWarning')).toBeInTheDocument();
Expand All @@ -46,19 +46,24 @@ describe('getStatusBadgeConfig', () => {
it('should render failed status and trigger "Why?"', () => {
account_status = MT5_ACCOUNT_STATUS.FAILED;

renderCheck(account_status, openFailedVerificationModal, selected_account_type);
renderCheck(account_status, openVerificationDocsListModal, selected_account_type);

expect(screen.getByText('Verification failed.')).toBeInTheDocument();
expect(screen.getByText('IcRedWarning')).toBeInTheDocument();

fireEvent.click(screen.getByText('Why?'));
expect(openFailedVerificationModal).toBeCalledWith(selected_account_type);
expect(openVerificationDocsListModal).toBeCalledWith(selected_account_type);
});

it('should render needs_verification status and redirect to identity by default', () => {
account_status = MT5_ACCOUNT_STATUS.NEEDS_VERIFICATION;

renderCheck(account_status, openFailedVerificationModal, selected_account_type, setIsVerificationModalVisible);
renderCheck(
account_status,
openVerificationDocsListModal,
selected_account_type,
setIsVerificationModalVisible
);

expect(screen.getByText(/Needs verification./));
expect(screen.getByText('IcAlertInfo'));
Expand All @@ -74,7 +79,7 @@ describe('getStatusBadgeConfig', () => {
it('should render migrated_with_position status', () => {
account_status = MT5_ACCOUNT_STATUS.MIGRATED_WITH_POSITION;

renderCheck(account_status, openFailedVerificationModal, selected_account_type);
renderCheck(account_status, openVerificationDocsListModal, selected_account_type);

expect(screen.getByText('No new positions')).toBeInTheDocument();
expect(screen.getByText('IcAlertWarning')).toBeInTheDocument();
Expand All @@ -83,7 +88,7 @@ describe('getStatusBadgeConfig', () => {
it('should render migrated_without_position status', () => {
account_status = MT5_ACCOUNT_STATUS.MIGRATED_WITHOUT_POSITION;

renderCheck(account_status, openFailedVerificationModal, selected_account_type);
renderCheck(account_status, openVerificationDocsListModal, selected_account_type);

expect(screen.getByText('Account closed')).toBeInTheDocument();
expect(screen.getByText('IcAlertWarning')).toBeInTheDocument();
Expand All @@ -92,7 +97,7 @@ describe('getStatusBadgeConfig', () => {
it('should render need_verification status and redirect to POA when POI is verified', () => {
account_status = MT5_ACCOUNT_STATUS.NEEDS_VERIFICATION;

renderCheck(account_status, openFailedVerificationModal, selected_account_type, undefined, {
renderCheck(account_status, openVerificationDocsListModal, selected_account_type, undefined, {
poi_status: AUTH_STATUS_CODES.VERIFIED,
poa_status: AUTH_STATUS_CODES.NONE,
});
Expand All @@ -109,7 +114,7 @@ describe('getStatusBadgeConfig', () => {
it('should render need_verification status and redirect to POI when POI status is not verified and POA status is not verified', () => {
account_status = MT5_ACCOUNT_STATUS.NEEDS_VERIFICATION;

renderCheck(account_status, openFailedVerificationModal, selected_account_type, undefined, {
renderCheck(account_status, openVerificationDocsListModal, selected_account_type, undefined, {
poi_status: AUTH_STATUS_CODES.NONE,
poa_status: AUTH_STATUS_CODES.NONE,
});
Expand Down
88 changes: 88 additions & 0 deletions packages/account/src/Configs/get-mt5-status-badge-config.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import React from 'react';
import { Text } from '@deriv/components';
import { MT5_ACCOUNT_STATUS, TRADING_PLATFORM_STATUS } from '@deriv/shared';
import { Localize } from '@deriv/translations';
import { TMT5AccountStatus } from '../Types/common.type';

const getMT5StatusBadgeConfig = (mt5_account_status: TMT5AccountStatus) => {
const BadgeTextComponent = <Text key={0} weight='bold' size='xxxs' color='warning' />;

switch (mt5_account_status) {
case MT5_ACCOUNT_STATUS.PENDING:
return {
text: (
<Localize
i18n_default_text='<0>Pending verification</0>'
components={[<Text key={0} weight='bold' size='xxxs' color='var(--status-warning)' />]}
/>
),
icon: 'IcAlertWarning',
};
case MT5_ACCOUNT_STATUS.FAILED:
return {
text: (
<Localize
i18n_default_text='<0>Verification failed.</0> <1>Why?</1>'
components={[
<Text key={0} weight='bold' size='xxxs' color='var(--status-danger)' />,
<Text
key={1}
className='link-verification-failed'
onClick={() => {
//TODO: default jurisdiction;
}}
/>,
]}
/>
),
icon: 'IcRedWarning',
};
case MT5_ACCOUNT_STATUS.NEEDS_VERIFICATION: {
return {
text: (
<Localize
i18n_default_text='<0>Needs verification.</0><1>Verify now</1>'
components={[
<Text key={0} weight='bold' size='xxxs' color='var(--status-info)' />,
<Text
key={1}
className='link-need-verification'
onClick={() => {
//TODO: default jurisdiction;
}}
/>,
]}
/>
),
icon: 'IcAlertInfo',
};
}
case MT5_ACCOUNT_STATUS.MIGRATED_WITH_POSITION:
return {
text: <Localize i18n_default_text='<0>No new positions</0>' components={[BadgeTextComponent]} />,
icon: 'IcAlertWarning',
};
case MT5_ACCOUNT_STATUS.MIGRATED_WITHOUT_POSITION:
return {
text: <Localize i18n_default_text='<0>Account closed</0>' components={[BadgeTextComponent]} />,
icon: 'IcAlertWarning',
};
case MT5_ACCOUNT_STATUS.UNDER_MAINTENANCE:
return {
text: <Localize i18n_default_text='<0>Server maintenance</0>' components={[BadgeTextComponent]} />,
icon: 'IcAlertWarning',
};
case TRADING_PLATFORM_STATUS.UNAVAILABLE:
return {
text: <Localize i18n_default_text='<0>Unavailable</0>' components={[BadgeTextComponent]} />,
icon: 'IcAlertWarning',
};
default:
return {
text: '',
icon: '',
};
}
};

export default getMT5StatusBadgeConfig;
65 changes: 15 additions & 50 deletions packages/account/src/Configs/get-status-badge-config.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,12 @@
import React from 'react';
import { Text } from '@deriv/components';
import { AUTH_STATUS_CODES, MT5_ACCOUNT_STATUS, TRADING_PLATFORM_STATUS, routes } from '@deriv/shared';
import { ACCOUNT_BADGE_STATUS } from '@deriv/shared';
import { Localize } from '@deriv/translations';
import { TAuthStatusCodes, TMT5AccountStatus } from '../Types/common.type';
import { Link } from 'react-router-dom';
import { TAccountBadgeStatus } from '../Types/common.type';

const getStatusBadgeConfig = (
mt5_account_status: TMT5AccountStatus,
openFailedVerificationModal?: (selected_account_type: string) => void,
selected_account_type?: string,
setIsVerificationModalVisible?: (value: boolean) => void,
user_account_status?: { poi_status: TAuthStatusCodes; poa_status: TAuthStatusCodes }
) => {
const BadgeTextComponent = <Text key={0} weight='bold' size='xxxs' color='warning' />;

switch (mt5_account_status) {
case MT5_ACCOUNT_STATUS.PENDING:
const getStatusBadgeConfig = (account_status: TAccountBadgeStatus, openVerificationDocsListModal: () => void) => {
switch (account_status) {
case ACCOUNT_BADGE_STATUS.PENDING:
return {
text: (
<Localize
Expand All @@ -25,7 +16,7 @@ const getStatusBadgeConfig = (
),
icon: 'IcAlertWarning',
};
case MT5_ACCOUNT_STATUS.FAILED:
case ACCOUNT_BADGE_STATUS.FAILED:
return {
text: (
<Localize
Expand All @@ -36,60 +27,34 @@ const getStatusBadgeConfig = (
key={1}
className='link-verification-failed'
onClick={() => {
openFailedVerificationModal?.(selected_account_type ?? '');
openVerificationDocsListModal();
}}
/>,
]}
/>
),
icon: 'IcRedWarning',
};
case MT5_ACCOUNT_STATUS.NEEDS_VERIFICATION: {
const redirect_url =
user_account_status?.poi_status === AUTH_STATUS_CODES.NONE
? routes.proof_of_identity
: routes.proof_of_address;
case ACCOUNT_BADGE_STATUS.NEEDS_VERIFICATION: {
return {
text: (
<Localize
i18n_default_text='<0>Needs verification.</0><1>Verify now</1>'
components={[
<Text key={0} weight='bold' size='xxxs' color='var(--status-info)' />,
setIsVerificationModalVisible ? (
<Text
key={1}
className='link-need-verification'
onClick={() => setIsVerificationModalVisible?.(true)}
/>
) : (
<Link key={1} className='link-need-verification' to={redirect_url} />
),
<Text
key={1}
className='link-need-verification'
onClick={() => {
openVerificationDocsListModal();
}}
/>,
]}
/>
),
icon: 'IcAlertInfo',
};
}
case MT5_ACCOUNT_STATUS.MIGRATED_WITH_POSITION:
return {
text: <Localize i18n_default_text='<0>No new positions</0>' components={[BadgeTextComponent]} />,
icon: 'IcAlertWarning',
};
case MT5_ACCOUNT_STATUS.MIGRATED_WITHOUT_POSITION:
return {
text: <Localize i18n_default_text='<0>Account closed</0>' components={[BadgeTextComponent]} />,
icon: 'IcAlertWarning',
};
case MT5_ACCOUNT_STATUS.UNDER_MAINTENANCE:
return {
text: <Localize i18n_default_text='<0>Server maintenance</0>' components={[BadgeTextComponent]} />,
icon: 'IcAlertWarning',
};
case TRADING_PLATFORM_STATUS.UNAVAILABLE:
return {
text: <Localize i18n_default_text='<0>Unavailable</0>' components={[BadgeTextComponent]} />,
icon: 'IcAlertWarning',
};
default:
return {
text: '',
Expand Down
3 changes: 3 additions & 0 deletions packages/account/src/Types/common.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
MT5_ACCOUNT_STATUS,
Platforms,
TRADING_PLATFORM_STATUS,
ACCOUNT_BADGE_STATUS,
} from '@deriv/shared';

export type TToken = NonNullable<ApiToken['tokens']>[0];
Expand Down Expand Up @@ -281,6 +282,8 @@ export type TFinancialInformationForm = Omit<SetFinancialAssessmentRequest, 'set

export type TAuthStatusCodes = typeof AUTH_STATUS_CODES[keyof typeof AUTH_STATUS_CODES];

export type TAccountBadgeStatus = typeof ACCOUNT_BADGE_STATUS[keyof typeof ACCOUNT_BADGE_STATUS] | null;

export type TMT5AccountStatus =
| typeof MT5_ACCOUNT_STATUS[keyof typeof MT5_ACCOUNT_STATUS]
| typeof TRADING_PLATFORM_STATUS[keyof typeof TRADING_PLATFORM_STATUS];
Expand Down
Loading
Loading