Skip to content

Commit

Permalink
[Wallet] Farhan//WALL-2286/Wallet Added Success Modal (#11162)
Browse files Browse the repository at this point in the history
* feat: wallet added success modal

* chore: change max-width for desktop modal

* fix: remeove unnecessary props

* fix: code smell

* chore: use wallet actions screen for success modal, add test cases

* chore: separate component

* fix: text size

* fix: display balance
  • Loading branch information
farhan-nurzi-deriv committed Nov 7, 2023
1 parent aa2b605 commit 03e7bce
Show file tree
Hide file tree
Showing 34 changed files with 479 additions and 341 deletions.
15 changes: 12 additions & 3 deletions packages/api/src/hooks/useCreateWallet.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { useMemo } from 'react';
import useInvalidateQuery from '../useInvalidateQuery';
import useMutation from '../useMutation';
import useCurrencyConfig from './useCurrencyConfig';
import { displayMoney } from '../utils';

/** A custom hook to create new wallet account */
const useCreateWallet = () => {
const invalidate = useInvalidateQuery();
const { getConfig } = useCurrencyConfig();
const {
data,
mutate: _mutate,
Expand All @@ -19,9 +22,15 @@ const useCreateWallet = () => {

const modified_data = useMemo(() => {
if (!data?.new_account_wallet) return;

return data.new_account_wallet;
}, [data?.new_account_wallet]);
const currencyConfig = getConfig(data?.new_account_wallet.currency || 'USD');
return {
...data.new_account_wallet,
/** The balance of the account in currency format. */
display_balance: displayMoney(0, currencyConfig?.display_code || 'USD', {
fractional_digits: currencyConfig?.fractional_digits,
}),
};
}, [data?.new_account_wallet, getConfig]);

return {
/** New account information */
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useCallback, useEffect } from 'react';
import { useActiveWalletAccount, useCreateNewRealAccount, useSettings } from '@deriv/api';
import { toMoment } from '../../../../shared/src/utils/date';
import { Success } from '../../features/cfd/screens/Success';
import { CFDSuccess } from '../../features/cfd/screens/CFDSuccess';
import useDevice from '../../hooks/useDevice';
import DerivApps from '../../public/images/deriv-apps.svg';
import { ModalStepWrapper, WalletButton, WalletText } from '../Base';
Expand All @@ -25,7 +25,7 @@ const DerivAppsGetAccount: React.FC = () => {
renderFooter={isDesktop ? undefined : () => <DerivAppsSuccessFooter />}
shouldHideHeader={isDesktop}
>
<Success
<CFDSuccess
description={`Transfer funds from ${activeWallet?.wallet_currency_type} Wallet to your Deriv Apps (${landingCompanyName}) account to start trading.`}
displayBalance={activeWallet?.display_balance}
renderButton={() => <DerivAppsSuccessFooter />}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import React, { useCallback, useMemo } from 'react';
import useDevice from '../../hooks/useDevice';
import { THooks } from '../../types';
import { ModalStepWrapper, ModalWrapper, WalletButton, WalletButtonGroup } from '../Base';
import { WalletCard } from '../WalletCard';
import { WalletSuccess } from '../WalletSuccess';

type TWalletAddedSuccessProps = {
currency: THooks.CreateWallet['currency'];
displayBalance: THooks.CreateWallet['display_balance'];
landingCompany: THooks.CreateWallet['landing_company_shortcode'];
onPrimaryButtonClick: () => void;
onSecondaryButtonClick: () => void;
};

const WalletAddedSuccess: React.FC<TWalletAddedSuccessProps> = ({
currency,
displayBalance,
landingCompany,
onPrimaryButtonClick,
onSecondaryButtonClick,
}) => {
const { isMobile } = useDevice();
const description = 'Make a deposit into your new Wallet.';
const title = useMemo(
() => `Your ${currency} wallet (${landingCompany?.toUpperCase()}) is ready`,
[currency, landingCompany]
);
const renderFooter = useCallback(
() => (
<div className='wallets-add-more__success-footer'>
<WalletButtonGroup isFlex>
<WalletButton onClick={onSecondaryButtonClick} text='Maybe later' variant='outlined' />
<WalletButton onClick={onPrimaryButtonClick} text='Deposit' />
</WalletButtonGroup>
</div>
),
[onPrimaryButtonClick, onSecondaryButtonClick]
);
const renderIcon = useCallback(
() => (
<WalletCard
balance={displayBalance}
currency={currency || 'USD'}
landingCompanyName={landingCompany}
width='24rem'
/>
),
[currency, displayBalance, landingCompany]
);

if (isMobile)
return (
<ModalStepWrapper renderFooter={renderFooter} title=''>
<WalletSuccess description={description} renderIcon={renderIcon} title={title} />
</ModalStepWrapper>
);

return (
<ModalWrapper hideCloseButton>
<WalletSuccess
description={description}
renderButtons={renderFooter}
renderIcon={renderIcon}
title={title}
/>
</ModalWrapper>
);
};

export default WalletAddedSuccess;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default as WalletAddedSuccess } from './WalletAddedSuccess';
2 changes: 1 addition & 1 deletion packages/wallets/src/components/WalletCard/WalletCard.scss
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
&__details {
display: flex;
padding: 0.8rem;
min-width: 44.44vw;
min-width: 16rem;
flex-direction: column;
justify-content: space-between;
align-items: flex-start;
Expand Down
32 changes: 15 additions & 17 deletions packages/wallets/src/components/WalletCard/WalletCard.tsx
Original file line number Diff line number Diff line change
@@ -1,48 +1,46 @@
import React from 'react';
import { useBalance } from '@deriv/api';
import { THooks } from '../../types';
import { WalletText } from '../Base';
import { WalletCardIcon } from '../WalletCardIcon';
import { WalletGradientBackground } from '../WalletGradientBackground';
import { WalletListCardBadge } from '../WalletListCardBadge';
import './WalletCard.scss';

type TProps = {
account: THooks.WalletAccountsList;
balance: string;
currency: string;
isDemo?: boolean;
landingCompanyName?: string;
width?: React.CSSProperties['width'];
};

const WalletCard: React.FC<TProps> = ({ account }) => {
const WalletCard: React.FC<TProps> = ({ balance, currency, isDemo, landingCompanyName, width }) => {
const { isLoading } = useBalance();
return (
<div className='wallets-card'>
<WalletGradientBackground
currency={account?.wallet_currency_type || 'USD'}
currency={isDemo ? 'Demo' : currency}
device='mobile'
hasShine
isDemo={account?.is_virtual}
isDemo={isDemo}
type='card'
>
<div className='wallets-card__details'>
<div className='wallets-card__details' style={{ width }}>
<div className='wallets-card__details__top'>
<WalletCardIcon type={account?.wallet_currency_type} />
<WalletCardIcon type={isDemo ? 'Demo' : currency} />
<div className='wallets-card__details-landing_company'>
{account?.landing_company_name && (
<WalletListCardBadge
isDemo={account?.is_virtual}
label={account?.landing_company_name}
/>
)}
{landingCompanyName && <WalletListCardBadge isDemo={isDemo} label={landingCompanyName} />}
</div>
</div>
<div className='wallets-card__details__bottom'>
<WalletText color={account?.is_virtual ? 'white' : 'black'} size='2xs'>
{account?.currency} Wallet
<WalletText color={isDemo ? 'white' : 'black'} size='2xs'>
{currency} Wallet
</WalletText>
{isLoading ? (
<div className='wallets-skeleton wallets-card--balance-loader' />
) : (
<WalletText color={account?.is_virtual ? 'white' : 'black'} size='sm' weight='bold'>
{account?.display_balance}
<WalletText color={isDemo ? 'white' : 'black'} size='sm' weight='bold'>
{balance}
</WalletText>
)}
</div>
Expand Down
13 changes: 5 additions & 8 deletions packages/wallets/src/components/WalletError/WalletError.scss
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
.wallets-error {
width: 47.6rem;
padding: 3rem;
padding: 2.4rem;
border-radius: 0.4rem;
background: #fff;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
gap: 2.4rem;
flex-shrink: 0;

@include mobile {
width: 90vw;
display: flex;
align-items: center;
width: 100%;
height: 100%;
}
}
34 changes: 23 additions & 11 deletions packages/wallets/src/components/WalletError/WalletError.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import React, { ComponentProps } from 'react';
import useDevice from '../../hooks/useDevice';
import ErrorIcon from '../../public/images/error-icon.svg';
import { ModalStepWrapper } from '../Base';
import WalletButton from '../Base/WalletButton/WalletButton';
import WalletsActionScreen from '../WalletsActionScreen/WalletsActionScreen';
import './WalletError.scss';

type TProps = {
buttonText?: string;
buttonVariant?: ComponentProps<typeof WalletButton>['variant'];
errorMessage: string;
onClick?: () => void;
title?: string;
type?: 'modal' | 'page';
};

const WalletError: React.FC<TProps> = ({
Expand All @@ -18,18 +20,28 @@ const WalletError: React.FC<TProps> = ({
errorMessage,
onClick,
title,
type = 'page',
}) => {
const { isDesktop, isMobile } = useDevice();

return (
<WalletsActionScreen
actionText={buttonText}
actionVariant={buttonVariant}
description={errorMessage}
icon={<ErrorIcon />}
onAction={onClick}
title={title}
type={type}
/>
<ModalStepWrapper shouldHideHeader={isDesktop}>
<div className='wallets-error'>
<WalletsActionScreen
description={errorMessage}
icon={<ErrorIcon />}
renderButtons={() => (
<WalletButton
isFullWidth={isMobile}
onClick={onClick}
size='lg'
text={buttonText}
variant={buttonVariant}
/>
)}
title={title}
/>
</div>
</ModalStepWrapper>
);
};

Expand Down
16 changes: 16 additions & 0 deletions packages/wallets/src/components/WalletSuccess/WalletSuccess.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
.wallets-success {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
padding: 2.4rem;
width: 39.2rem;
border-radius: 1rem;
text-align: center;
background: var(--system-light-8-primary-background, #fff);

@include mobile {
width: 100%;
height: calc(100% - 8.5rem);
}
}
26 changes: 26 additions & 0 deletions packages/wallets/src/components/WalletSuccess/WalletSuccess.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import React, { ComponentProps, ReactNode } from 'react';
import WalletsActionScreen from '../WalletsActionScreen/WalletsActionScreen';
import './WalletSuccess.scss';

type TSuccessProps = {
description: string;
renderButtons?: ComponentProps<typeof WalletsActionScreen>['renderButtons'];
renderIcon: () => ReactNode;
title: string;
};

const WalletSuccess: React.FC<TSuccessProps> = ({ description, renderButtons, renderIcon, title }) => {
return (
<div className='wallets-success'>
<WalletsActionScreen
desciptionSize='sm'
description={description}
icon={renderIcon()}
renderButtons={renderButtons}
title={title}
/>
</div>
);
};

export default WalletSuccess;
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import WalletSuccess from '../WalletSuccess';

describe('<WalletSuccess />', () => {
it('should render with the info provided', () => {
render(
<WalletSuccess
description='Your new wallet account created'
renderIcon={() => <i data-testid='dt-success-icon'>Icon</i>}
title='Account created'
/>
);

expect(screen.getByText('Your new wallet account created')).toBeInTheDocument();
expect(screen.getByText('Account created')).toBeInTheDocument();
expect(screen.getByTestId('dt-success-icon')).toBeInTheDocument();
});

it('should render with the buttons', () => {
const mockRenderButtons = jest.fn(() => <button data-testid='dt-button'>Button</button>);

render(
<WalletSuccess
description='Your new wallet account created'
renderButtons={mockRenderButtons}
renderIcon={() => <i data-testid='dt-success-icon'>Icon</i>}
title='Account created'
/>
);

expect(mockRenderButtons).toHaveBeenCalled();
expect(screen.getByTestId('dt-button')).toBeInTheDocument();
});
});
1 change: 1 addition & 0 deletions packages/wallets/src/components/WalletSuccess/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default as WalletSuccess } from './WalletSuccess';
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,7 @@
align-items: center;
gap: 2.4rem;

&__modal {
padding: 2.4rem;
border-radius: 0.8rem;
background: #fff;
box-shadow: 0px 32px 64px 0px rgba(14, 14, 14, 0.14);

@include mobile {
width: 90vw;
}
}

&__content {
&__info {
display: flex;
flex-direction: column;
gap: 0.8rem;
Expand Down
Loading

1 comment on commit 03e7bce

@vercel
Copy link

@vercel vercel bot commented on 03e7bce Nov 7, 2023

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

deriv-app – ./

deriv-app.binary.sx
deriv-app-git-master.binary.sx
deriv-app.vercel.app
binary.sx

Please sign in to comment.