Skip to content

Commit

Permalink
Amina/fix: disable account when proof failed (#9555)
Browse files Browse the repository at this point in the history
* fix: disable account when proof failed

* fix: disable account when proof failed

* fix: flag

* fix: import

* fix: update with master
  • Loading branch information
amina-deriv authored Aug 15, 2023
1 parent 8b90802 commit 3133e6f
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import { StoreProvider, mockStore } from '@deriv/stores';
import CFDsListing from '../index';

jest.mock('Components/containers/listing-container', () =>
jest.fn(({ children }) => <div data-testid='listing-container'>{children}</div>)
);

describe('CFDsListing', () => {
const mock = mockStore({
traders_hub: {
selected_region: 'NON-EU',
has_any_real_account: true,
is_real: true,
can_get_more_cfd_mt5_accounts: true,
no_MF_account: true,
},
client: {
is_landing_company_loaded: true,
real_account_creation_unlock_date: '2022-02-02',
},
modules: {
cfd: {
toggleCompareAccountsModal: jest.fn(),
setAccountType: jest.fn(),
},
},
});

it('should render the component', () => {
const wrapper = ({ children }: { children: JSX.Element }) => (
<StoreProvider store={mock}>{children}</StoreProvider>
);

render(<CFDsListing />, { wrapper });
expect(screen.getByTestId('listing-container')).toBeInTheDocument();
});
});
41 changes: 27 additions & 14 deletions packages/appstore/src/components/cfds-listing/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { observer } from 'mobx-react-lite';
import { observer, useStore } from '@deriv/stores';
import { Text, StaticUrl } from '@deriv/components';
import { isMobile, formatMoney, getAuthenticationStatusInfo, Jurisdiction } from '@deriv/shared';
import { localize, Localize } from '@deriv/translations';
Expand All @@ -10,7 +10,6 @@ import PlatformLoader from 'Components/pre-loader/platform-loader';
import GetMoreAccounts from 'Components/get-more-accounts';
import { Actions } from 'Components/containers/trading-app-card-actions';
import { getHasDivider } from 'Constants/utils';
import { useStores } from 'Stores/index';
import { AvailableAccount, TDetailsOfEachMT5Loginid } from 'Types';
import './cfds-listing.scss';

Expand All @@ -20,14 +19,14 @@ type TDetailedExistingAccount = AvailableAccount &
key: string;
};

const CFDsListing = () => {
const CFDsListing = observer(() => {
const {
client,
modules: { cfd },
traders_hub,
common,
ui,
} = useStores();
} = useStore();
const {
available_dxtrade_accounts,
available_derivez_accounts,
Expand Down Expand Up @@ -62,8 +61,12 @@ const CFDsListing = () => {
const accounts_sub_text =
!is_eu_user || is_demo_low_risk ? localize('Compare accounts') : localize('Account Information');

const { poi_pending_for_bvi_labuan, poi_resubmit_for_bvi_labuan, poa_resubmit_for_labuan, is_idv_revoked } =
getAuthenticationStatusInfo(account_status);
const {
poi_pending_for_bvi_labuan_vanuatu,
poi_resubmit_for_bvi_labuan_vanuatu,
poa_resubmit_for_labuan,
is_idv_revoked,
} = getAuthenticationStatusInfo(account_status);

const getAuthStatus = (status_list: boolean[]) => status_list.some(status => status);

Expand All @@ -74,13 +77,16 @@ const CFDsListing = () => {
if (
getAuthStatus([
is_idv_revoked,
poi_resubmit_for_bvi_labuan,
poi_resubmit_for_bvi_labuan_vanuatu,
current_acc_status === 'proof_failed',
])
) {
return 'failed';
} else if (
getAuthStatus([poi_pending_for_bvi_labuan, current_acc_status === 'verification_pending'])
getAuthStatus([
poi_pending_for_bvi_labuan_vanuatu,
current_acc_status === 'verification_pending',
])
) {
return 'pending';
}
Expand All @@ -91,20 +97,27 @@ const CFDsListing = () => {
getAuthStatus([
poa_resubmit_for_labuan,
is_idv_revoked,
poi_resubmit_for_bvi_labuan,
poi_resubmit_for_bvi_labuan_vanuatu,
current_acc_status === 'proof_failed',
])
) {
return 'failed';
} else if (
getAuthStatus([poi_pending_for_bvi_labuan, current_acc_status === 'verification_pending'])
getAuthStatus([
poi_pending_for_bvi_labuan_vanuatu,
current_acc_status === 'verification_pending',
])
) {
return 'pending';
}
return null;
}
default:
return null;
if (current_acc_status === 'proof_failed') {
return 'failed';
} else if (current_acc_status === 'verification_pending') {
return 'pending';
}
}
}
return null;
Expand Down Expand Up @@ -183,7 +196,7 @@ const CFDsListing = () => {
existing_account.status || is_idv_revoked
? getMT5AccountAuthStatus(
existing_account.status,
existing_account?.short_code_and_region?.toLowerCase()
existing_account?.landing_company_short
)
: null;

Expand Down Expand Up @@ -389,6 +402,6 @@ const CFDsListing = () => {
: !is_real && <PlatformLoader />} */}
</ListingContainer>
);
};
});

export default observer(CFDsListing);
export default CFDsListing;
10 changes: 10 additions & 0 deletions packages/stores/src/mockStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,16 @@ const mock = (): TStores & { is_mock: boolean } => {
is_demo_low_risk: false,
is_mt5_notification_modal_visible: false,
setMT5NotificationModal: jest.fn(),
available_dxtrade_accounts: [],
available_derivez_accounts: [],
has_any_real_account: false,
startTrade: jest.fn(),
getExistingAccounts: jest.fn(),
getAccount: jest.fn(),
toggleAccountTypeModalVisibility: jest.fn(),
can_get_more_cfd_mt5_accounts: false,
is_demo_low_risk: true,
showTopUpModal: jest.fn(),
},
menu: {
attach: jest.fn(),
Expand Down
10 changes: 10 additions & 0 deletions packages/stores/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,16 @@ type TTradersHubStore = {
is_demo_low_risk: boolean;
is_mt5_notification_modal_visible: boolean;
setMT5NotificationModal: (value: boolean) => void;
available_dxtrade_accounts: DetailsOfEachMT5Loginid[];
available_derivez_accounts: DetailsOfEachMT5Loginid[];
has_any_real_account: boolean;
startTrade: () => void;
getExistingAccounts: () => void;
getAccount: () => void;
toggleAccountTypeModalVisibility: () => void;
can_get_more_cfd_mt5_accounts: boolean;
is_demo_low_risk: boolean;
showTopUpModal: () => void;
};

/**
Expand Down

0 comments on commit 3133e6f

Please sign in to comment.