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 5 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 @@ -36,10 +36,11 @@ const ReportTab = () => (
);

const CashierTab = observer(() => {
const { client, ui } = useStore();
const { client, ui, traders_hub } = 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 } = traders_hub;

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
Expand Up @@ -17,12 +17,13 @@ import PlatformSwitcher from './platform-switcher';

const MenuLink = observer(
({ link_to, icon, is_active, is_disabled, is_language, suffix_icon, text, onClickLink, is_hidden }) => {
const { common, ui, client } = useStore();
const { common, ui, client, traders_hub } = useStore();
const { changeCurrentLanguage } = common;
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 } = traders_hub;

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,61 @@
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 } = 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 onClose = () => {
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;
5 changes: 5 additions & 0 deletions packages/core/src/Stores/client-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ export default class ClientStore extends BaseStore {
reality_check_duration: computed,
reality_check_dismissed: computed,
has_active_real_account: computed,
has_svg_account: computed,
has_maltainvest_account: computed,
has_malta_account: computed,
has_any_real_account: computed,
Expand Down Expand Up @@ -491,6 +492,10 @@ export default class ClientStore extends BaseStore {
return this.active_accounts.some(acc => acc.is_virtual === 0);
}

get has_svg_account() {
return this.active_accounts.some(acc => acc.landing_company_shortcode === 'svg');
}
thisyahlen-deriv marked this conversation as resolved.
Show resolved Hide resolved

get has_maltainvest_account() {
return this.active_accounts.some(acc => acc.landing_company_shortcode === 'maltainvest');
}
Expand Down
7 changes: 7 additions & 0 deletions packages/core/src/Stores/traders-hub-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export default class TradersHubStore extends BaseStore {
is_demo: computed,
is_eu_selected: computed,
is_real: computed,
real_account_needed_for_cashier: computed,
is_currency_switcher_disabled_for_mf: computed,
no_CR_account: computed,
no_MF_account: computed,
Expand Down Expand Up @@ -478,6 +479,12 @@ export default class TradersHubStore extends BaseStore {
return this.selected_region === 'EU';
}

get real_account_needed_for_cashier() {
const { has_svg_account, has_maltainvest_account } = this.root_store.client;

return ((has_svg_account && this.is_eu_user) || (has_maltainvest_account && !this.is_eu_user)) && this.is_real;
thisyahlen-deriv marked this conversation as resolved.
Show resolved Hide resolved
}
thisyahlen-deriv marked this conversation as resolved.
Show resolved Hide resolved

get multipliers_account_status() {
const {
has_maltainvest_account,
Expand Down
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/stores/src/mockStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,8 @@ 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(),
Expand Down
2 changes: 2 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 Down