Skip to content

Commit

Permalink
Merge branch 'master' of github.com:binary-com/deriv-app into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
jim-deriv committed Feb 28, 2023
2 parents 8a1a960 + ad4c71a commit f1d0f3a
Show file tree
Hide file tree
Showing 32 changed files with 960 additions and 854 deletions.
4 changes: 2 additions & 2 deletions packages/account/src/Components/hooks/useToggleValidation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import React from 'react';

export const useToggleValidation = (hash: string) => {
const [is_validation_enabled, setIsValidationEnabled] = React.useState(false);
const { is_deriv_app } = getPlatformFromUrl();
const { is_staging_deriv_app } = getPlatformFromUrl();

React.useEffect(() => {
// This effect allows to toggle IDV validation
// for repetitive and sequential numbers
if (is_deriv_app || (hash && hash === '#toggle_id_validation')) {
if (!is_staging_deriv_app || (hash && hash === '#toggle_id_validation')) {
setIsValidationEnabled(true);
} else {
setIsValidationEnabled(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@ import { Autocomplete, Button, DesktopWrapper, Input, MobileWrapper, Text, Selec
import { Formik, Field } from 'formik';
import { localize, Localize } from '@deriv/translations';
import { formatInput, WS } from '@deriv/shared';
import { isSequentialNumber, isRecurringNumberRegex, getDocumentData, getRegex } from './utils';
import {
isSequentialNumber,
isRecurringNumberRegex,
getDocumentData,
getRegex,
preventEmptyClipboardPaste,
} from './utils';
import { useToggleValidation } from '../../hooks/useToggleValidation';
import FormFooter from 'Components/form-footer';
import BackButtonIcon from 'Assets/ic-poi-back-btn.svg';
Expand Down Expand Up @@ -96,7 +102,10 @@ const IdvDocumentSubmit = ({ handleBack, handleViewComplete, selected_country, i
if (!document_number) {
errors.document_number =
localize('Please enter your document number. ') + getExampleFormat(document_type.example_format);
} else if (validation_is_enabled && (is_recurring_number || is_sequential_number)) {
} else if (
(validation_is_enabled && (is_recurring_number || is_sequential_number)) ||
document_number === document_type.example_format
) {
errors.document_number = localize('Please enter a valid ID number.');
} else {
const format_regex = getRegex(document_type.value);
Expand Down Expand Up @@ -238,7 +247,7 @@ const IdvDocumentSubmit = ({ handleBack, handleViewComplete, selected_country, i
autoComplete='off'
placeholder='Enter your document number'
value={values.document_number}
onPaste={e => e.preventDefault()}
onPaste={preventEmptyClipboardPaste}
onBlur={handleBlur}
onChange={handleChange}
onKeyUp={e => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ export const getDocumentData = (country_code, document_type) => {

const getImageLocation = image_name => getUrlBase(`/public/images/common/${image_name}`);

export const preventEmptyClipboardPaste = e => {
const clipboardData = (e.clipboardData || window.clipboardData).getData('text');
if (clipboardData.length === 0) {
e.preventDefault();
}
};

// Unsupported Regex List
const regex = [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,13 @@ import {
ThemedScrollbars,
} from '@deriv/components';
import { isDesktop, formatInput, isMobile } from '@deriv/shared';
import { getDocumentData, getRegex, isSequentialNumber, isRecurringNumberRegex } from '../../idv-document-submit/utils';
import {
getDocumentData,
getRegex,
isSequentialNumber,
isRecurringNumberRegex,
preventEmptyClipboardPaste,
} from '../../idv-document-submit/utils';
import { useToggleValidation } from '../../../hooks/useToggleValidation';
import DocumentSubmitLogo from 'Assets/ic-document-submit-icon.svg';

Expand Down Expand Up @@ -88,7 +94,10 @@ export const IdvDocSubmitOnSignup = ({ citizen_data, has_previous, onPrevious, o
if (!document_number) {
errors.document_number =
localize('Please enter your document number. ') + getExampleFormat(document_type.example_format);
} else if (validation_is_enabled && (is_recurring_number || is_sequential_number)) {
} else if (
(validation_is_enabled && (is_recurring_number || is_sequential_number)) ||
document_number === document_type.example_format
) {
errors.document_number = localize('Please enter a valid ID number.');
} else {
const format_regex = getRegex(document_type.value);
Expand Down Expand Up @@ -295,7 +304,7 @@ export const IdvDocSubmitOnSignup = ({ citizen_data, has_previous, onPrevious, o
autoComplete='off'
placeholder='Enter your document number'
value={values.document_number}
onPaste={e => e.preventDefault()}
onPaste={preventEmptyClipboardPaste}
onBlur={handleBlur}
onChange={handleChange}
onKeyUp={e => {
Expand Down
6 changes: 5 additions & 1 deletion packages/appstore/src/components/CFDs/cfd-accounts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,11 @@ const CFDAccounts = ({ account_type }: TCFDAccountsProps) => {
{!is_demo_tab && (
<div className='cfd-accounts-container__compare-accounts' onClick={toggleCompareAccountsModal}>
<Text weight='bold' size='xxs' color='red'>
<Localize i18n_default_text={is_eu ? 'Account Information' : 'Compare accounts'} />
{is_eu ? (
<Localize i18n_default_text='Account Information' />
) : (
<Localize i18n_default_text='Compare accounts' />
)}
</Text>
</div>
)}
Expand Down
11 changes: 7 additions & 4 deletions packages/appstore/src/components/CFDs/cfd-demo-accounts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@ import { DetailsOfEachMT5Loginid } from '@deriv/api-types';
const CFDDemoAccounts = ({ isDerivedVisible, isFinancialVisible, current_list }: TCFDAccountsProps) => {
const { client, modules, common, ui }: TRootStore = useStores();
const { is_eu } = client;
const account_name = is_eu ? 'CFDs' : 'Financial';
const account_name = is_eu ? localize('CFDs') : localize('Financial');
const account_desc = is_eu
? 'Trade CFDs on MT5 with forex, stocks, stock indices, synthetics, cryptocurrencies, and commodities.'
: 'Trade CFDs on MT5 with forex, stocks, stock indices, commodities, and cryptocurrencies.';
? localize(
'Trade CFDs on MT5 with forex, stocks, stock indices, synthetics, cryptocurrencies, and commodities.'
)
: localize('Trade CFDs on MT5 with forex, stocks, stock indices, commodities, and cryptocurrencies.');

const available_demo_accounts: TStaticAccountProps[] = [
{
name: 'Derived',
Expand All @@ -24,7 +27,7 @@ const CFDDemoAccounts = ({ isDerivedVisible, isFinancialVisible, current_list }:
},
{
name: account_name,
description: localize(account_desc),
description: account_desc,
is_visible: isFinancialVisible(CFD_PLATFORMS.MT5),
disabled: false,
platform: CFD_PLATFORMS.MT5,
Expand Down
33 changes: 9 additions & 24 deletions packages/appstore/src/components/CFDs/cfd-real-accounts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,12 @@ const CFDRealAccounts = ({
const { setAppstorePlatform, platform } = common;
const { isEligibleForMoreRealMt5, is_eu } = client;
const history = useHistory();
const account_name = is_eu ? 'CFDs' : 'Financial';
const account_name = is_eu ? localize('CFDs') : localize('Financial');
const account_desc = is_eu
? 'Trade CFDs on MT5 with forex, stocks, stock indices, synthetics, cryptocurrencies, and commodities.'
: 'Trade CFDs on MT5 with forex, stocks, stock indices, commodities, and cryptocurrencies.';
? localize(
'Trade CFDs on MT5 with forex, stocks, stock indices, synthetics, cryptocurrencies, and commodities.'
)
: localize('Trade CFDs on MT5 with forex, stocks, stock indices, commodities, and cryptocurrencies.');
const available_real_accounts: TStaticAccountProps[] = [
{
name: 'Derived',
Expand All @@ -51,7 +53,7 @@ const CFDRealAccounts = ({
},
{
name: account_name,
description: localize(account_desc),
description: account_desc,
is_visible: isFinancialVisible(CFD_PLATFORMS.MT5),
disabled: has_cfd_account_error(CFD_PLATFORMS.MT5),
platform: CFD_PLATFORMS.MT5,
Expand Down Expand Up @@ -79,10 +81,7 @@ const CFDRealAccounts = ({
return url;
};

const openAccountTransfer = (
data: DetailsOfEachMT5Loginid & { account_id?: string; platform?: string },
meta: { category: string; type?: string }
) => {
const openAccountTransfer = (data: DetailsOfEachMT5Loginid & { account_id?: string; platform?: string }) => {
if (data.platform === CFD_PLATFORMS.DXTRADE)
sessionStorage.setItem('cfd_transfer_to_login_id', data.account_id as string);
else sessionStorage.setItem('cfd_transfer_to_login_id', data.login as string);
Expand All @@ -93,23 +92,9 @@ const CFDRealAccounts = ({

const onClickFundReal = (account: DetailsOfEachMT5Loginid) => {
if (platform === 'dxtrade') {
return openAccountTransfer(current_list[getAccountListKey(account, platform)], {
category: account.account_type as keyof TOpenAccountTransferMeta,
type: getCFDAccountKey({
market_type: account.market_type,
sub_account_type: account.sub_account_type,
platform,
}),
});
return openAccountTransfer(current_list[getAccountListKey(account, platform)]);
}
return openAccountTransfer(account, {
category: account.account_type as keyof TOpenAccountTransferMeta,
type: getCFDAccountKey({
market_type: account.market_type,
sub_account_type: account.sub_account_type,
platform: CFD_PLATFORMS.MT5,
}),
});
return openAccountTransfer(account);
};

const OnClickGetAccount = (account: TStaticAccountProps) => {
Expand Down
37 changes: 34 additions & 3 deletions packages/appstore/src/components/main-title-bar/asset-summary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import './asset-summary.scss';
import TotalAssetsLoader from 'Components/pre-loader/total-assets-loader';

const AssetSummary = () => {
const { traders_hub, client } = useStores();
const { traders_hub, client, common } = useStores();
const {
selected_account_type,
platform_real_balance,
Expand All @@ -21,17 +21,48 @@ const AssetSummary = () => {
no_MF_account,
} = traders_hub;
const { is_logging_in, is_switching } = client;
const { getExchangeRate } = common;

const [exchanged_rate_cfd_real, setExchangedRateCfdReal] = React.useState(1);
const [exchanged_rate_cfd_demo, setExchangedRateCfdDemo] = React.useState(1);

React.useEffect(() => {
const getCurrentExchangeRate = (
currency: string,
setExchangeRate: React.Dispatch<React.SetStateAction<number>>,
base_currency = platform_real_balance.currency
) => {
if (currency) {
getExchangeRate(currency, base_currency).then((res: number) => {
setExchangeRate(res);
});
}
};

if (cfd_real_balance.currency !== platform_real_balance.currency) {
getCurrentExchangeRate(cfd_real_balance.currency, setExchangedRateCfdReal);
}
if (cfd_demo_balance.currency !== platform_demo_balance.currency) {
getCurrentExchangeRate(cfd_demo_balance.currency, setExchangedRateCfdDemo, platform_demo_balance.currency);
}
}, [
cfd_demo_balance.currency,
cfd_real_balance.currency,
getExchangeRate,
platform_demo_balance.currency,
platform_real_balance.currency,
]);

const getTotalBalance = () => {
if (selected_account_type === 'real') {
return {
balance: platform_real_balance.balance + cfd_real_balance.balance,
balance: platform_real_balance.balance + cfd_real_balance.balance * exchanged_rate_cfd_real,
currency: platform_real_balance.currency,
};
}

return {
balance: platform_demo_balance.balance + cfd_demo_balance.balance,
balance: platform_demo_balance.balance + cfd_demo_balance.balance * exchanged_rate_cfd_demo,
currency: platform_demo_balance.currency,
};
};
Expand Down
2 changes: 1 addition & 1 deletion packages/appstore/src/components/main-title-bar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ const MainTitleBar = () => {
</Tabs>
</>
) : (
<div className='main-title-bar-mobile--regulator__container loader'>
<div className='main-title-bar-mobile--regulator__container content-loader'>
<RegulationsSwitcherLoader />
</div>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
justify-content: flex-end;
width: 14rem;

&__container.loader {
&__container.content-loader {
width: 100%;
height: 100%;
padding: 0;
Expand Down
Loading

0 comments on commit f1d0f3a

Please sign in to comment.