diff --git a/packages/wallets/src/features/cfd/modals/CreatePasswordModal/CreatePasswordModal.tsx b/packages/wallets/src/features/cfd/modals/CreatePasswordModal/CreatePasswordModal.tsx new file mode 100644 index 000000000000..c4ca633dca25 --- /dev/null +++ b/packages/wallets/src/features/cfd/modals/CreatePasswordModal/CreatePasswordModal.tsx @@ -0,0 +1,57 @@ +import React, { ComponentProps, FC } from 'react'; +import { ModalStepWrapper, ModalWrapper, WalletButton } from '../../../../components'; +import useDevice from '../../../../hooks/useDevice'; +import { PlatformDetails } from '../../constants'; +import { CreatePassword } from '../../screens'; + +const CreatePasswordModal: FC> = ({ + isLoading, + onPasswordChange, + onPrimaryClick, + password, + platform, +}) => { + const { isMobile } = useDevice(); + if (isMobile) { + return ( + { + return ( + + {`Create ${PlatformDetails[platform].title} password`} + + ); + }} + title={''} + > + + + ); + } + + return ( + + + + ); +}; + +export default CreatePasswordModal; diff --git a/packages/wallets/src/features/cfd/modals/CreatePasswordModal/index.ts b/packages/wallets/src/features/cfd/modals/CreatePasswordModal/index.ts new file mode 100644 index 000000000000..07b5ed417b41 --- /dev/null +++ b/packages/wallets/src/features/cfd/modals/CreatePasswordModal/index.ts @@ -0,0 +1 @@ +export { default as CreatePasswordModal } from './CreatePasswordModal'; diff --git a/packages/wallets/src/features/cfd/modals/DxtradeEnterPasswordModal/DxtradeEnterPasswordModal.tsx b/packages/wallets/src/features/cfd/modals/DxtradeEnterPasswordModal/DxtradeEnterPasswordModal.tsx index 3ffad4d2cac1..c75ee0abe5d9 100644 --- a/packages/wallets/src/features/cfd/modals/DxtradeEnterPasswordModal/DxtradeEnterPasswordModal.tsx +++ b/packages/wallets/src/features/cfd/modals/DxtradeEnterPasswordModal/DxtradeEnterPasswordModal.tsx @@ -7,13 +7,15 @@ import { useDxtradeAccountsList, } from '@deriv/api-v2'; import { SentEmailContent, WalletError } from '../../../../components'; -import { ModalStepWrapper, ModalWrapper, WalletButton, WalletButtonGroup } from '../../../../components/Base'; +import { ModalStepWrapper, ModalWrapper } from '../../../../components/Base'; import { useModal } from '../../../../components/ModalProvider'; import useDevice from '../../../../hooks/useDevice'; import useSendPasswordResetEmail from '../../../../hooks/useSendPasswordResetEmail'; import { PlatformDetails } from '../../constants'; -import { CFDSuccess, CreatePassword, EnterPassword } from '../../screens'; +import { CreatePasswordModal } from '../CreatePasswordModal'; +import { EnterPasswordModal } from '../EnterPasswordModal'; import { PasswordLimitExceededModal } from '../PasswordLimitExceededModal'; +import { SuccessModal } from '../SuccessModal'; import './DxtradeEnterPasswordModal.scss'; const DxtradeEnterPasswordModal = () => { @@ -81,158 +83,6 @@ const DxtradeEnterPasswordModal = () => { } }, [dxtradePlatform, hide, isDxtradePasswordNotSet, isMobile, isResetPasswordSuccessful, show]); - const renderFooter = useMemo(() => { - if (isCreateAccountSuccessful) { - if (accountType === 'demo') { - return ( -
- - OK - -
- ); - } - return ( - - hide()} size={isMobile ? 'lg' : 'md'} variant='outlined'> - Maybe later - - { - hide(); - history.push('/wallets/cashier/transfer', { toAccountLoginId: createdAccount?.account_id }); - }} - size={isMobile ? 'lg' : 'md'} - > - Transfer funds - - - ); - } - - if (!isDxtradePasswordNotSet) { - return ( - - { - sendEmail({ - platform: dxtradePlatform, - }); - }} - size={isMobile ? 'lg' : 'md'} - variant='outlined' - > - Forgot password? - - - Add account - - - ); - } - - return ( - - {`Create ${PlatformDetails.dxtrade.title} password`} - - ); - }, [ - accountType, - createdAccount?.account_id, - dxtradePlatform, - hide, - history, - isCreateAccountSuccessful, - isDxtradePasswordNotSet, - isLoading, - isMobile, - isResetPasswordLoading, - onSubmit, - password, - sendEmail, - ]); - - const successComponent = useMemo(() => { - if (isCreateAccountSuccessful && dxtradeAccountListSuccess) { - return ( - renderFooter} - title={`Your ${PlatformDetails.dxtrade.title}${ - accountType === 'demo' ? ` ${accountType}` : '' - } account is ready`} - /> - ); - } - }, [ - isCreateAccountSuccessful, - dxtradeAccountListSuccess, - successDescription, - dxtradeBalance, - dxtradePlatform, - accountType, - renderFooter, - ]); - - const passwordComponent = useMemo(() => { - if (!isCreateAccountSuccessful && accountStatusSuccess) { - return isDxtradePasswordNotSet ? ( - setPassword(e.target.value)} - onPrimaryClick={onSubmit} - password={password} - platform={dxtradePlatform} - /> - ) : ( - setPassword(e.target.value)} - onPrimaryClick={onSubmit} - onSecondaryClick={() => { - sendEmail({ - platform: dxtradePlatform, - }); - }} - password={password} - passwordError={error?.error?.code === 'PasswordError'} - platform={dxtradePlatform} - setPassword={setPassword} - /> - ); - } - }, [ - isCreateAccountSuccessful, - accountStatusSuccess, - isDxtradePasswordNotSet, - isLoading, - onSubmit, - password, - dxtradePlatform, - isResetPasswordLoading, - error?.error?.code, - sendEmail, - ]); - if (status === 'error' && error?.error?.code === 'PasswordReset') { return ( { /> ); } - if (status === 'error' && error?.error?.code !== 'PasswordError') { return ; } @@ -260,20 +109,50 @@ const DxtradeEnterPasswordModal = () => { ); } - if (isMobile) { + if (!isCreateAccountSuccessful && accountStatusSuccess) { + return isDxtradePasswordNotSet ? ( + setPassword(e.target.value)} + onPrimaryClick={onSubmit} + password={password} + platform={dxtradePlatform} + /> + ) : ( + setPassword(e.target.value)} + onPrimaryClick={onSubmit} + onSecondaryClick={() => { + sendEmail({ + platform: dxtradePlatform, + }); + }} + password={password} + passwordError={error?.error?.code === 'PasswordError'} + platform={dxtradePlatform} + setPassword={setPassword} + /> + ); + } + if (isCreateAccountSuccessful && dxtradeAccountListSuccess) { return ( - renderFooter} title={' '}> - {successComponent} - {passwordComponent} - + { + hide(); + history.push('/wallets/cashier/transfer', { toAccountLoginId: createdAccount?.account_id }); + }} + onSecondaryClick={hide} + platform={dxtradePlatform} + /> ); } - return ( - - {successComponent} - {passwordComponent} - - ); + return null; }; export default DxtradeEnterPasswordModal; diff --git a/packages/wallets/src/features/cfd/modals/EnterPasswordModal/EnterPasswordModal.tsx b/packages/wallets/src/features/cfd/modals/EnterPasswordModal/EnterPasswordModal.tsx new file mode 100644 index 000000000000..cafb7d2fe4cd --- /dev/null +++ b/packages/wallets/src/features/cfd/modals/EnterPasswordModal/EnterPasswordModal.tsx @@ -0,0 +1,87 @@ +import React, { ComponentProps, FC } from 'react'; +import { ModalStepWrapper, ModalWrapper, WalletButton, WalletButtonGroup } from '../../../../components'; +import useDevice from '../../../../hooks/useDevice'; +import { PlatformDetails } from '../../constants'; +import { EnterPassword } from '../../screens'; + +const EnterPasswordModal: FC> = ({ + isForgotPasswordLoading, + isLoading, + marketType, + onPasswordChange, + onPrimaryClick, + onSecondaryClick, + password, + passwordError, + platform, + setPassword, +}) => { + const { isMobile } = useDevice(); + + const title = `Enter your ${PlatformDetails[platform].title} password`; + + if (isMobile) { + return ( + { + return ( + + + Forgot password? + + + Add account + + + ); + }} + title={title} + > + + + ); + } + + return ( + + + + ); +}; + +export default EnterPasswordModal; diff --git a/packages/wallets/src/features/cfd/modals/EnterPasswordModal/index.ts b/packages/wallets/src/features/cfd/modals/EnterPasswordModal/index.ts new file mode 100644 index 000000000000..f765028f7a42 --- /dev/null +++ b/packages/wallets/src/features/cfd/modals/EnterPasswordModal/index.ts @@ -0,0 +1 @@ +export { default as EnterPasswordModal } from './EnterPasswordModal'; diff --git a/packages/wallets/src/features/cfd/modals/SuccessModal/SuccessModal.tsx b/packages/wallets/src/features/cfd/modals/SuccessModal/SuccessModal.tsx new file mode 100644 index 000000000000..0ec10b805f79 --- /dev/null +++ b/packages/wallets/src/features/cfd/modals/SuccessModal/SuccessModal.tsx @@ -0,0 +1,75 @@ +import React, { ComponentProps, FC } from 'react'; +import { useActiveWalletAccount } from '@deriv/api-v2'; +import { ModalStepWrapper, ModalWrapper, WalletButton, WalletButtonGroup } from '../../../../components'; +import useDevice from '../../../../hooks/useDevice'; +import { PlatformDetails } from '../../constants'; +import { CFDSuccess } from '../../screens'; + +type TProps = Omit, 'title'> & { + onPrimaryClick?: () => void; + onSecondaryClick?: () => void; +}; + +const SuccessModal: FC = ({ + description, + displayBalance = '', + marketType = 'all', + onPrimaryClick, + onSecondaryClick, + platform = 'dxtrade', +}) => { + const { isMobile } = useDevice(); + const { data: activeWallet } = useActiveWalletAccount(); + const accountType = activeWallet?.is_virtual ? 'demo' : 'real'; + const title = `Your ${PlatformDetails[platform].title}${ + accountType === 'demo' ? ` ${accountType}` : '' + } account is ready`; + + const renderButton = () => { + return accountType === 'demo' ? ( +
+ + OK + +
+ ) : ( + + + Maybe later + + + Transfer funds + + + ); + }; + + if (isMobile) { + return ( + + + + ); + } + + return ( + + + + ); +}; + +export default SuccessModal; diff --git a/packages/wallets/src/features/cfd/modals/SuccessModal/index.ts b/packages/wallets/src/features/cfd/modals/SuccessModal/index.ts new file mode 100644 index 000000000000..259dad886e14 --- /dev/null +++ b/packages/wallets/src/features/cfd/modals/SuccessModal/index.ts @@ -0,0 +1 @@ +export { default as SuccessModal } from './SuccessModal'; diff --git a/packages/wallets/src/features/cfd/screens/EnterPassword/EnterPassword.tsx b/packages/wallets/src/features/cfd/screens/EnterPassword/EnterPassword.tsx index 2b06e82fa7b5..2ea3fcca6c85 100644 --- a/packages/wallets/src/features/cfd/screens/EnterPassword/EnterPassword.tsx +++ b/packages/wallets/src/features/cfd/screens/EnterPassword/EnterPassword.tsx @@ -11,6 +11,7 @@ type TProps = { isForgotPasswordLoading?: boolean; isLoading?: boolean; marketType: TMarketTypes.CreateOtherCFDAccount; + modalTitle?: string; onPasswordChange?: (e: React.ChangeEvent) => void; onPrimaryClick?: () => void; onSecondaryClick?: () => void; @@ -24,6 +25,7 @@ const EnterPassword: React.FC = ({ isForgotPasswordLoading, isLoading, marketType, + modalTitle, onPasswordChange, onPrimaryClick, onSecondaryClick, @@ -49,9 +51,11 @@ const EnterPassword: React.FC = ({ return (
- - Enter your {title} password - + {isDesktop && ( + + {modalTitle} + + )}
Enter your {title} password to add a{' '}