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

[Wallets] Responsive view for success and password modal #10871

Merged
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,18 @@
grid-template-rows: 9% auto;

&--fixed {
grid-template-rows: 9% auto 8%;
grid-template-rows: 7% auto 8%;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reduced the header height

}
}

&__header {
padding: 2rem;
padding: 0 2rem;
border-bottom: 2px solid #f2f3f4;
display: flex;
justify-content: space-between;
align-items: center;
display: grid;
grid-template-columns: auto 4%;

&-close-icon {
yashim-deriv marked this conversation as resolved.
Show resolved Hide resolved
cursor: pointer;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
.wallets-button-group {
display: flex;
width: 100%;
gap: 1.2rem;

&--vertical {
flex-direction: column;
}

&__item {
width: 100%;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import React from 'react';
import { type WalletButton } from '../WalletButton';
import './WalletButtonGroup.scss';
import classNames from 'classnames';

type TWalletButtonGroupProps = {
isVertical?: boolean;
};

const WalletButtonGroup: React.FC<React.PropsWithChildren<TWalletButtonGroupProps>> = ({ children, isVertical }) => {
return (
<div
className={classNames('wallets-button-group', {
'wallets-button-group--vertical': isVertical,
})}
>
{Children.map(children, child => (

Check failure on line 17 in packages/wallets/src/components/Base/WalletButtonGroup/WalletButtonGroup.tsx

View workflow job for this annotation

GitHub Actions / Build And Test

Cannot find name 'Children'. Did you mean 'children'?

Check failure on line 17 in packages/wallets/src/components/Base/WalletButtonGroup/WalletButtonGroup.tsx

View workflow job for this annotation

GitHub Actions / Build And Test

Parameter 'child' implicitly has an 'any' type.
<div className='wallets-button-group__item'>{child}</div>
yashim-deriv marked this conversation as resolved.
Show resolved Hide resolved
))}
</div>
);
};

export default WalletButtonGroup;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a new base component to group buttons.
Screenshot 2023-10-23 at 1 30 51 PM

Screenshot 2023-10-23 at 1 30 57 PM

Adding isVertical option allows the button grouping to be grouped vertically:
Screenshot 2023-10-23 at 1 31 04 PM

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default as WalletButtonGroup } from './WalletButtonGroup';
1 change: 1 addition & 0 deletions packages/wallets/src/components/Base/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export * from './ProgressBar';
export * from './Tabs';
export * from './WalletAlertMessage';
export * from './WalletButton';
export * from './WalletButtonGroup';
export * from './WalletClipboard';
export * from './WalletText';
export * from './WalletTextField';
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import SwapFreeMT5Icon from '../../public/images/mt5-swap-free.svg';
import { WalletCardIcon } from '../WalletCardIcon';
import { WalletGradientBackground } from '../WalletGradientBackground';
import type { useSortedMT5Accounts } from '@deriv/api';
import useDevice from '../../hooks/useDevice';
import './WalletMarketCurrencyIcon.scss';

const marketTypeToIconMapper: Record<string, ComponentType<SVGAttributes<SVGElement>>> = {
Expand All @@ -28,6 +29,8 @@ type TWalletMarketCurrencyIconProps = {
};

const WalletMarketCurrencyIcon = ({ currency, isDemo, marketType, platform }: TWalletMarketCurrencyIconProps) => {
const { isMobile } = useDevice();

const MarketTypeIcon =
marketType === 'all' && Object.keys(marketTypeToPlatformIconMapper).includes(platform)
? marketTypeToPlatformIconMapper[platform]
Expand All @@ -42,7 +45,7 @@ const WalletMarketCurrencyIcon = ({ currency, isDemo, marketType, platform }: TW
}`}
>
<WalletGradientBackground currency={currency} hasShine isDemo={isDemo} type='card'>
<WalletCardIcon type={isDemo ? 'Demo' : currency} />
<WalletCardIcon size={isMobile ? 'xl' : 'lg'} type={isDemo ? 'Demo' : currency} />
</WalletGradientBackground>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.wallets-mt5-password-modal {
&__footer {
width: 100%;

&--pair {
display: grid;
grid-template-columns: 1fr 1fr;
grid-gap: 10px;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ import {
useSettings,
useTradingPlatformPasswordChange,
} from '@deriv/api';
import { ModalWrapper, WalletButton } from '../../../../components/Base';
import { ModalStepWrapper, ModalWrapper, WalletButton, WalletButtonGroup } from '../../../../components/Base';
import { useModal } from '../../../../components/ModalProvider';
import MT5PasswordIcon from '../../../../public/images/ic-mt5-password.svg';
import { CreatePassword, EnterPassword, Success } from '../../screens';
import { TMarketTypes, TPlatforms } from '../../types';
import useDevice from '../../../../hooks/useDevice';
import './MT5PasswordModal.scss';
import { MarketTypeToTitleMapper, PlatformToTitleMapper } from '../../constants';

type TProps = {
Expand All @@ -28,6 +30,7 @@ const MT5PasswordModal: React.FC<TProps> = ({ marketType, platform }) => {
const { data: availableMT5Accounts } = useAvailableMT5Accounts();
const { data: settings } = useSettings();
const { hide } = useModal();
const { isMobile } = useDevice();

const hasMT5Account = mt5Accounts?.find(account => account.login);
const isDemo = activeWallet?.is_virtual;
Expand Down Expand Up @@ -68,6 +71,70 @@ const MT5PasswordModal: React.FC<TProps> = ({ marketType, platform }) => {
});
};

const renderTitle = () => {
if (!isSuccess && hasMT5Account) return `Enter your ${PlatformToTitleMapper.mt5} password`;
return '';
};

const renderFooter = () => {
if (isSuccess) return <WalletButton isFullWidth onClick={hide} size='lg' text='Continue' />;
if (hasMT5Account)
return (
<WalletButtonGroup>
<WalletButton isFullWidth size='lg' text='Forgot password?' variant='outlined' />
<WalletButton disabled={!password} isFullWidth onClick={onSubmit} size='lg' text='Add account' />
</WalletButtonGroup>
);
return (
<WalletButton
disabled={!password}
isFullWidth
onClick={onSubmit}
size='lg'
text='Create Deriv MT5 Password'
/>
);
};

if (isMobile) {
return (
<ModalStepWrapper renderFooter={renderFooter} title={renderTitle()}>
{isSuccess && (
<Success
description={`You can now start practicing trading with your ${marketTypeTitle} ${
isDemo ? ' demo' : 'real'
} account.`}
displayBalance={
mt5Accounts?.find(account => account.market_type === marketType)?.display_balance || ''
}
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
marketType={marketType}
onPasswordChange={e => setPassword(e.target.value)}
onPrimaryClick={onSubmit}
password={password}
platform='mt5'
/>
) : (
<CreatePassword
icon={<MT5PasswordIcon />}
onPasswordChange={e => setPassword(e.target.value)}
onPrimaryClick={onSubmit}
password={password}
platform='mt5'
/>
))}
</ModalStepWrapper>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

EnterPassword

Screenshot 2023-10-23 at 2 32 24 PM

Success

Screenshot 2023-10-23 at 2 32 33 PM

CreatePassword

Screenshot 2023-10-23 at 2 32 45 PM

);
}

return (
<ModalWrapper hideCloseButton={isSuccess}>
{isSuccess && (
Expand All @@ -90,13 +157,15 @@ const MT5PasswordModal: React.FC<TProps> = ({ marketType, platform }) => {
marketType={marketType}
onPasswordChange={e => setPassword(e.target.value)}
onPrimaryClick={onSubmit}
password={password}
platform='mt5'
/>
) : (
<CreatePassword
icon={<MT5PasswordIcon />}
onPasswordChange={e => setPassword(e.target.value)}
onPrimaryClick={onSubmit}
password={password}
platform='mt5'
/>
))}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
border-radius: 8px;
background: var(--system-light-8-primary-background, #fff);

@include mobile {
width: 100%;
}

&-title {
font-weight: 700;
font-size: 18px;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,20 @@ import PasswordShowIcon from '../../../../public/images/ic-password-show.svg';
import './CreatePassword.scss';
import { TPlatforms } from '../../types';
import { PlatformToTitleMapper } from '../../constants';
import { WalletButton } from '../../../../components/Base';
import useDevice from '../../../../hooks/useDevice';

type TProps = {
icon: React.ReactNode;
onPasswordChange?: (e: React.ChangeEvent<HTMLInputElement>) => void;
onPrimaryClick: () => void;
password: string;
platform: TPlatforms.All;
};

const CreatePassword: React.FC<TProps> = ({ icon, onPasswordChange, onPrimaryClick, platform }) => {
const CreatePassword: React.FC<TProps> = ({ icon, onPasswordChange, onPrimaryClick, password, platform }) => {
const { isMobile } = useDevice();

const title = PlatformToTitleMapper[platform];
return (
<div className='wallets-create-password'>
Expand All @@ -24,9 +29,14 @@ const CreatePassword: React.FC<TProps> = ({ icon, onPasswordChange, onPrimaryCli
<input onChange={onPasswordChange} placeholder={`${title} password`} type='password' />
<PasswordShowIcon className='wallets-create-password-input-trailing-icon' />
</div>
<button className='wallets-create-password-button' onClick={onPrimaryClick}>
Create {title} password
</button>
{!isMobile && (
<WalletButton
disabled={!password}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed an issue where the button is not disabled when user has not entered any password. In design the button was disabled when input was empty

Screen.Recording.2023-10-23.at.1.15.49.PM.mov

onClick={onPrimaryClick}
size='lg'
text={`Create ${title} password`}
/>
)}
</div>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,23 @@
background: var(--system-light-8-primary-background, #fff);
box-shadow: 0px 0px 24px 0px rgba(0, 0, 0, 0.25);

@include mobile {
justify-content: flex-start;
border-radius: 0;
box-shadow: none;
}

&--container {
display: flex;
width: 400px;
padding: 0 24px 24px;
adrienne-deriv marked this conversation as resolved.
Show resolved Hide resolved
flex-direction: column;
align-items: flex-start;
gap: 8px;

@include mobile {
width: 100%;
}
}

&-title {
Expand Down
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use the components we already created from the base for this file 😃 👍🏼

Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ import PasswordShowIcon from '../../../../public/images/ic-password-show.svg';
import './EnterPassword.scss';
import { TMarketTypes, TPlatforms } from '../../types';
import { PlatformToTitleMapper } from '../../constants';
import useDevice from '../../../../hooks/useDevice';

type TProps = {
isLoading?: boolean;
marketType: TMarketTypes.CreateOtherCFDAccount;
onPasswordChange?: (e: React.ChangeEvent<HTMLInputElement>) => void;
onPrimaryClick?: () => void;
onSecondaryClick?: () => void;
password: string;
platform: TPlatforms.All;
};

Expand All @@ -19,32 +21,38 @@ const EnterPassword: React.FC<TProps> = ({
onPasswordChange,
onPrimaryClick,
onSecondaryClick,
password,
platform,
}) => {
const { isDesktop } = useDevice();
const title = PlatformToTitleMapper[platform];
return (
<React.Fragment>
<div className='wallets-enter-password'>
<div className='wallets-enter-password--container'>
<div className='wallets-enter-password-title'>Enter your {title} password</div>
<span className='wallets-enter-password-subtitle'>
Enter your {title} password to add a {title} {marketType} account.
</span>
<div className='wallets-enter-password-input'>
<input onChange={onPasswordChange} placeholder={`${title} password`} type='password' />
<PasswordShowIcon className='wallets-create-password-input-trailing-icon' />
</div>
<div className='wallets-enter-password'>
<div className='wallets-enter-password--container'>
{isDesktop && <div className='wallets-enter-password-title'>Enter your {title} password</div>}
<span className='wallets-enter-password-subtitle'>
Enter your {title} password to add a {title} {marketType} account.
</span>
<div className='wallets-enter-password-input'>
<input onChange={onPasswordChange} placeholder={`${title} password`} type='password' />
<PasswordShowIcon className='wallets-create-password-input-trailing-icon' />
</div>
</div>
{isDesktop && (
<div className='wallets-enter-password-buttons'>
<button className='wallets-enter-password-forgot-password-button' onClick={onSecondaryClick}>
Forgot password?
</button>
<button className='wallets-enter-password-add-button' disabled={isLoading} onClick={onPrimaryClick}>
<button
className='wallets-enter-password-add-button'
disabled={isLoading || !password}
onClick={onPrimaryClick}
>
Add account
</button>
</div>
</div>
</React.Fragment>
)}
</div>
);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
text-align: center;
background: var(--system-light-8-primary-background, #fff);

@include mobile {
width: 100%;
height: 100%;
}

&__info {
display: flex;
flex-direction: column;
Expand All @@ -20,6 +25,10 @@
position: relative;
border-radius: 10px;

@include mobile {
height: fit-content;
}

&-badge {
position: absolute;
top: 0;
Expand Down
Loading
Loading