Skip to content

Commit

Permalink
Matin/[BL-396]/Removal of country-level business logic (#14743)
Browse files Browse the repository at this point in the history
* chore: initial commit

* fix: failed tests

* chore: removal of useAccountTransferVisible

* fix: test cases

* chore: revert back some changes

* chore: review comments

* chore: Remove country-level business logic

* chore: remove is_uk flag

* chore: empty commit
  • Loading branch information
matin-deriv committed May 13, 2024
1 parent 49dc9ae commit cc2a418
Show file tree
Hide file tree
Showing 26 changed files with 24 additions and 189 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ describe('<SelfExclusionArticle />', () => {
let mock_self_exclusion_context = {
is_app_settings: false,
is_eu: false,
is_uk: false,
currency: '',
overlay_ref: document.createElement('div'),
toggleArticle: jest.fn(),
Expand All @@ -39,7 +38,6 @@ describe('<SelfExclusionArticle />', () => {
mock_self_exclusion_context = {
is_app_settings: false,
is_eu: false,
is_uk: false,
currency: '',
overlay_ref: document.createElement('div'),
toggleArticle: jest.fn(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ describe('<SelfExclusionConfirmPage />', () => {
is_app_settings: false,
is_wrapper_bypassed: false,
toggleArticle: jest.fn(),
is_uk: false,
handleSubmit: jest.fn(),
validateFields: jest.fn(),
};
Expand All @@ -49,7 +48,6 @@ describe('<SelfExclusionConfirmPage />', () => {
is_app_settings: false,
is_wrapper_bypassed: false,
toggleArticle: jest.fn(),
is_uk: false,
handleSubmit: jest.fn(),
validateFields: jest.fn(),
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ import { Localize, localize } from '@deriv/translations';
import { Button, Icon, OpenLiveChatLink, Popup, Text } from '@deriv/components';
import SelfExclusionContext from './self-exclusion-context';

type TSelfExclusionArticleItems = Record<
'is_eu' | 'is_uk' | 'is_deriv_crypto' | 'is_app_settings',
boolean | undefined
>;
type TSelfExclusionArticleItems = Record<'is_eu' | 'is_deriv_crypto' | 'is_app_settings', boolean | undefined>;

type TSelfExclusionArticleContent = {
is_in_overlay: boolean;
Expand Down Expand Up @@ -123,10 +120,10 @@ export const selfExclusionArticleItems = ({ is_eu, is_deriv_crypto, is_app_setti
};

const SelfExclusionArticleContent = ({ is_in_overlay }: Partial<TSelfExclusionArticleContent>) => {
const { is_app_settings, toggleArticle, overlay_ref, is_eu, is_uk } = React.useContext(SelfExclusionContext);
const { is_app_settings, toggleArticle, overlay_ref, is_eu } = React.useContext(SelfExclusionContext);
const { is_deriv_crypto } = React.useContext(PlatformContext);

const keyed_article_items = selfExclusionArticleItems({ is_eu, is_uk, is_deriv_crypto, is_app_settings });
const keyed_article_items = selfExclusionArticleItems({ is_eu, is_deriv_crypto, is_app_settings });
if (is_in_overlay) {
return (
<Popup.Overlay
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ export type TSelfExclusionContext = {
is_appstore?: boolean;
is_app_settings?: boolean;
is_eu?: boolean;
is_uk?: boolean;
is_mf?: boolean;
is_tablet?: boolean;
is_wrapper_bypassed?: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ const mock = {
standpoint: {
svg: false,
},
is_uk: false,
is_virtual: false,
is_switching: false,
landing_company_shortcode: '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ type TResponse = {

const SelfExclusion = observer(({ is_app_settings, overlay_ref, setIsOverlayShown }: TSelfExclusion) => {
const { client, ui } = useStore();
const { currency, is_virtual, is_switching, standpoint, is_eu, is_uk, logout, landing_company_shortcode } = client;
const { currency, is_virtual, is_switching, standpoint, is_eu, logout, landing_company_shortcode } = client;
const { is_tablet } = ui;
const is_wrapper_bypassed = false;
const is_mf = landing_company_shortcode === 'maltainvest';
Expand Down Expand Up @@ -440,7 +440,6 @@ const SelfExclusion = observer(({ is_app_settings, overlay_ref, setIsOverlayShow
is_eu,
is_mf,
is_tablet,
is_uk,
is_wrapper_bypassed,
objectValuesToString,
overlay_ref,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,4 @@ describe('AccountInfo component', () => {
expect(text).toBeInTheDocument();
expect(screen.queryByText(/no currency assigned/i)).not.toBeInTheDocument();
});

it('should render proper "AccountType" base on the passed properties', () => {
const { rerender } = render(<AccountInfo account_type='financial' />);
expect(screen.getByText(/multipliers/i)).toBeInTheDocument();

rerender(<AccountInfo account_type='gaming' country_standpoint={{ is_united_kingdom: true }} />);
expect(screen.getByText(/gaming/i)).toBeInTheDocument();

rerender(<AccountInfo account_type='gaming' country_standpoint={{ is_belgium: true }} />);
expect(screen.getByText(/options/i)).toBeInTheDocument();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,7 @@ import DisplayAccountType from '../display-account-type';

describe('DisplayAccountType component', () => {
it('should render "Multipliers"', () => {
render(<DisplayAccountType account_type='financial' country_standpoint={{}} is_eu={false} />);
render(<DisplayAccountType account_type='financial' is_eu={false} />);
expect(screen.getByText(/multipliers/i)).toBeInTheDocument();
});

it('should render "Gaming" if is_united_kingdom = true', () => {
render(
<DisplayAccountType account_type='gaming' country_standpoint={{ is_united_kingdom: true }} is_eu={false} />
);
expect(screen.getByText(/gaming/i)).toBeInTheDocument();
});

it('should render "Options" for Belgium', () => {
render(<DisplayAccountType account_type='gaming' country_standpoint={{ is_belgium: true }} is_eu={true} />);
expect(screen.getByText(/options/i)).toBeInTheDocument();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ const AccountActions = React.memo(
account_type,
balance,
currency,
country_standpoint,
disableApp,
enableApp,
is_acc_switcher_on,
Expand Down Expand Up @@ -63,7 +62,6 @@ const AccountActions = React.memo(
is_virtual={is_virtual}
is_mobile
currency={currency}
country_standpoint={country_standpoint}
is_dialog_on={is_acc_switcher_on}
toggleDialog={toggleAccountsDialog}
/>
Expand Down Expand Up @@ -99,7 +97,6 @@ const AccountActions = React.memo(
is_eu={is_eu}
is_virtual={is_virtual}
currency={currency}
country_standpoint={country_standpoint}
is_dialog_on={is_acc_switcher_on}
toggleDialog={toggleAccountsDialog}
/>
Expand Down Expand Up @@ -148,7 +145,6 @@ AccountActions.propTypes = {
is_eu: PropTypes.bool,
disableApp: PropTypes.any,
enableApp: PropTypes.any,
country_standpoint: PropTypes.object,
is_acc_switcher_on: PropTypes.any,
is_logged_in: PropTypes.any,
is_notifications_visible: PropTypes.any,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ const AccountInfo = ({
account_type = '',
balance,
currency,
country_standpoint,
disableApp,
enableApp,
is_dialog_on,
Expand Down Expand Up @@ -71,11 +70,7 @@ const AccountInfo = ({
)}
</p>
<Text size='xxxs' line_height='s'>
<DisplayAccountType
account_type={account_type}
country_standpoint={country_standpoint}
is_eu={is_eu}
/>
<DisplayAccountType account_type={account_type} is_eu={is_eu} />
</Text>
</div>
)}
Expand Down Expand Up @@ -123,7 +118,6 @@ AccountInfo.propTypes = {
account_type: PropTypes.string,
balance: PropTypes.string,
currency: PropTypes.string,
country_standpoint: PropTypes.object,
disableApp: PropTypes.func,
enableApp: PropTypes.func,
is_dialog_on: PropTypes.bool,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,14 @@ import { Localize } from '@deriv/translations';

type TDisplayAccountType = {
account_type: string;
country_standpoint: {
is_united_kingdom?: boolean;
is_belgium?: boolean;
};
is_eu: boolean;
};

const DisplayAccountType = ({ account_type, country_standpoint, is_eu }: TDisplayAccountType) => {
const DisplayAccountType = ({ account_type, is_eu }: TDisplayAccountType) => {
if (account_type === 'financial') {
return <Localize i18n_default_text='Multipliers' />;
} else if (account_type === 'gaming') {
if (country_standpoint.is_united_kingdom) {
return <Localize i18n_default_text='Gaming' />;
}
if (is_eu || country_standpoint.is_belgium) {
if (is_eu) {
return <Localize i18n_default_text='Options' />;
}
return <Localize i18n_default_text='Derived' />;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ let store = mockStore({
},
],
residence: 'id',
country_standpoint: { is_united_kingdom: true },
is_eu: false,
is_landing_company_loaded: true,
is_low_risk: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ const AccountList = ({
balance,
currency,
currency_icon,
country_standpoint,
display_type,
has_balance,
has_error,
Expand Down Expand Up @@ -49,12 +48,7 @@ const AccountList = ({
/>
<span>
{display_type === 'currency' ? (
<CurrencyDisplay
country_standpoint={country_standpoint}
currency={currency}
loginid={loginid}
is_virtual={is_virtual}
/>
<CurrencyDisplay currency={currency} loginid={loginid} is_virtual={is_virtual} />
) : (
<AccountDisplay
is_eu={is_eu}
Expand Down Expand Up @@ -114,14 +108,11 @@ const AccountList = ({
);
};

const CurrencyDisplay = ({ country_standpoint, currency, loginid, is_virtual }) => {
const user_is_from_this_country_list = Object.values(country_standpoint).includes(true);
const CurrencyDisplay = ({ currency, loginid, is_virtual }) => {
const account_type = loginid.replace(/\d/g, '');

if (user_is_from_this_country_list) {
if (account_type === 'MF') {
return <Localize i18n_default_text='Multipliers' />;
}
if (account_type === 'MF') {
return <Localize i18n_default_text='Multipliers' />;
}

if (is_virtual) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ const AccountSwitcher = observer(({ history, is_mobile, is_visible }) => {
accounts,
account_type,
account_list,
country_standpoint,
currency,
is_eu,
is_landing_company_loaded,
Expand Down Expand Up @@ -222,7 +221,6 @@ const AccountSwitcher = observer(({ history, is_mobile, is_visible }) => {
balance={accounts[account.loginid].balance}
currency={accounts[account.loginid].currency}
currency_icon={`IcCurrency-${account.icon}`}
country_standpoint={country_standpoint}
display_type={'currency'}
has_balance={'balance' in accounts[account.loginid]}
has_reset_balance={canResetBalance(accounts[account_loginid])}
Expand Down Expand Up @@ -269,7 +267,6 @@ const AccountSwitcher = observer(({ history, is_mobile, is_visible }) => {
balance={accounts[account.loginid].balance}
currency={accounts[account.loginid].currency}
currency_icon={`IcCurrency-${account.icon}`}
country_standpoint={country_standpoint}
display_type={'currency'}
has_balance={'balance' in accounts[account.loginid]}
is_disabled={account.is_disabled}
Expand Down Expand Up @@ -341,7 +338,6 @@ const AccountSwitcher = observer(({ history, is_mobile, is_visible }) => {
balance={accounts[account.loginid].balance}
currency={accounts[account.loginid].currency}
currency_icon={`IcCurrency-${account.icon}`}
country_standpoint={country_standpoint}
display_type={'currency'}
has_balance={'balance' in accounts[account.loginid]}
is_disabled={account.is_disabled}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ const DefaultHeaderWallets = () => {
account_type,
balance,
currency,
country_standpoint,
is_bot_allowed,
is_eu,
is_logged_in,
Expand Down Expand Up @@ -144,7 +143,6 @@ const DefaultHeaderWallets = () => {
account_type={account_type}
balance={balance}
currency={currency}
country_standpoint={country_standpoint}
disableApp={disableApp}
enableApp={enableApp}
is_acc_switcher_on={is_acc_switcher_on}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ type THeaderAccountActions = {

const HeaderAccountActions = observer(({ onClickDeposit }: THeaderAccountActions) => {
const { client, ui, notifications } = useStore();
const { account_type, balance, currency, country_standpoint, is_eu, is_logged_in, is_virtual } = client;
const { account_type, balance, currency, is_eu, is_logged_in, is_virtual } = client;
const {
account_switcher_disabled_message,
disableApp,
Expand All @@ -27,7 +27,6 @@ const HeaderAccountActions = observer(({ onClickDeposit }: THeaderAccountActions
account_type={account_type}
balance={balance}
currency={currency}
country_standpoint={country_standpoint}
disableApp={disableApp}
enableApp={enableApp}
is_acc_switcher_on={is_accounts_switcher_on}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,8 @@ type TPlatforms = typeof platforms;

const TradersHubHeaderWallets = observer(() => {
const { client, common, traders_hub, ui } = useStore();
const {
account_type,
balance,
country_standpoint,
currency,
has_any_real_account,
is_eu,
is_logged_in,
is_mt5_allowed,
is_virtual,
} = client;
const { account_type, balance, currency, has_any_real_account, is_eu, is_logged_in, is_mt5_allowed, is_virtual } =
client;
const { platform } = common;
const { modal_data } = traders_hub;
const {
Expand Down Expand Up @@ -139,7 +130,6 @@ const TradersHubHeaderWallets = observer(() => {
acc_switcher_disabled_message={account_switcher_disabled_message}
account_type={account_type}
balance={account_balance}
country_standpoint={country_standpoint}
currency={currency}
is_dialog_on={is_accounts_switcher_on}
is_disabled={false}
Expand All @@ -166,7 +156,6 @@ const TradersHubHeaderWallets = observer(() => {
acc_switcher_disabled_message={account_switcher_disabled_message}
account_type={account_type}
balance={account_balance}
country_standpoint={country_standpoint}
currency={currency}
is_dialog_on={is_accounts_switcher_on}
is_disabled={false}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,8 @@ const CurrencySelectionModal = makeLazyLoader(

const TradersHubHeader = observer(() => {
const { client, common, traders_hub, ui } = useStore();
const {
account_type,
balance,
country_standpoint,
currency,
has_any_real_account,
is_eu,
is_logged_in,
is_mt5_allowed,
is_virtual,
} = client;
const { account_type, balance, currency, has_any_real_account, is_eu, is_logged_in, is_mt5_allowed, is_virtual } =
client;
const { platform } = common;
const { modal_data } = traders_hub;
const {
Expand Down Expand Up @@ -172,7 +163,6 @@ const TradersHubHeader = observer(() => {
acc_switcher_disabled_message={account_switcher_disabled_message}
account_type={account_type}
balance={account_balance}
country_standpoint={country_standpoint}
currency={currency}
is_dialog_on={is_accounts_switcher_on}
is_disabled={false}
Expand Down Expand Up @@ -201,7 +191,6 @@ const TradersHubHeader = observer(() => {
acc_switcher_disabled_message={account_switcher_disabled_message}
account_type={account_type}
balance={account_balance}
country_standpoint={country_standpoint}
currency={currency}
is_dialog_on={is_accounts_switcher_on}
is_disabled={false}
Expand Down
Loading

0 comments on commit cc2a418

Please sign in to comment.