Skip to content

Commit

Permalink
chore: Remove country-level business logic
Browse files Browse the repository at this point in the history
  • Loading branch information
matin-deriv committed May 6, 2024
1 parent 654ca28 commit f176b0d
Show file tree
Hide file tree
Showing 19 changed files with 17 additions and 145 deletions.
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 @@ -25,17 +25,8 @@ type TPlatforms = typeof platforms;

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 @@ -140,7 +131,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 @@ -169,7 +159,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
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ describe('<RealAccountSignup />', () => {
const store = mockStore({
client: {
available_crypto_currencies: [],
country_standpoint: '',
currency: 'USD',
fetchAccountSettings: jest.fn(),
residence: 'gb',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,13 @@ export const getAccountTitle = landing_company_shortcode => {

/**
* @param {string} landing_company_shortcode
* @param {boolean} is_belgium_residence,
*
* @return {EXPERIAN.WARN|EXPERIAN.SUCCESS|EXPERIAN.DANGER}
*/
export const getExperianResult = status => {
const { landing_company_shortcode = '', is_belgium_residence = false } = status;
const { landing_company_shortcode = '' } = status;

if (landing_company_shortcode === 'svg' || is_belgium_residence) return EXPERIAN.SUCCESS;
if (landing_company_shortcode === 'svg') return EXPERIAN.SUCCESS;

return EXPERIAN.SUCCESS;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const modal_pages_indices = {
};
let active_modal_index_no = 0;

const WizardHeading = ({ country_standpoint, currency, real_account_signup_target }) => {
const WizardHeading = ({ currency, real_account_signup_target }) => {
const maltainvest_signup = real_account_signup_target === 'maltainvest';
const deposit_cash_signup = real_account_signup_target === 'deposit_cash';

Expand All @@ -53,10 +53,7 @@ const WizardHeading = ({ country_standpoint, currency, real_account_signup_targe

switch (real_account_signup_target) {
case 'maltainvest':
if (country_standpoint.is_france || country_standpoint.is_other_eu || country_standpoint.is_rest_of_eu) {
return <Localize i18n_default_text='Setup your account' />;
}
return <Localize i18n_default_text='Add a Deriv Financial account' />;
return <Localize i18n_default_text='Setup your account' />;
default:
return <Localize i18n_default_text='Add a Deriv account' />;
}
Expand All @@ -66,7 +63,6 @@ const RealAccountSignup = observer(({ history, state_index, is_trading_experienc
const { ui, client, traders_hub, modules } = useStore();
const {
available_crypto_currencies,
country_standpoint,
currency,
fetchAccountSettings,
has_fiat,
Expand Down Expand Up @@ -95,7 +91,6 @@ const RealAccountSignup = observer(({ history, state_index, is_trading_experienc
const deposit_target = modules.cashier.general_store.deposit_target;
const setIsDeposit = modules.cashier.general_store.setIsDeposit;
const should_show_all_available_currencies = modules.cashier.general_store.should_show_all_available_currencies;
const is_belgium_residence = client.residence === 'be'; // TODO: [deriv-eu] refactor this once more residence checks are required
const [current_action, setCurrentAction] = React.useState(null);
const [is_loading, setIsLoading] = React.useState(false);
const [error, setError] = React.useState(null);
Expand Down Expand Up @@ -631,10 +626,8 @@ const RealAccountSignup = observer(({ history, state_index, is_trading_experienc
return (
<Title
available_crypto_currencies={available_crypto_currencies}
country_standpoint={country_standpoint}
currency={currency}
has_fiat={has_fiat}
is_belgium_residence={is_belgium_residence}
is_eu={show_eu_related_content}
real_account_signup_target={real_account_signup_target}
should_show_all_available_currencies={should_show_all_available_currencies}
Expand Down Expand Up @@ -669,9 +662,7 @@ const RealAccountSignup = observer(({ history, state_index, is_trading_experienc
if (Title) {
return (
<Title
country_standpoint={country_standpoint}
currency={currency}
is_belgium_residence={is_belgium_residence}
real_account_signup_target={real_account_signup_target}
should_show_all_available_currencies={should_show_all_available_currencies}
/>
Expand Down
Loading

0 comments on commit f176b0d

Please sign in to comment.