Skip to content

Commit

Permalink
Merge branch 'master' into coveralls-workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
heorhi-deriv committed Nov 14, 2024
2 parents 8f20d87 + 0c0815a commit c666325
Show file tree
Hide file tree
Showing 88 changed files with 1,363 additions and 1,155 deletions.
4 changes: 2 additions & 2 deletions packages/account/src/Configs/employment-tax-info-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const generateEmploymentTaxInfoFormValues = ({
},
});

const getEmploymentTaxIfoConfig = (
const getEmploymentTaxInfoConfig = (
{
account_settings,
residence_list,
Expand All @@ -60,4 +60,4 @@ const getEmploymentTaxIfoConfig = (
};
};

export default getEmploymentTaxIfoConfig;
export default getEmploymentTaxInfoConfig;
32 changes: 27 additions & 5 deletions packages/account/src/Configs/user-profile-validation-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { localize } from '@deriv-com/translations';
import * as Yup from 'yup';
import { ValidationConstants } from '@deriv-com/utils';
import dayjs from 'dayjs';
import { TinValidations } from '@deriv/api/types';
import { TEmployeeDetailsTinValidationConfig } from '../Types';

const {
Expand All @@ -25,6 +24,7 @@ type TINDepdendents = {
* This flag indicates that tin was skipped before and was set by BE
*/
is_tin_auto_set?: boolean;
is_employment_status_tin_mandatory?: boolean;
};

Yup.addMethod(Yup.string, 'validatePhoneNumberLength', function (message) {
Expand All @@ -38,10 +38,20 @@ Yup.addMethod(Yup.string, 'validatePhoneNumberLength', function (message) {
});
});

const makeTinOptional = ({ is_mf, is_real, tin_skipped, is_tin_auto_set }: TINDepdendents) => {
const makeTinOptional = ({
is_mf,
is_real,
tin_skipped,
is_tin_auto_set,
is_employment_status_tin_mandatory,
}: TINDepdendents) => {
const check_if_tin_skipped = tin_skipped && !is_tin_auto_set;
if (is_real) {
return check_if_tin_skipped;
// Students and unemployed are not required to provide TIN to have a regulated MT5 jurisdiction
if (is_tin_auto_set && is_employment_status_tin_mandatory) {
return true;
}
return check_if_tin_skipped || !is_employment_status_tin_mandatory;
}
// Check For Virtual account
if (is_mf) {
Expand All @@ -56,9 +66,14 @@ export const getEmploymentAndTaxValidationSchema = ({
is_real = false,
is_tin_auto_set = false,
is_duplicate_account = false,
is_employment_status_tin_mandatory = false,
}: TEmployeeDetailsTinValidationConfig) => {
return Yup.object({
employment_status: Yup.string().required(localize('Employment status is required.')),
employment_status: Yup.string().when('is_employment_status_tin_mandatory', {
is: () => is_employment_status_tin_mandatory,
then: Yup.string().required(localize('Employment status is required.')),
otherwise: Yup.string().notRequired(),
}),
tax_residence: Yup.string().when('is_mf', {
is: () => is_mf,
then: Yup.string().required(localize('Tax residence is required.')),
Expand All @@ -73,7 +88,14 @@ export const getEmploymentAndTaxValidationSchema = ({
}),
tax_identification_number: Yup.string()
.when(['tin_skipped'], {
is: (tin_skipped: boolean) => makeTinOptional({ is_mf, is_real, tin_skipped, is_tin_auto_set }),
is: (tin_skipped: boolean) =>
makeTinOptional({
is_mf,
is_real,
tin_skipped,
is_tin_auto_set,
is_employment_status_tin_mandatory,
}),
then: Yup.string().notRequired(),
otherwise: Yup.string().required(localize('Tax identification number is required.')),
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,19 @@ const EmploymentTaxDetailsContainer = observer(
const { data: residence_list } = useResidenceList();
const { client } = useStore();

const { is_virtual, account_settings } = client;
const { is_virtual, account_settings, account_status } = client;

const { tin_employment_status_bypass } = tin_validation_config;

const is_tin_required = !is_virtual && !tin_employment_status_bypass?.includes(values.employment_status);
const is_employment_status_mandatory = is_virtual
? true
: Boolean(account_status?.status?.includes('mt5_additional_kyc_required'));

const is_tin_required =
!is_virtual &&
values.employment_status &&
!tin_employment_status_bypass?.includes(values.employment_status) &&
is_employment_status_mandatory;

const [is_tax_residence_popover_open, setIsTaxResidencePopoverOpen] = useState(false);
const [is_tin_popover_open, setIsTinPopoverOpen] = useState(false);
Expand Down Expand Up @@ -132,15 +140,11 @@ const EmploymentTaxDetailsContainer = observer(

const isFieldDisabled = (field_name: string) => isFieldImmutable(field_name, editable_fields);

// [TODO] - This should come from BE
const should_disable_employment_status =
isFieldDisabled('employment_status') || Boolean(is_virtual && client.account_settings.employment_status);

return (
<div id={'employment-tax-section'}>
<EmploymentStatusField
required
is_disabled={should_disable_employment_status}
required={is_employment_status_mandatory}
is_disabled={isFieldDisabled('employment_status')}
fieldFocused={should_focus_fields && !account_settings.employment_status}
/>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ const EmploymentTaxInfo = observer(
is_duplicate_account:
client.account_settings.immutable_fields?.includes('tax_identification_number') ||
client.account_settings.immutable_fields?.includes('tax_residence'),
is_employment_status_tin_mandatory: true, // Override the value to true as we need to make Employment status mandatory for Real account creation
});

const handleCancel = (values: FormikValues) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,12 +300,15 @@ const PersonalDetailsForm = observer(() => {

const is_tin_auto_set = Boolean(account_settings?.tin_skipped);

const is_employment_status_tin_mandatory = Boolean(account_status?.status?.includes('mt5_additional_kyc_required'));

const PersonalDetailSchema = getPersonalDetailsValidationSchema(
is_virtual,
is_svg,
tin_validation_config,
is_tin_auto_set,
account_settings?.immutable_fields
account_settings?.immutable_fields,
is_employment_status_tin_mandatory
);
const displayErrorMessage = (status: { code: string; msg: string }) => {
if (status?.code === 'PhoneNumberTaken') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@ export const getPersonalDetailsValidationSchema = (
is_svg?: boolean,
tin_validation_config?: TinValidations,
is_tin_auto_set?: boolean,
immutable_fields?: string[]
immutable_fields?: string[],
is_employment_status_tin_mandatory?: boolean
) => {
if (is_virtual) return Yup.object();

Expand All @@ -154,6 +155,7 @@ export const getPersonalDetailsValidationSchema = (
is_tin_auto_set,
is_duplicate_account:
immutable_fields?.includes('tax_identification_number') || immutable_fields?.includes('tax_residence'),
is_employment_status_tin_mandatory,
});

return personal_details_schema.concat(address_detail_schema).concat(employment_tin_schema);
Expand Down
13 changes: 7 additions & 6 deletions packages/account/src/Types/common.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ export type TIDVFormValues = {
error_message?: string;
};

export type TPlatforms = typeof Platforms[keyof typeof Platforms];
export type TPlatforms = (typeof Platforms)[keyof typeof Platforms];

export type TServerError = {
code?: string;
Expand All @@ -172,7 +172,7 @@ export type TServerError = {
details?: { [key: string]: string };
fields?: string[];
};
export type TCFDPlatform = typeof CFD_PLATFORMS[keyof typeof CFD_PLATFORMS];
export type TCFDPlatform = (typeof CFD_PLATFORMS)[keyof typeof CFD_PLATFORMS];

export type TClosingAccountFormValues = {
'financial-priorities': boolean;
Expand Down Expand Up @@ -250,7 +250,7 @@ export type TAutoComplete = {
value: boolean;
text: string;
};
export type TPaymentMethodIdentifier = typeof IDENTIFIER_TYPES[keyof typeof IDENTIFIER_TYPES];
export type TPaymentMethodIdentifier = (typeof IDENTIFIER_TYPES)[keyof typeof IDENTIFIER_TYPES];

export type TPaymentMethodInfo = {
documents_required: number;
Expand Down Expand Up @@ -285,11 +285,11 @@ export type TProofOfOwnershipErrors = Record<

export type TFinancialInformationForm = Omit<SetFinancialAssessmentRequest, 'set_financial_assessment'>;

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

export type TMT5AccountStatus =
| typeof MT5_ACCOUNT_STATUS[keyof typeof MT5_ACCOUNT_STATUS]
| typeof TRADING_PLATFORM_STATUS[keyof typeof TRADING_PLATFORM_STATUS];
| (typeof MT5_ACCOUNT_STATUS)[keyof typeof MT5_ACCOUNT_STATUS]
| (typeof TRADING_PLATFORM_STATUS)[keyof typeof TRADING_PLATFORM_STATUS];

export type TFilesDescription = {
descriptions: { id: string; value: JSX.Element }[];
Expand Down Expand Up @@ -343,6 +343,7 @@ export type TEmployeeDetailsTinValidationConfig = {
is_real?: boolean;
is_tin_auto_set?: boolean;
is_duplicate_account?: boolean;
is_employment_status_tin_mandatory?: boolean;
};

type ReqRule = ['req', React.ReactNode];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,13 @@ const Virtual = observer(() => {
i18n_default_text='You need to switch to a real money account to use this feature.<0/>You can do this by selecting a real account from the <1>Account Switcher.</1>'
components={[
<br key={0} />,
<span key={1} className='virtual__account-switch-text' onClick={toggleAccountsDialog} />,
<span
key={1}
className='virtual__account-switch-text'
onClick={() => {
toggleAccountsDialog();
}}
/>,
]}
/>
</Text>
Expand Down
3 changes: 0 additions & 3 deletions packages/core/build/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,6 @@ const copyConfig = base => {
{
from: path.resolve(__dirname, '../../../node_modules/@deriv/cashier/dist/cashier/public'),
to: 'cashier/public',
transform(_content, transform_path) {
return transform_path.split('node_modules/@deriv/cashier/dist/')[1];
},
},
{
from: path.resolve(__dirname, '../../../node_modules/@deriv/trader/dist/trader'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe('AccountInfoWallets component', () => {
},
};

it('should show "disabled_message" when "is_disabled" property is "true"', () => {
it('should show "disabled_message" when "is_disabled" property is "true"', async () => {
const mock = mockStore({
client: {
accounts: {
Expand Down Expand Up @@ -64,7 +64,7 @@ describe('AccountInfoWallets component', () => {
render(<AccountInfoWallets is_dialog_on={false} toggleDialog={toggleDialog} />, { wrapper: wrapper(mock) });

const popover = screen.getByTestId('dt_popover_wrapper');
userEvent.hover(popover);
await userEvent.hover(popover);
const disabled_message = screen.getByText(/test disabled message/i);
expect(disabled_message).toBeInTheDocument();
});
Expand Down Expand Up @@ -108,7 +108,7 @@ describe('AccountInfoWallets component', () => {
expect(div_element).not.toHaveClass('acc-info--show');
});

it('can not "toggleDialog" when "is_disabled" property is "true"', () => {
it('can not "toggleDialog" when "is_disabled" property is "true"', async () => {
const mock = mockStore({
client: {
accounts: {
Expand All @@ -134,7 +134,7 @@ describe('AccountInfoWallets component', () => {
render(<AccountInfoWallets is_dialog_on={false} toggleDialog={toggleDialog} />, { wrapper: wrapper(mock) });

const div_element = screen.getByTestId('dt_acc_info');
userEvent.click(div_element);
await userEvent.click(div_element);
expect(toggleDialog).toHaveBeenCalledTimes(0);
});

Expand Down Expand Up @@ -185,35 +185,6 @@ describe('AccountInfoWallets component', () => {
expect(screen.queryByText('SVG')).not.toBeInTheDocument();
});

it('should render "MALTA" label', () => {
const mock = mockStore({
client: {
accounts: {
CRW909900: {
account_category: 'wallet',
currency: 'USD',
is_virtual: 0,
is_disabled: 0,
landing_company_name: 'maltainvest',
linked_to: [{ loginid: 'CR123', platform: 'dtrade' }],
},
CR123: {
account_category: 'trading',
currency: 'USD',
is_virtual: 0,
is_disabled: 0,
},
},
loginid: 'CR123',
},
});

const toggleDialog = jest.fn();
render(<AccountInfoWallets is_dialog_on={false} toggleDialog={toggleDialog} />, { wrapper: wrapper(mock) });

expect(screen.queryByText('MALTA')).toBeInTheDocument();
});

it('should render "IcLock" icon when "is_disabled" property is "true"', () => {
const mock = mockStore({
client: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ const AccountInfoWallets = observer(({ is_dialog_on, toggleDialog }: TAccountInf

if (!linked_wallet) return <AccountsInfoLoader is_logged_in={is_logged_in} is_mobile={!isDesktop} speed={3} />;

const show_badge = linked_wallet.is_malta_wallet || linked_wallet.is_virtual;
const show_badge = linked_wallet.is_virtual;

return (
<div className='acc-info__wrapper'>
Expand Down
Loading

0 comments on commit c666325

Please sign in to comment.