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/currency-switcher-card/real/real-account-switcher.tsx b/packages/appstore/src/components/currency-switcher-card/real/real-account-switcher.tsx index 8e3bb2bb56a4..0c6e60a9272c 100644 --- a/packages/appstore/src/components/currency-switcher-card/real/real-account-switcher.tsx +++ b/packages/appstore/src/components/currency-switcher-card/real/real-account-switcher.tsx @@ -1,15 +1,19 @@ import React from 'react'; import { observer } from 'mobx-react-lite'; +import { StatusBadge } from '@deriv/components'; import CurrencySwitcherContainer from 'Components/containers/currency-switcher-container'; import CurrencySwitcherLoader from 'Components/pre-loader/currency-switcher-loader'; import { useStores } from 'Stores/index'; -import StatusBadge from './switcher-status-badge'; import RealAccountCard from './real-account-card'; import './real-account-switcher.scss'; const AccountNeedsVerification = observer(() => { const { client, traders_hub } = useStores(); - const { account_list, loginid } = client; + const { + authentication_status: { document_status }, + account_list, + loginid, + } = client; const { openModal } = traders_hub; const title = account_list.find((acc: { loginid: string }) => loginid === acc.loginid).title; @@ -24,7 +28,7 @@ const AccountNeedsVerification = observer(() => { openModal('currency_selection'); }} > - + ); }); 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/components/src/components/status-badge/index.ts b/packages/components/src/components/status-badge/index.ts new file mode 100644 index 000000000000..6b27ebe05ffb --- /dev/null +++ b/packages/components/src/components/status-badge/index.ts @@ -0,0 +1,4 @@ +import StatusBadge from './status-badge'; +import './status-badge.scss'; + +export default StatusBadge; diff --git a/packages/appstore/src/components/currency-switcher-card/real/switcher-status-badge.scss b/packages/components/src/components/status-badge/status-badge.scss similarity index 100% rename from packages/appstore/src/components/currency-switcher-card/real/switcher-status-badge.scss rename to packages/components/src/components/status-badge/status-badge.scss diff --git a/packages/appstore/src/components/currency-switcher-card/real/switcher-status-badge.tsx b/packages/components/src/components/status-badge/status-badge.tsx similarity index 88% rename from packages/appstore/src/components/currency-switcher-card/real/switcher-status-badge.tsx rename to packages/components/src/components/status-badge/status-badge.tsx index c08cde50c89c..114d745c6264 100644 --- a/packages/appstore/src/components/currency-switcher-card/real/switcher-status-badge.tsx +++ b/packages/components/src/components/status-badge/status-badge.tsx @@ -2,10 +2,14 @@ import React from 'react'; import classNames from 'classnames'; import { Link } from 'react-router-dom'; import { observer } from 'mobx-react-lite'; -import { useStores } from 'Stores/index'; -import { Icon, Text } from '@deriv/components'; +import Icon from '../icon'; +import Text from '../text'; import { Localize } from '@deriv/translations'; -import './switcher-status-badge.scss'; +import './status-badge.scss'; + +type TStatusBadge = { + document_status: any; +}; const status_text = { pending: { @@ -43,9 +47,7 @@ const status_text = { }, }; -const StatusBadge = () => { - const { client } = useStores(); - const { document_status } = client.authentication_status; +const StatusBadge = ({ document_status }: TStatusBadge) => { const { text, icon } = status_text[document_status as keyof typeof status_text] ?? status_text.default; return ( diff --git a/packages/components/src/index.js b/packages/components/src/index.js index 897d7785cd21..a4eb3924a540 100644 --- a/packages/components/src/index.js +++ b/packages/components/src/index.js @@ -87,6 +87,7 @@ export { default as RouteWithSubroutes } from './components/route-with-subroutes export { default as SelectNative } from './components/select-native'; export { default as StaticUrl } from './components/static-url'; export { default as SendEmailTemplate } from './components/send-email-template'; +export { default as StatusBadge } from './components/status-badge'; export { default as SwipeableWrapper } from './components/swipeable-wrapper'; export { default as RelativeDatepicker } from './components/relative-datepicker'; export { default as RemainingTime } from './components/remaining-time'; 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 66% 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..ef81c5c9f396 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,41 @@ import React from 'react'; -import { observer } from 'mobx-react-lite'; -import { Button, Icon, Modal, Money, Text } from '@deriv/components'; +import { Button, Icon, Modal, Money, StatusBadge, 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 + authentication_status: any; + //TODO: Replace the type with a proper one when ts migration cards merged + accounts: any; + closeModal: () => void; + is_authentication_needed: boolean; 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, + authentication_status, + accounts, + closeModal, + is_authentication_needed, + is_visible, + loginid: current_loginid, + openRealAccountSignup, + selected_region, + switchAccount, +}: CurrencySelectionModalProps) => { return (
@@ -58,7 +76,7 @@ const CurrencySelectionModal = ({ is_visible }: CurrencySelectionModalProps) =>
{is_selected && selected_region === 'EU' && is_authentication_needed ? ( - + ) : ( @@ -73,7 +91,7 @@ const CurrencySelectionModal = ({ is_visible }: CurrencySelectionModalProps) =>