Skip to content

Commit

Permalink
[UPM-1431] Suisin/chore: update new design changes on withdrawal limi…
Browse files Browse the repository at this point in the history
…ts (deriv-com#17217)

* chore: update new design changes on withdrawal limits

* chore: remove unused scss from code base

* chore: update to use localize function instead of Localize component

* chore: fix mobile design not same

* chore: empty commit
  • Loading branch information
suisin-deriv authored Oct 31, 2024
1 parent cbd9d49 commit d49dcc5
Show file tree
Hide file tree
Showing 12 changed files with 289 additions and 154 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -349,71 +349,6 @@ describe('<AccountLimits/>', () => {
expect(screen.getByTestId('withdrawal_limits_table')).toHaveTextContent('Limit');
});

it('show show withdrawal limit lifted message if is_fully_authenticated is true', () => {
render(
<StoreProvider store={store}>
<AccountLimits {...props} />
</StoreProvider>
);

expect(
screen.getByText(/your account is fully authenticated and your withdrawal limits have been lifted\./i)
).toBeInTheDocument();
});

it('withdrawal_limits_table should show `Total withdrawal allowed` when is_fully_authenticated is false', () => {
store = mockStore({
client: {
...mock.client,
is_fully_authenticated: false,
},
});
render(
<StoreProvider store={store}>
<AccountLimits {...props} />
</StoreProvider>
);
expect(screen.getByText(/total withdrawal allowed/i)).toBeInTheDocument();
});

it('should show limit_notice message when is_fully_authenticated is false in responsive mode', () => {
store = mockStore({
client: {
...mock.client,
is_fully_authenticated: false,
},
});
(useDevice as jest.Mock).mockReturnValueOnce({ isDesktop: false });
render(
<BrowserRouter>
<StoreProvider store={store}>
<AccountLimits {...props} />
</StoreProvider>
</BrowserRouter>
);
expect(screen.getByText(/stated limits are subject to change without prior notice\./i)).toBeInTheDocument();
});

it('should not show limit_notice message when is_fully_authenticated is false', () => {
store = mockStore({
client: {
...mock.client,
is_fully_authenticated: false,
},
});
(useDevice as jest.Mock).mockReturnValueOnce({ isDesktop: true });
render(
<BrowserRouter>
<StoreProvider store={store}>
<AccountLimits {...props} is_app_settings={false} />
</StoreProvider>
</BrowserRouter>
);
expect(
screen.queryByText(/your account is fully authenticated and your withdrawal limits have been lifted\./i)
).not.toBeInTheDocument();
});

it('should show AccountLimitsArticle when should_show_article and isDesktop is true', () => {
store = mockStore(mock);
(useDevice as jest.Mock).mockReturnValueOnce({ isDesktop: true });
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import WithdrawalLimitsTable from '../withdrawal-limits-table';
import { mockStore, StoreProvider } from '@deriv/stores';
import { useGetWithdrawalLimitsDetails } from '@deriv/hooks';
import userEvent from '@testing-library/user-event';

jest.mock('@deriv/hooks', () => ({
useGetWithdrawalLimitsDetails: jest.fn(),
}));

describe('WithdrawalLimitsTable', () => {
const store = mockStore({});

beforeEach(() => {
jest.clearAllMocks();
});

const renderComponent = () =>
render(
<StoreProvider store={store}>
<WithdrawalLimitsTable />
</StoreProvider>
);

const constant_title = ['Withdrawal limits', 'Limit (USD)'];

it('should renders the withdrawal limits table correctly', () => {
(useGetWithdrawalLimitsDetails as jest.Mock).mockReturnValue({
withdrawal_limit_details: [
{
withdrawal_title: 'Lifetime limit',
withdrawal_info_message: 'Lifetime limit info',
withdrawal_amount: 10000,
},
{
withdrawal_title: '30-day limit',
withdrawal_info_message: '30-day limit info',
withdrawal_amount: 5000,
},
],
});

renderComponent();

constant_title.map(title => expect(screen.getByText(title)).toBeInTheDocument());

expect(screen.getByText(/Lifetime limit/)).toBeInTheDocument();
expect(screen.getByText(/10,000/)).toBeInTheDocument();

expect(screen.getByText(/30-day limit/)).toBeInTheDocument();
expect(screen.getByText(/5,000/)).toBeInTheDocument();
});

it('should render withdrawal_info_message on mouse hover on the info icon', () => {
(useGetWithdrawalLimitsDetails as jest.Mock).mockReturnValue({
withdrawal_limit_details: [
{
withdrawal_title: 'Lifetime limit',
withdrawal_info_message: 'Lifetime limit info',
withdrawal_amount: 10000,
},
],
});

renderComponent();
expect(screen.queryByText(/Lifetime limit info/)).not.toBeInTheDocument();
const pop_over_icon = screen.getByTestId('dt_popover_wrapper');
userEvent.hover(pop_over_icon);
expect(screen.queryByText(/Lifetime limit info/)).toBeInTheDocument();
});

it('should not render any value if withdrawal_limit_details is empty', () => {
(useGetWithdrawalLimitsDetails as jest.Mock).mockReturnValue({
withdrawal_limit_details: [],
});

renderComponent();

constant_title.map(title => expect(screen.getByText(title)).toBeInTheDocument());

expect(screen.queryByText(/Lifetime limit/)).not.toBeInTheDocument();
expect(screen.queryByText(/10,000/)).not.toBeInTheDocument();

expect(screen.queryByText(/30-day limit/)).not.toBeInTheDocument();
expect(screen.queryByText(/5,000/)).not.toBeInTheDocument();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,17 @@ import { useDevice } from '@deriv-com/ui';

type TAccountLimitsExtraInfo = {
message: string;
should_display_in_info_tooltip?: boolean;
className?: string;
};

const AccountLimitsExtraInfo = ({ message, ...props }: TAccountLimitsExtraInfo) => {
const AccountLimitsExtraInfo = ({
message,
should_display_in_info_tooltip = false,
...props
}: TAccountLimitsExtraInfo) => {
const { isDesktop } = useDevice();
if (!isDesktop) {
if (!isDesktop && !should_display_in_info_tooltip) {
return (
<Text color='less-prominent' line_height='s' size='xxxs'>
{message}
Expand All @@ -19,7 +24,7 @@ const AccountLimitsExtraInfo = ({ message, ...props }: TAccountLimitsExtraInfo)
return (
<Popover
data_testid='dt_acc_limits_popover'
alignment='right'
alignment={isDesktop ? 'right' : 'top'}
className='da-account-limits__popover'
icon='info'
is_bubble_hover_enabled
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ type TAccountLimitsTableCell = {
align: 'right' | 'left';
is_hint: boolean;
level: string;
className?: string;
renderExtraInfo: () => ReactElement;
};

Expand All @@ -15,12 +16,13 @@ const AccountLimitsTableCell = ({
is_hint,
level,
renderExtraInfo,
className,
}: PropsWithChildren<Partial<TAccountLimitsTableCell>>) => {
const text_size = is_hint ? 'xxxs' : 'xxs';

return (
<td
className={clsx('da-account-limits__table-cell', {
className={clsx('da-account-limits__table-cell', className, {
'da-account-limits__table-cell--left': align !== 'right',
'da-account-limits__table-cell--right': align === 'right',
'da-account-limits__table-cell--submarket': level === 'submarket',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@
&--submarket {
padding-left: 1rem;
}
&--withdrawal-limit {
@include mobile-or-tablet-screen {
flex-direction: row;
}
}
}

&-wrapper {
Expand All @@ -70,10 +75,6 @@
}
}

&__text-container {
margin: 1.2rem 1.2rem 1.2rem 0;
}

&__popover {
margin-inline-start: 0.8rem;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,13 +237,7 @@ const AccountLimits = observer(
</table>
{/* We only show "Withdrawal Limits" on account-wide settings pages. */}

{!is_app_settings && (
<WithdrawalLimitsTable
num_of_days_limit={num_of_days_limit}
remainder={remainder}
withdrawal_since_inception_monetary={withdrawal_since_inception_monetary}
/>
)}
{!is_app_settings && <WithdrawalLimitsTable />}
</ThemedScrollbars>
</div>
{should_show_article && isDesktop && <AccountLimitsArticle />}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,85 +1,60 @@
import { Fragment } from 'react';
import { Text } from '@deriv/components';
import { FormatUtils, CurrencyConstants } from '@deriv-com/utils';
import { Localize } from '@deriv/translations';
import { observer, useStore } from '@deriv/stores';
import AccountLimitsTableCell from './account-limits-table-cell';
import AccountLimitsTableHeader from './account-limits-table-header';
import AccountLimitsExtraInfo from './account-limits-extra-info';
import { useGetWithdrawalLimitsDetails } from '@deriv/hooks';

type TWithdrawalLimitsTable = {
num_of_days_limit?: string | number;
withdrawal_since_inception_monetary?: string | number;
remainder?: string | number;
};
const WithdrawalLimitsTable = observer(() => {
const { client } = useStore();
const { withdrawal_limit_details } = useGetWithdrawalLimitsDetails();
const { currency } = client;

const WithdrawalLimitsTable = observer(
({ num_of_days_limit, withdrawal_since_inception_monetary, remainder }: TWithdrawalLimitsTable) => {
const { client } = useStore();
const { currency, is_fully_authenticated } = client;
return (
<Fragment>
<table className='da-account-limits__table' data-testid='withdrawal_limits_table'>
<thead>
<tr>
<AccountLimitsTableHeader>
<Localize i18n_default_text='Withdrawal limits' />
</AccountLimitsTableHeader>
{is_fully_authenticated && (
<AccountLimitsTableHeader align='right'>
<Localize i18n_default_text='Limit' />
</AccountLimitsTableHeader>
)}
</tr>
</thead>
<tbody>
{!is_fully_authenticated && (
<Fragment>
<tr>
<AccountLimitsTableCell>
<Localize i18n_default_text='Total withdrawal allowed' />
</AccountLimitsTableCell>
<AccountLimitsTableCell align='right'>
{FormatUtils.formatMoney((num_of_days_limit as number) ?? 0, {
return (
<Fragment>
<table className='da-account-limits__table' data-testid='withdrawal_limits_table'>
<thead>
<tr>
<AccountLimitsTableHeader>
<Localize i18n_default_text='Withdrawal limits' />
</AccountLimitsTableHeader>
<AccountLimitsTableHeader align='right'>
<Localize i18n_default_text='Limit (USD)' />
</AccountLimitsTableHeader>
</tr>
</thead>
<tbody>
<Fragment>
{withdrawal_limit_details.map((withdrawal_limit_detail, index) => (
<tr key={index}>
<AccountLimitsTableCell
className='da-account-limits__table-cell--withdrawal-limit'
renderExtraInfo={() => (
<AccountLimitsExtraInfo
should_display_in_info_tooltip
message={withdrawal_limit_detail.withdrawal_info_message}
/>
)}
>
{withdrawal_limit_detail.withdrawal_title}
</AccountLimitsTableCell>
<AccountLimitsTableCell align='right'>
{FormatUtils.formatMoney(
(withdrawal_limit_detail.withdrawal_amount as number) ?? 0,
{
currency: currency as CurrencyConstants.Currency,
})}
</AccountLimitsTableCell>
</tr>
<tr>
<AccountLimitsTableCell>
<Localize i18n_default_text='Total withdrawn' />
</AccountLimitsTableCell>
<AccountLimitsTableCell align='right'>
{FormatUtils.formatMoney((withdrawal_since_inception_monetary as number) ?? 0, {
currency: currency as CurrencyConstants.Currency,
})}
</AccountLimitsTableCell>
</tr>
<tr>
<AccountLimitsTableCell>
<Localize i18n_default_text='Maximum withdrawal remaining' />
</AccountLimitsTableCell>
<AccountLimitsTableCell align='right'>
{FormatUtils.formatMoney((remainder as number) ?? 0, {
currency: currency as CurrencyConstants.Currency,
})}
</AccountLimitsTableCell>
</tr>
</Fragment>
)}
</tbody>
</table>
<div className='da-account-limits__text-container'>
<Text as='p' size='xxs' color='less-prominent' line_height='xs'>
{is_fully_authenticated ? (
<Localize i18n_default_text='Your account is fully authenticated and your withdrawal limits have been lifted.' />
) : (
<Localize i18n_default_text='Stated limits are subject to change without prior notice.' />
)}
</Text>
</div>
</Fragment>
);
}
);
}
)}
</AccountLimitsTableCell>
</tr>
))}
</Fragment>
</tbody>
</table>
</Fragment>
);
});

export default WithdrawalLimitsTable;
Loading

0 comments on commit d49dcc5

Please sign in to comment.