Skip to content

Commit

Permalink
adrienne/refactor: account ready modal to success modal (binary-com#1…
Browse files Browse the repository at this point in the history
…0740)

* chore: backup

* refactor: renamed account ready modal to success modal

* refactor: renamed account ready modal to success modal

* chore: used wallet text, waiting for line height

* chore: removed unused css

* chore: backup before merge

* chore: fix eslint types

* chore: fix eslint types

* chore: fix issue where svg has checkbox jurisdiction

* chore: fix eslint sort issue
  • Loading branch information
adrienne-deriv committed Oct 18, 2023
1 parent df32de0 commit 01398de
Show file tree
Hide file tree
Showing 14 changed files with 165 additions and 116 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type TMarketTypes = React.ComponentProps<typeof MT5AccountType>['selectedMarketT

type TModalState = {
marketType?: TMarketTypes;
platform?: string;
};

const ModalContext = createContext<TModalContext | null>(null);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import React, { ComponentType, SVGAttributes } from 'react';
import DerivedMT5Icon from '../../public/images/mt5-derived.svg';
import DerivXIcon from '../../public/images/derivx.svg';
import CTraderIcon from '../../public/images/ctrader.svg';
import FinancialMT5Icon from '../../public/images/mt5-financial.svg';
import SwapFreeMT5Icon from '../../public/images/mt5-swap-free.svg';
import { WalletCardIcon } from '../WalletCardIcon';
import { WalletGradientBackground } from '../WalletGradientBackground';
import type { useSortedMT5Accounts } from '@deriv/api';
import './WalletMarketCurrencyIcon.scss';

const marketTypeToIconMapper: Record<string, ComponentType<SVGAttributes<SVGElement>>> = {
Expand All @@ -12,14 +15,23 @@ const marketTypeToIconMapper: Record<string, ComponentType<SVGAttributes<SVGElem
synthetic: DerivedMT5Icon,
};

const marketTypeToPlatformIconMapper: Record<string, ComponentType<SVGAttributes<SVGElement>>> = {
ctrader: CTraderIcon,
dxtrade: DerivXIcon,
};

type TWalletMarketCurrencyIconProps = {
currency: string;
isDemo: boolean;
marketType: string;
marketType: Exclude<NonNullable<ReturnType<typeof useSortedMT5Accounts>['data']>[number]['market_type'], undefined>;
platform: string;
};

const WalletMarketCurrencyIcon = ({ currency, isDemo, marketType }: TWalletMarketCurrencyIconProps) => {
const MarketTypeIcon = marketTypeToIconMapper[marketType];
const WalletMarketCurrencyIcon = ({ currency, isDemo, marketType, platform }: TWalletMarketCurrencyIconProps) => {
const MarketTypeIcon =
marketType === 'all' && Object.keys(marketTypeToPlatformIconMapper).includes(platform)
? marketTypeToPlatformIconMapper[platform]
: marketTypeToIconMapper[marketType];

return (
<div className='wallets-market-currency-icon'>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { TradingAccountCard } from '../../../../components';
import { WalletButton } from '../../../../components/Base';
import CTrader from '../../../../public/images/ctrader.svg';
import './CTraderList.scss';
import { useModal } from '../../../../components/ModalProvider';
import { MT5PasswordModal } from '../../modals';

const ctraderMapper = [
{
Expand All @@ -13,6 +15,8 @@ const ctraderMapper = [
];

const CTraderList: React.FC = () => {
const { show } = useModal();

return (
<div className='wallets-ctrader'>
<div className='wallets-ctrader__title'>
Expand All @@ -24,7 +28,13 @@ const CTraderList: React.FC = () => {
{...account}
key={`ctrader--${account.title}`}
leading={() => <div className='wallets-ctrader__content__icon'>{account.icon}</div>}
trailing={() => <WalletButton color='primary-light' text='Get' />}
trailing={() => (
<WalletButton
color='primary-light'
onClick={() => show(<MT5PasswordModal marketType='all' platform='ctrader' />)}
text='Get'
/>
)}
>
<div className='wallets-ctrader__content__details'>
<p className='wallets-ctrader__content__details-title'>{account.title}</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ const AvailableMT5AccountsList: React.FC<TProps> = ({ account }) => {
});
show(
activeWallet?.is_virtual ? (
<MT5PasswordModal marketType={account?.market_type || 'synthetic'} />
<MT5PasswordModal
marketType={account?.market_type || 'synthetic'}
platform={account.platform}
/>
) : (
<JurisdictionModal />
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
import React, { useState } from 'react';
import { useActiveWalletAccount, useCreateOtherCFDAccount } from '@deriv/api';
import { ModalWrapper } from '../../../../components/Base';
import { ModalWrapper, WalletButton } from '../../../../components/Base';
import DxTradePasswordIcon from '../../../../public/images/ic-dxtrade-password.svg';
import { AccountReady, CreatePassword } from '../../screens';
import { Success, CreatePassword } from '../../screens';
import './DxtradeEnterPasswordModal.scss';
import { useModal } from '../../../../components/ModalProvider';

const DxtradeEnterPasswordModal = () => {
const [password, setPassword] = useState('');
const { isSuccess, mutate } = useCreateOtherCFDAccount();
const { data: activeWallet } = useActiveWalletAccount();
const { hide } = useModal();
const accountType = activeWallet?.is_virtual ? 'demo' : 'real';

const onSubmit = () => {
mutate({
payload: {
account_type: activeWallet?.is_virtual ? 'demo' : 'real',
account_type: accountType,
market_type: 'all',
password,
platform: 'dxtrade',
Expand All @@ -23,7 +26,15 @@ const DxtradeEnterPasswordModal = () => {

return (
<ModalWrapper hideCloseButton={isSuccess}>
{isSuccess && <AccountReady marketType='all' />}
{isSuccess && (
<Success
description={`You can now start practicing trading with your Deriv X ${accountType} account.`}
marketType='all'
platform='dxtrade'
renderButton={() => <WalletButton isFullWidth onClick={hide} size='lg' text='Continue' />}
title={`Your Deriv X ${accountType} account is ready`}
/>
)}
{!isSuccess && (
<CreatePassword
icon={<DxTradePasswordIcon />}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const JurisdictionModal = () => {
const { isLoading } = useAvailableMT5Accounts();

const marketType = modalState?.marketType || 'all';
const platform = modalState?.platform || 'mt5';

const capitalizedMarketType = marketTypeToTitleMapper[marketType];

Expand All @@ -27,7 +28,7 @@ const JurisdictionModal = () => {
renderFooter={() => (
<WalletButton
disabled={!selectedJurisdiction}
onClick={() => show(<MT5PasswordModal marketType={marketType} />)}
onClick={() => show(<MT5PasswordModal marketType={marketType} platform={platform} />)}
text='Next'
/>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,42 @@ import {
useSettings,
useSortedMT5Accounts,
} from '@deriv/api';
import { ModalWrapper } from '../../../../components/Base';
import { ModalWrapper, WalletButton } from '../../../../components/Base';
import MT5PasswordIcon from '../../../../public/images/ic-mt5-password.svg';
import { AccountReady, CreatePassword, EnterPassword } from '../../screens';
import { Success, CreatePassword, EnterPassword } from '../../screens';
import { useModal } from '../../../../components/ModalProvider';

type TProps = {
marketType: Exclude<NonNullable<ReturnType<typeof useSortedMT5Accounts>['data']>[number]['market_type'], undefined>;
platform: string;
};

const MT5PasswordModal: React.FC<TProps> = ({ marketType }) => {
const marketTypeToTitleMapper: Record<TProps['marketType'], string> = {
all: 'Swap-Free',
financial: 'MT5 Financial',
synthetic: 'MT5 Derived',
};

const marketTypeToPlatformTitleMapper: Record<string, string> = {
ctrader: 'cTrader',
dxtrade: 'Deriv X',
};

const MT5PasswordModal: React.FC<TProps> = ({ marketType, platform }) => {
const [password, setPassword] = useState('');
const { isSuccess, mutate } = useCreateMT5Account();
const { data: activeWallet } = useActiveWalletAccount();
const { data: mt5Accounts } = useMT5AccountsList();
const { data: availableMT5Accounts } = useAvailableMT5Accounts();
const { data: settings } = useSettings();
const { hide } = useModal();

const hasMT5Account = mt5Accounts?.find(account => account.login);
const isDemo = activeWallet?.is_virtual;
const marketTypeTitle =
marketType === 'all' && Object.keys(marketTypeToPlatformTitleMapper).includes(platform)
? marketTypeToPlatformTitleMapper[platform]
: marketTypeToTitleMapper[marketType];

const onSubmit = () => {
const accountType = marketType === 'synthetic' ? 'gaming' : marketType;
Expand All @@ -49,7 +69,17 @@ const MT5PasswordModal: React.FC<TProps> = ({ marketType }) => {

return (
<ModalWrapper hideCloseButton={isSuccess}>
{isSuccess && <AccountReady marketType={marketType} />}
{isSuccess && (
<Success
description={`You can now start practicing trading with your ${marketTypeTitle} ${
isDemo ? ' demo' : 'real'
} account.`}
marketType={marketType}
platform={platform}
renderButton={() => <WalletButton isFullWidth onClick={hide} size='lg' text='Continue' />}
title={`Your ${marketTypeTitle} ${isDemo ? ' demo' : 'real'} account is ready`}
/>
)}
{!isSuccess &&
(hasMT5Account ? (
<EnterPassword
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const JurisdictionScreen: FC<TJurisdictionScreenProps> = ({ selectedJurisdiction
))}
</div>

{selectedJurisdiction && (
{selectedJurisdiction && selectedJurisdiction !== 'svg' && (
<div className='wallets-jurisdiction-screen__tnc'>
Add Your Deriv MT5 Financial account under Deriv (V) Ltd, regulated by the Vanuatu Financial
Services Commission.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
.wallets-account-ready {
.wallets-success {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
padding: 16px;
padding: 16px 24px;
gap: 24px;
width: 392px;
border-radius: 10px;
Expand All @@ -20,27 +20,6 @@
position: relative;
border-radius: 10px;

&__text {
&--type {
font-weight: 400;
line-height: 14px;
font-size: 10px;
}

&--wallet {
font-size: 10px;
font-weight: 400;
line-height: 14px;
color: #999999;
}

&--amount {
font-size: 14px;
font-weight: 700;
line-height: 20px;
}
}

&-badge {
position: absolute;
top: 0;
Expand All @@ -63,17 +42,6 @@
}
}

&__title {
font-weight: 700;
font-size: 16px;
line-height: 24px;
}

&__subtitle {
font-size: 14px;
line-height: 20px;
}

&__button {
background-color: #ff444f;
color: #ffffff;
Expand Down
Loading

0 comments on commit 01398de

Please sign in to comment.