Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

thisyahlen/chore: real account needed for cashier popup #8029

Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
5f19142
chore: real account needed for cashier popup
thisyahlen-deriv Mar 27, 2023
ade2729
Merge branch 'master' of github.com:binary-com/deriv-app into thisyah…
thisyahlen-deriv Mar 27, 2023
144b314
Merge branch 'master' into thisyahlen/91782/real_account_needed_for_c…
thisyahlen-deriv Mar 27, 2023
541a357
fix: add new mobx to mockstore
thisyahlen-deriv Mar 27, 2023
b84874c
Merge branch 'thisyahlen/91782/real_account_needed_for_cashier_popup'…
thisyahlen-deriv Mar 27, 2023
31c0046
fix: move dem all to stores
thisyahlen-deriv Mar 27, 2023
202f006
fix: switch region
thisyahlen-deriv Mar 27, 2023
1161e7c
fix: add in mockstore
thisyahlen-deriv Mar 27, 2023
d7f637c
Merge branch 'master' of github.com:binary-com/deriv-app into thisyah…
thisyahlen-deriv Mar 27, 2023
948fba0
Merge branch 'master' into thisyahlen/91782/real_account_needed_for_c…
thisyahlen-deriv Mar 27, 2023
4a3539e
fix: add tests and resolve comments
thisyahlen-deriv Mar 27, 2023
0eeb65a
Merge branch 'thisyahlen/91782/real_account_needed_for_cashier_popup'…
thisyahlen-deriv Mar 27, 2023
4afc426
fix: use mockstore in tests
thisyahlen-deriv Mar 27, 2023
877634f
Merge branch 'master' of github.com:binary-com/deriv-app into thisyah…
thisyahlen-deriv Mar 30, 2023
88beae3
fix: add for responsive
thisyahlen-deriv Mar 30, 2023
2b0dab1
Merge branch 'master' of github.com:binary-com/deriv-app into thisyah…
thisyahlen-deriv Mar 30, 2023
7dcf713
Merge branch 'master' into thisyahlen/91782/real_account_needed_for_c…
thisyahlen-deriv Apr 4, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions packages/core/src/App/Components/Layout/Header/menu-links.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { BinaryLink } from '../../Routes';
import { observer, useStore } from '@deriv/stores';
import { routes } from '@deriv/shared';
import { localize } from '@deriv/translations';
import { useP2PNotificationCount } from '@deriv/hooks';
import { useP2PNotificationCount, useRealAccountNeededForCashier } from '@deriv/hooks';
import './menu-links.scss';
import { useHistory } from 'react-router';

Expand Down Expand Up @@ -38,8 +38,9 @@ const ReportTab = () => (
const CashierTab = observer(() => {
const { client, ui } = useStore();
const { has_any_real_account, is_virtual } = client;
const { toggleReadyToDepositModal } = ui;
const { toggleReadyToDepositModal, toggleNeedRealAccountForCashierModal } = ui;
const p2p_notification_count = useP2PNotificationCount();
const real_account_needed_for_cashier = useRealAccountNeededForCashier();

const history = useHistory();

Expand All @@ -49,18 +50,23 @@ const CashierTab = observer(() => {
const toggleModal = () => {
if (toggle_modal_routes && !has_any_real_account) {
toggleReadyToDepositModal();
} else if (window.location.pathname === routes.traders_hub) {
toggleNeedRealAccountForCashierModal();
}
};

const handleClickCashier = () => {
if (!has_any_real_account && is_virtual) {
toggleModal();
} else if (real_account_needed_for_cashier) {
toggleModal();
thisyahlen-deriv marked this conversation as resolved.
Show resolved Hide resolved
} else {
history.push(routes.cashier_deposit);
}
};

const cashier_redirect = toggle_modal_routes && !has_any_real_account && is_virtual;
const cashier_redirect =
(toggle_modal_routes && !has_any_real_account && is_virtual) || real_account_needed_for_cashier;

return (
<MenuItems
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import classNames from 'classnames';
import React from 'react';
import { Div100vhContainer, Icon, MobileDrawer, ToggleSwitch, Text, Button } from '@deriv/components';
import { useOnrampVisible, useAccountTransferVisible } from '@deriv/hooks';
import { useOnrampVisible, useAccountTransferVisible, useRealAccountNeededForCashier } from '@deriv/hooks';
import { routes, PlatformContext, getStaticUrl, whatsapp_url, ContentFlag } from '@deriv/shared';
import { observer, useStore } from '@deriv/stores';
import { localize, getAllowedLanguages, getLanguage } from '@deriv/translations';
Expand All @@ -22,7 +22,8 @@ const MenuLink = observer(
const deriv_static_url = getStaticUrl(link_to);
const history = useHistory();
const { has_any_real_account, is_virtual } = client;
const { toggleReadyToDepositModal } = ui;
const { toggleReadyToDepositModal, toggleNeedRealAccountForCashierModal } = ui;
const real_account_needed_for_cashier = useRealAccountNeededForCashier();

const cashier_link =
link_to === routes.cashier_deposit ||
Expand All @@ -31,6 +32,27 @@ const MenuLink = observer(

if (is_hidden) return null;

const traders_hub_path = window.location.pathname === routes.traders_hub;

if (real_account_needed_for_cashier && cashier_link && traders_hub_path) {
const handleClickCashier = () => {
onClickLink();
toggleNeedRealAccountForCashierModal();
};
return (
<div
className={classNames('header__menu-mobile-link', {
'header__menu-mobile-link--disabled': is_disabled,
})}
onClick={handleClickCashier}
>
<Icon className='header__menu-mobile-link-icon' icon={icon} />
<span className='header__menu-mobile-link-text'>{text}</span>
{suffix_icon && <Icon className='header__menu-mobile-link-suffix-icon' icon={suffix_icon} />}
</div>
);
}

if (cashier_link && is_virtual && !has_any_real_account) {
const toggle_modal_routes =
window.location.pathname === routes.root || window.location.pathname === routes.traders_hub;
Expand Down
7 changes: 7 additions & 0 deletions packages/core/src/App/Containers/Modals/app-modals.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import DerivRealAccountRequiredModal from 'App/Components/Elements/Modals/deriv-
import ExitTradersHubModal from './exit-traders-hub-modal';
import ReadyToDepositModal from './ready-to-deposit-modal';
import RiskAcceptTestWarningModal from './risk-accept-test-warning-modal';
import NeedRealAccountForCashierModal from './need-real-account-for-cashier-modal';

const AccountSignupModal = React.lazy(() =>
moduleLoader(() => import(/* webpackChunkName: "account-signup-modal" */ '../AccountSignupModal'))
Expand Down Expand Up @@ -80,6 +81,7 @@ const AppModals = ({
is_ready_to_deposit_modal_visible,
is_trading_experience_incomplete,
should_show_risk_accept_modal,
is_need_real_account_for_cashier_modal_visible,
}) => {
const url_params = new URLSearchParams(useLocation().search);
const url_action_param = url_params.get('action');
Expand Down Expand Up @@ -162,6 +164,10 @@ const AppModals = ({
ComponentToLoad = <ReadyToDepositModal />;
}

if (is_need_real_account_for_cashier_modal_visible) {
ComponentToLoad = <NeedRealAccountForCashierModal />;
}

return (
<>
<RedirectNoticeModal is_logged_in={is_logged_in} is_eu={is_eu_user} portal_id='popup_root' />
Expand Down Expand Up @@ -193,6 +199,7 @@ export default connect(({ client, ui, traders_hub }) => ({
is_warning_scam_message_modal_visible: ui.is_warning_scam_message_modal_visible,
is_exit_traders_hub_modal_visible: ui.is_exit_traders_hub_modal_visible,
is_ready_to_deposit_modal_visible: ui.is_ready_to_deposit_modal_visible,
is_need_real_account_for_cashier_modal_visible: ui.is_need_real_account_for_cashier_modal_visible,
content_flag: traders_hub.content_flag,
is_trading_experience_incomplete: client.is_trading_experience_incomplete,
should_show_risk_accept_modal: ui.should_show_risk_accept_modal,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import NeedRealAccountForCashierModal from './need-real-account-for-cashier-modal';
import './need-real-account-for-cashier-modal.scss';

export default NeedRealAccountForCashierModal;
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
.need-real-account-for-cashier-dialog {
.dc-dialog {
&__header-wrapper {
margin: 0 0 2rem;
}
}
@include mobile {
.dc-dialog {
&__content,
&__button {
font-size: 1.2rem;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import React from 'react';
import { Dialog } from '@deriv/components';
import { Localize, localize } from '@deriv/translations';
import { useStore, observer } from '@deriv/stores';
import { useHistory } from 'react-router-dom';
import { routes } from '@deriv/shared';
import './need-real-account-for-cashier-modal.scss';

const NeedRealAccountForCashierModal = observer(() => {
const { ui, traders_hub } = useStore();
const { is_eu_user, selectRegion } = traders_hub;
const {
is_need_real_account_for_cashier_modal_visible: is_open,
toggleNeedRealAccountForCashierModal,
disableApp,
enableApp,
openRealAccountSignup,
} = ui;

const history = useHistory();

const createAccount = () => {
toggleNeedRealAccountForCashierModal();
return is_eu_user ? openRealAccountSignup('maltainvest') : openRealAccountSignup();
};

const switchRegulation = () => {
return is_eu_user ? selectRegion('Non-EU') : selectRegion('EU');
};

const onClose = async () => {
await switchRegulation();
toggleNeedRealAccountForCashierModal();
history.push(routes.cashier_deposit);
thisyahlen-deriv marked this conversation as resolved.
Show resolved Hide resolved
};

const regulation = is_eu_user ? 'EU' : 'non-EU';

const active_real_regulation = is_eu_user ? 'non-EU' : 'EU';

return (
<Dialog
className='need-real-account-for-cashier-dialog'
title={localize('The cashier is for real accounts only')}
confirm_button_text={localize('Add account')}
onConfirm={createAccount}
cancel_button_text={localize('Switch account')}
onCancel={onClose}
is_closed_on_cancel
disableApp={disableApp}
enableApp={enableApp}
is_closed_on_confirm
is_visible={is_open}
dismissable={false}
has_close_icon
onClose={toggleNeedRealAccountForCashierModal}
>
<Localize
i18n_default_text='It looks like you don’t have a real {{regulation}} account. To use the cashier, switch to your {{active_real_regulation}} real account, or get an {{regulation}} real account.'
values={{ regulation, active_real_regulation }}
/>
</Dialog>
);
});

export default NeedRealAccountForCashierModal;
7 changes: 7 additions & 0 deletions packages/core/src/Stores/ui-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ export default class UIStore extends BaseStore {
is_deriv_account_needed_modal_visible = false;
is_exit_traders_hub_modal_visible = false;
is_ready_to_deposit_modal_visible = false;
is_need_real_account_for_cashier_modal_visible = false;
is_switch_to_deriv_account_modal_visible = false;
is_cfd_reset_password_modal_enabled = false;
sub_section_index = 0;
Expand Down Expand Up @@ -208,6 +209,7 @@ export default class UIStore extends BaseStore {
has_read_scam_message: observable,
is_exit_traders_hub_modal_visible: observable,
is_ready_to_deposit_modal_visible: observable,
is_need_real_account_for_cashier_modal_visible: observable,
is_services_error_visible: observable,
is_unsupported_contract_modal_visible: observable,
is_new_account: observable,
Expand Down Expand Up @@ -349,6 +351,7 @@ export default class UIStore extends BaseStore {
toggleWelcomeModal: action.bound,
toggleExitTradersHubModal: action.bound,
toggleReadyToDepositModal: action.bound,
toggleNeedRealAccountForCashierModal: action.bound,
toggleShouldShowRealAccountsList: action.bound,
toggleShouldShowMultipliersOnboarding: action.bound,
shouldNavigateAfterChooseCrypto: action.bound,
Expand Down Expand Up @@ -904,6 +907,10 @@ export default class UIStore extends BaseStore {
this.is_ready_to_deposit_modal_visible = !this.is_ready_to_deposit_modal_visible;
}

toggleNeedRealAccountForCashierModal() {
this.is_need_real_account_for_cashier_modal_visible = !this.is_need_real_account_for_cashier_modal_visible;
}

setCFDPasswordResetModal(val) {
this.is_cfd_reset_password_modal_enabled = !!val;
}
Expand Down
2 changes: 2 additions & 0 deletions packages/hooks/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ export { default as useHasActiveRealAccount } from './useHasActiveRealAccount';
export { default as useP2PNotificationCount } from './useP2PNotificationCount';
export { default as useOnrampVisible } from './useOnrampVisible';
export { default as useSwitchToRealAccount } from './useSwitchToRealAccount';
export { default as useRealAccountNeededForCashier } from './useRealAccountNeededForCashier';
export { default as useHasSvgAccount } from './useHasSvgAccount';
11 changes: 11 additions & 0 deletions packages/hooks/src/useHasSvgAccount.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { useStore } from '@deriv/stores';

const useHasSvgAccount = () => {
thisyahlen-deriv marked this conversation as resolved.
Show resolved Hide resolved
const { client } = useStore();
const { active_accounts } = client;
const has_svg_account = active_accounts.some(account => account.landing_company_shortcode === 'svg');

return has_svg_account;
};

export default useHasSvgAccount;
18 changes: 18 additions & 0 deletions packages/hooks/src/useRealAccountNeededForCashier.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { useStore } from '@deriv/stores';
import useHasSvgAccount from './useHasSvgAccount';
import useHasMaltaInvestAccount from './useHasMaltaInvestAccount';

const useRealAccountNeededForCashier = () => {
thisyahlen-deriv marked this conversation as resolved.
Show resolved Hide resolved
const { traders_hub } = useStore();
const { is_eu_user, is_real } = traders_hub;

const has_svg_account = useHasSvgAccount();
const has_maltainvest_account = useHasMaltaInvestAccount();

const no_real_mf_account = has_svg_account && !has_maltainvest_account && is_eu_user;
const no_real_cr_account = !has_svg_account && has_maltainvest_account && !is_eu_user;

return (no_real_mf_account || no_real_cr_account) && is_real;
thisyahlen-deriv marked this conversation as resolved.
Show resolved Hide resolved
};

export default useRealAccountNeededForCashier;
4 changes: 4 additions & 0 deletions packages/stores/src/mockStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,12 +238,16 @@ const mock = (): TRootStore => {
sub_section_index: 0,
toggleReadyToDepositModal: jest.fn(),
is_ready_to_deposit_modal_visible: false,
is_need_real_account_for_cashier_modal_visible: false,
toggleNeedRealAccountForCashierModal: jest.fn(),
},
traders_hub: {
closeModal: jest.fn(),
openModal: jest.fn(),
content_flag: '',
is_eu_user: false,
is_real: false,
selectRegion: jest.fn(),
},
menu: {
attach: jest.fn(),
Expand Down
4 changes: 4 additions & 0 deletions packages/stores/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,8 @@ type TUiStore = {
setSubSectionIndex: (index: number) => void;
toggleReadyToDepositModal: () => void;
is_ready_to_deposit_modal_visible: boolean;
is_need_real_account_for_cashier_modal_visible: boolean;
toggleNeedRealAccountForCashierModal: () => void;
};

type TMenuStore = {
Expand All @@ -250,6 +252,8 @@ type TTradersHubStore = {
content_flag: any;
openModal: (modal_id: string, props?: any) => void;
is_eu_user: boolean;
is_real: boolean;
selectRegion: (region: string) => void;
};

export type TRootStore = {
Expand Down