From 8f39fa0000d63f9f1fd73b7c76ae55c557ea38fa Mon Sep 17 00:00:00 2001 From: Bahar Date: Thu, 5 Jan 2023 10:59:11 +0800 Subject: [PATCH 1/2] feat: integrate-create-new-account-with-diel-account-switcher --- .../account-transfer-modal.tsx | 17 +- .../src/components/modals/modal-manager.tsx | 4 +- packages/appstore/src/stores/index.ts | 1 + .../__tests__/account-transfer.spec.tsx | 3 +- .../account-transfer-no-account.spec.tsx | 1 + .../account-transfer-no-account.tsx | 27 ++- .../account-transfer/account-transfer.tsx | 173 +++++++++--------- .../currency-selection-modal.scss | 0 .../CurrencySelectionModal/currency/index.tsx | 35 ++++ .../curreny-selection-modal.tsx | 55 ++++-- .../CurrencySelectionModal}/index.ts | 0 .../CurrencySelectionModal/types.tsx | 38 ++++ .../Layout/header/trading-hub-header.jsx | 5 + packages/stores/types.ts | 6 + 14 files changed, 253 insertions(+), 112 deletions(-) rename packages/{appstore/src/components/modals/currency-selection-modal => core/src/App/Containers/CurrencySelectionModal}/currency-selection-modal.scss (100%) create mode 100644 packages/core/src/App/Containers/CurrencySelectionModal/currency/index.tsx rename packages/{appstore/src/components/modals/currency-selection-modal => core/src/App/Containers/CurrencySelectionModal}/curreny-selection-modal.tsx (68%) rename packages/{appstore/src/components/modals/currency-selection-modal => core/src/App/Containers/CurrencySelectionModal}/index.ts (100%) create mode 100644 packages/core/src/App/Containers/CurrencySelectionModal/types.tsx diff --git a/packages/appstore/src/components/account-transfer-modal/account-transfer-modal.tsx b/packages/appstore/src/components/account-transfer-modal/account-transfer-modal.tsx index 83fcddb3de85..c681d8386c97 100644 --- a/packages/appstore/src/components/account-transfer-modal/account-transfer-modal.tsx +++ b/packages/appstore/src/components/account-transfer-modal/account-transfer-modal.tsx @@ -18,10 +18,16 @@ const AccountTransferModal = ({ is_modal_open, toggleModal }: TAccountTransferMo account_transfer: { is_transfer_confirm, should_switch_account }, }, }, + traders_hub: { closeModal, openModal }, } = useStore(); const history = useHistory(); + React.useEffect(() => { + return () => closeModal(); + // eslint-disable-next-line react-hooks/exhaustive-deps + }, []); + const modal_title = !is_transfer_confirm && ; const onClickDeposit = () => { @@ -34,6 +40,10 @@ const AccountTransferModal = ({ is_modal_open, toggleModal }: TAccountTransferMo history.push(routes.cashier_acc_transfer); }; + const openAccountSwitcherModal = () => { + openModal('currency_selection'); + }; + return ( - + ); diff --git a/packages/appstore/src/components/modals/modal-manager.tsx b/packages/appstore/src/components/modals/modal-manager.tsx index aa5743f35f74..53fa7b1fb3b4 100644 --- a/packages/appstore/src/components/modals/modal-manager.tsx +++ b/packages/appstore/src/components/modals/modal-manager.tsx @@ -18,7 +18,6 @@ import RegulatorsCompareModal from './regulators-compare-modal'; import ExitTradersHubModal from './exit-traders-hub-modal'; import { useStores } from 'Stores'; import { TOpenAccountTransferMeta } from 'Types'; -import CurrencySelectionModal from './currency-selection-modal'; import { DetailsOfEachMT5Loginid } from '@deriv/api-types'; import AccountTransferModal from 'Components/account-transfer-modal'; @@ -40,7 +39,7 @@ const ModalManager = () => { getRealSyntheticAccountsExistingData, getRealFinancialAccountsExistingData, } = modules.cfd; - const { is_demo, modal_data, is_account_transfer_modal_open, toggleAccountTransferModal } = traders_hub; + const { is_demo, is_account_transfer_modal_open, toggleAccountTransferModal } = traders_hub; const [password_manager, setPasswordManager] = React.useState<{ is_visible: boolean; @@ -138,7 +137,6 @@ const ModalManager = () => { openPasswordModal={openRealPasswordModal} is_real_enabled={has_active_real_account || !is_demo} /> - React.useContext(stores_context); diff --git a/packages/cashier/src/pages/account-transfer/__tests__/account-transfer.spec.tsx b/packages/cashier/src/pages/account-transfer/__tests__/account-transfer.spec.tsx index 36b2c60314cd..f5038d204c3d 100644 --- a/packages/cashier/src/pages/account-transfer/__tests__/account-transfer.spec.tsx +++ b/packages/cashier/src/pages/account-transfer/__tests__/account-transfer.spec.tsx @@ -24,6 +24,7 @@ jest.mock('@deriv/shared/src/services/ws-methods', () => ({ jest.mock('../account-transfer-form', () => jest.fn(() => 'mockedAccountTransferForm')); jest.mock('Components/crypto-transactions-history', () => jest.fn(() => 'mockedCryptoTransactionsHistory')); jest.mock('Components/cashier-locked', () => jest.fn(() => 'mockedCashierLocked')); +jest.mock('../account-transfer-no-account', () => jest.fn(() => 'mockedAccountTransferNoAccount')); jest.mock('../account-transfer-receipt', () => jest.fn(() => 'mockedAccountTransferReceipt')); jest.mock('Components/error', () => jest.fn(() => 'mockedError')); @@ -140,7 +141,7 @@ describe('', () => { renderAccountTransfer(); - expect(await screen.findByText('You need at least two accounts')).toBeInTheDocument(); + expect(await screen.findByText('mockedAccountTransferNoAccount')).toBeInTheDocument(); }); it('should render the no balance component if the account has no balance', async () => { diff --git a/packages/cashier/src/pages/account-transfer/account-transfer-no-account/__tests__/account-transfer-no-account.spec.tsx b/packages/cashier/src/pages/account-transfer/account-transfer-no-account/__tests__/account-transfer-no-account.spec.tsx index 523a144e463a..5b2c5a1ca9e5 100644 --- a/packages/cashier/src/pages/account-transfer/account-transfer-no-account/__tests__/account-transfer-no-account.spec.tsx +++ b/packages/cashier/src/pages/account-transfer/account-transfer-no-account/__tests__/account-transfer-no-account.spec.tsx @@ -19,6 +19,7 @@ describe('', () => { ui: { toggleAccountsDialog: jest.fn(), }, + traders_hub: { openModal: jest.fn(), closeModal: jest.fn() }, }; }); diff --git a/packages/cashier/src/pages/account-transfer/account-transfer-no-account/account-transfer-no-account.tsx b/packages/cashier/src/pages/account-transfer/account-transfer-no-account/account-transfer-no-account.tsx index 798ef383dd87..e9e3d5f35e65 100644 --- a/packages/cashier/src/pages/account-transfer/account-transfer-no-account/account-transfer-no-account.tsx +++ b/packages/cashier/src/pages/account-transfer/account-transfer-no-account/account-transfer-no-account.tsx @@ -5,12 +5,22 @@ import { Localize } from '@deriv/translations'; import { useStore, observer } from '@deriv/stores'; import './account-transfer-no-account.scss'; -const AccountTransferNoAccount = observer(() => { +type TAccountTransferNoAccount = { + openAccountSwitcherModal?: () => void; +}; + +const AccountTransferNoAccount = observer(({ openAccountSwitcherModal }: TAccountTransferNoAccount) => { const { - client: { is_dxtrade_allowed }, + client: { is_dxtrade_allowed, is_pre_appstore }, ui: { toggleAccountsDialog }, + traders_hub: { openModal, closeModal }, } = useStore(); + React.useEffect(() => { + closeModal(); + // eslint-disable-next-line react-hooks/exhaustive-deps + }, []); + return (
@@ -33,7 +43,18 @@ const AccountTransferNoAccount = observer(() => { /> )} -
diff --git a/packages/cashier/src/pages/account-transfer/account-transfer.tsx b/packages/cashier/src/pages/account-transfer/account-transfer.tsx index b077bb20a6a4..10390d070601 100644 --- a/packages/cashier/src/pages/account-transfer/account-transfer.tsx +++ b/packages/cashier/src/pages/account-transfer/account-transfer.tsx @@ -17,106 +17,109 @@ type TAccountTransferProps = { onClickDeposit?: () => void; onClickNotes?: () => void; onClose?: () => void; + openAccountSwitcherModal?: () => void; setSideNotes?: (notes: TSideNotesProps) => void; }; -const AccountTransfer = observer(({ onClickDeposit, onClickNotes, onClose, setSideNotes }: TAccountTransferProps) => { - const { - modules: { - cashier: { account_transfer, general_store, transaction_history }, - }, - client, - } = useStore(); +const AccountTransfer = observer( + ({ onClickDeposit, onClickNotes, onClose, openAccountSwitcherModal, setSideNotes }: TAccountTransferProps) => { + const { + modules: { + cashier: { account_transfer, general_store, transaction_history }, + }, + client, + } = useStore(); - const { - accounts_list, - container, - error, - has_no_account, - has_no_accounts_balance, - is_transfer_confirm, - is_transfer_locked, - onMountAccountTransfer: onMount, - setAccountTransferAmount, - setIsTransferConfirm, - } = account_transfer; + const { + accounts_list, + container, + error, + has_no_account, + has_no_accounts_balance, + is_transfer_confirm, + is_transfer_locked, + onMountAccountTransfer: onMount, + setAccountTransferAmount, + setIsTransferConfirm, + } = account_transfer; - const { is_cashier_locked, is_loading, setActiveTab } = general_store; + const { is_cashier_locked, is_loading, setActiveTab } = general_store; - const { is_crypto_transactions_visible, onMount: recentTransactionOnMount } = transaction_history; + const { is_crypto_transactions_visible, onMount: recentTransactionOnMount } = transaction_history; - const { is_pre_appstore, is_switching, is_virtual } = client; + const { is_pre_appstore, is_switching, is_virtual } = client; - const [is_loading_status, setIsLoadingStatus] = React.useState(true); - const is_from_pre_appstore = is_pre_appstore && !location.pathname.startsWith(routes.cashier); + const [is_loading_status, setIsLoadingStatus] = React.useState(true); + const is_from_pre_appstore = is_pre_appstore && !location.pathname.startsWith(routes.cashier); - React.useEffect(() => { - if (!is_crypto_transactions_visible) { - recentTransactionOnMount(); - } - // eslint-disable-next-line react-hooks/exhaustive-deps - }, [is_switching]); + React.useEffect(() => { + if (!is_crypto_transactions_visible) { + recentTransactionOnMount(); + } + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [is_switching]); + + React.useEffect(() => { + setActiveTab(container); + onMount(); - React.useEffect(() => { - setActiveTab(container); - onMount(); + WS.wait('authorize', 'website_status', 'get_settings', 'paymentagent_list').then(() => { + setIsLoadingStatus(false); + }); - WS.wait('authorize', 'website_status', 'get_settings', 'paymentagent_list').then(() => { - setIsLoadingStatus(false); - }); + return () => { + setAccountTransferAmount(''); + setIsTransferConfirm(false); + }; + // eslint-disable-next-line react-hooks/exhaustive-deps + }, []); - return () => { - setAccountTransferAmount(''); - setIsTransferConfirm(false); - }; - // eslint-disable-next-line react-hooks/exhaustive-deps - }, []); + React.useEffect(() => { + if (typeof setSideNotes === 'function' && (has_no_accounts_balance || is_switching)) { + setSideNotes(null); + } + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [setSideNotes, has_no_accounts_balance]); - React.useEffect(() => { - if (typeof setSideNotes === 'function' && (has_no_accounts_balance || is_switching)) { - setSideNotes(null); + if (is_virtual) { + return ; + } + if (is_loading || is_switching || is_loading_status) { + return ; + } + if (is_cashier_locked) { + return ; + } + if (is_transfer_locked) { + return ; + } + if (error.is_show_full_page || (error.message && !accounts_list.length)) { + // for errors with CTA hide the form and show the error, + // for others show them at the bottom of the form next to submit button + return ; + } + if (has_no_account) { + return ; + } + if (has_no_accounts_balance) { + return ; + } + if (is_transfer_confirm) { + return ; + } + if (!is_from_pre_appstore && is_crypto_transactions_visible) { + return ; } - // eslint-disable-next-line react-hooks/exhaustive-deps - }, [setSideNotes, has_no_accounts_balance]); - if (is_virtual) { - return ; + return ( + + ); } - if (is_loading || is_switching || is_loading_status) { - return ; - } - if (is_cashier_locked) { - return ; - } - if (is_transfer_locked) { - return ; - } - if (error.is_show_full_page || (error.message && !accounts_list.length)) { - // for errors with CTA hide the form and show the error, - // for others show them at the bottom of the form next to submit button - return ; - } - if (has_no_account) { - return ; - } - if (has_no_accounts_balance) { - return ; - } - if (is_transfer_confirm) { - return ; - } - if (!is_from_pre_appstore && is_crypto_transactions_visible) { - return ; - } - - return ( - - ); -}); +); export default AccountTransfer; diff --git a/packages/appstore/src/components/modals/currency-selection-modal/currency-selection-modal.scss b/packages/core/src/App/Containers/CurrencySelectionModal/currency-selection-modal.scss similarity index 100% rename from packages/appstore/src/components/modals/currency-selection-modal/currency-selection-modal.scss rename to packages/core/src/App/Containers/CurrencySelectionModal/currency-selection-modal.scss diff --git a/packages/core/src/App/Containers/CurrencySelectionModal/currency/index.tsx b/packages/core/src/App/Containers/CurrencySelectionModal/currency/index.tsx new file mode 100644 index 000000000000..cf6aa04895d6 --- /dev/null +++ b/packages/core/src/App/Containers/CurrencySelectionModal/currency/index.tsx @@ -0,0 +1,35 @@ +import React from 'react'; +import { Icon } from '@deriv/components'; +import { capitalizeFirstLetter } from '@deriv/shared'; +import { IconProps } from '../types'; + +// TODO: This probably can be moved somewhere else. +export type Currency = + | 'AUD' + | 'BCH' + | 'BTC' + | 'BUSD' + | 'DAI' + | 'ETH' + | 'EURCHECK' + | 'EUR' + | 'EURS' + | 'EUSDT' + | 'GBP' + | 'IDK' + | 'LTC' + | 'PAX' + | 'TUSD' + | 'TUSDT' + | 'UNKNOWN' + | 'USD' + | 'USDC' + | 'USDK' + | 'UST' + | 'VIRTUAL'; + +const CurrencyIcon = ({ icon, ...props }: IconProps) => { + return ; +}; + +export default CurrencyIcon; diff --git a/packages/appstore/src/components/modals/currency-selection-modal/curreny-selection-modal.tsx b/packages/core/src/App/Containers/CurrencySelectionModal/curreny-selection-modal.tsx similarity index 68% rename from packages/appstore/src/components/modals/currency-selection-modal/curreny-selection-modal.tsx rename to packages/core/src/App/Containers/CurrencySelectionModal/curreny-selection-modal.tsx index 511accf97351..1c954a70105a 100644 --- a/packages/appstore/src/components/modals/currency-selection-modal/curreny-selection-modal.tsx +++ b/packages/core/src/App/Containers/CurrencySelectionModal/curreny-selection-modal.tsx @@ -1,23 +1,36 @@ import React from 'react'; -import { observer } from 'mobx-react-lite'; import { Button, Icon, Modal, Money, Text } from '@deriv/components'; import { localize } from '@deriv/translations'; import { getCurrencyName } from '@deriv/shared'; -import CurrencyIcon from 'Assets/svgs/currency'; -import { useStores } from 'Stores/index'; -import { AccountListDetail } from 'Types'; +import { connect } from 'Stores/connect'; +import RootStore from 'Stores/index'; +import CurrencyIcon from './currency'; +import { AccountListDetail } from './types'; import classNames from 'classnames'; -import StatusBadge from 'Components/currency-switcher-card/real/switcher-status-badge'; type CurrencySelectionModalProps = { + //TODO: Replace the type with a proper one when ts migration cards merged + account_list: object[]; + //TODO: Replace the type with a proper one when ts migration cards merged + accounts: any; + closeModal: () => void; is_visible: boolean; + loginid: string; + openRealAccountSignup: (account_type: string) => void; + selected_region: string; + switchAccount: (loginid: string) => void; }; -const CurrencySelectionModal = ({ is_visible }: CurrencySelectionModalProps) => { - const { client, traders_hub, ui } = useStores(); - const { accounts, account_list, loginid: current_loginid, switchAccount, is_authentication_needed } = client; - const { closeModal, selected_region } = traders_hub; - +const CurrencySelectionModal = ({ + account_list, + accounts, + closeModal, + is_visible, + loginid: current_loginid, + openRealAccountSignup, + selected_region, + switchAccount, +}: CurrencySelectionModalProps) => { return (
@@ -57,13 +70,9 @@ const CurrencySelectionModal = ({ is_visible }: CurrencySelectionModalProps) =>
- {is_selected && selected_region === 'EU' && is_authentication_needed ? ( - - ) : ( - - - - )} + + +
); @@ -73,7 +82,7 @@ const CurrencySelectionModal = ({ is_visible }: CurrencySelectionModalProps) =>