Skip to content

Commit

Permalink
Merge branch 'master' into migrate_svg_to_bvi_dvl
Browse files Browse the repository at this point in the history
  • Loading branch information
shaheer-deriv committed Sep 19, 2023
2 parents 417116a + 32bc244 commit ed58be9
Show file tree
Hide file tree
Showing 468 changed files with 6,770 additions and 5,513 deletions.
4 changes: 2 additions & 2 deletions packages/account/src/Components/Routes/binary-routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ const BinaryRoutes = (props: TBinaryRoutes) => {
}
>
<Switch>
{getRoutesConfig({ is_appstore }).map((route: TRoute, idx: number) => (
<RouteWithSubRoutes key={idx} {...route} {...props} />
{getRoutesConfig({ is_appstore }).map((route: TRoute) => (
<RouteWithSubRoutes key={`${route.getTitle?.()}-${route.path}`} {...route} {...props} />
))}
</Switch>
</React.Suspense>
Expand Down
4 changes: 2 additions & 2 deletions packages/account/src/Components/Routes/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { match, matchPath, RouteProps } from 'react-router';
import { routes } from '@deriv/shared';
import { TRouteConfig } from 'Types';

export const normalizePath = (path: string) => (/^\//.test(path) ? path : `/${path || ''}`); // Default to '/'
export const normalizePath = (path: string) => (path.startsWith('/') ? path : `/${path || ''}`); // Default to '/'

export const findRouteByPath = (path: string, routes_config?: TRouteConfig[]): RouteProps | undefined => {
let result: RouteProps | undefined;
Expand Down Expand Up @@ -31,7 +31,7 @@ export const findRouteByPath = (path: string, routes_config?: TRouteConfig[]): R
};

export const isRouteVisible = (route?: { is_authenticated: boolean }, is_logged_in?: boolean) =>
!(route && route.is_authenticated && !is_logged_in);
!(route?.is_authenticated && !is_logged_in);

export const getPath = (route_path: string, params: { [key: string]: string } = {}) =>
Object.keys(params).reduce((p, name) => p.replace(`:${name}`, params[name]), route_path);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const RouteWithSubRoutes = (route: TRouteWithSubRoutesProps) => {
);
}

const title = route.getTitle?.() || '';
const title = route.getTitle?.() ?? '';
document.title = `${title} | ${default_title}`;

alternateLinkTagChange();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const AccountLimitsTableCell = ({
{children}
</Text>
)}
{renderExtraInfo && renderExtraInfo()}
{renderExtraInfo?.()}
</td>
</React.Fragment>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const AccountLimitsTableHeader = ({
{children}
</Text>
)}
{renderExtraInfo && renderExtraInfo()}
{renderExtraInfo?.()}
</th>
);
};
Expand Down
140 changes: 20 additions & 120 deletions packages/account/src/Components/account-limits/account-limits.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import React from 'react';
import { FormikValues } from 'formik';
import classNames from 'classnames';
import { Loading, ThemedScrollbars, Text, ButtonLink } from '@deriv/components';
import { formatMoney, isDesktop, isMobile, useIsMounted, PlatformContext } from '@deriv/shared';
import { Loading, ThemedScrollbars } from '@deriv/components';
import { Localize, localize } from '@deriv/translations';
import LoadErrorMessage from 'Components/load-error-message';
import { observer, useStore } from '@deriv/stores';
import DemoMessage from 'Components/demo-message';
import LoadErrorMessage from 'Components/load-error-message';
import AccountLimitsArticle from './account-limits-article';
import AccountLimitsContext, { TAccountLimitsContext } from './account-limits-context';
import AccountLimitsExtraInfo from './account-limits-extra-info';
Expand All @@ -13,8 +15,7 @@ import AccountLimitsOverlay from './account-limits-overlay';
import AccountLimitsTableCell from './account-limits-table-cell';
import AccountLimitsTableHeader from './account-limits-table-header';
import AccountLimitsTurnoverLimitRow from './account-limits-turnover-limit-row';
import { observer, useStore } from '@deriv/stores';
import { FormikValues } from 'formik';
import WithdrawalLimitsTable from './withdrawal-limits-table';

type TAccountLimits = {
footer_ref?: React.RefObject<HTMLElement>;
Expand All @@ -36,20 +37,22 @@ const AccountLimits = observer(
should_show_article = true,
}: TAccountLimits) => {
const { client, common } = useStore();
const { account_limits, currency, getLimits, is_fully_authenticated, is_virtual, is_switching } = client;
const { account_limits, currency, getLimits, is_virtual, is_switching } = client;
const { is_from_derivgo } = common;
const isMounted = useIsMounted();
const [is_loading, setLoading] = React.useState(false);
const [is_overlay_shown, setIsOverlayShown] = React.useState(false);
const { is_appstore } = React.useContext(PlatformContext);

const handleGetLimitsResponse = () => {
if (isMounted()) setLoading(false);
};

React.useEffect(() => {
if (is_virtual) {
setLoading(false);
} else {
getLimits().then(() => {
if (isMounted()) setLoading(false);
});
getLimits().then(handleGetLimitsResponse);
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
Expand Down Expand Up @@ -105,9 +108,7 @@ const AccountLimits = observer(
}

const { commodities, forex, indices, synthetic_index } = { ...market_specific };
const forex_ordered = forex
?.slice()
.sort((a: FormikValues, b: FormikValues) => (a.name > b.name ? 1 : b.name > a.name ? -1 : 0));
const forex_ordered = forex?.slice().sort((a: FormikValues, b: FormikValues) => a.name.localeCompare(b.name));
const derived_ordered = synthetic_index
?.slice()
.sort((a: FormikValues, b: FormikValues) => (a.level > b.level ? 1 : -1));
Expand All @@ -131,7 +132,7 @@ const AccountLimits = observer(
<AccountLimitsArticle is_from_derivgo={is_from_derivgo} />
)}
<div className='da-account-limits__table-wrapper'>
<ThemedScrollbars is_bypassed={should_bypass_scrollbars || isMobile()}>
<ThemedScrollbars is_bypassed={!!should_bypass_scrollbars || isMobile()}>
<table className='da-account-limits__table' data-testid='trading_limit_item_table'>
<thead>
<tr>
Expand Down Expand Up @@ -232,115 +233,14 @@ const AccountLimits = observer(
</tbody>
</table>
{/* We only show "Withdrawal Limits" on account-wide settings pages. */}

{!is_app_settings && (
<React.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 ? (
<tr>
<AccountLimitsTableCell>
<React.Fragment>
<Text size='xxs' color='prominent'>
{localize(
'Your account is fully authenticated and your withdrawal limits have been lifted.'
)}
</Text>
</React.Fragment>
</AccountLimitsTableCell>
<AccountLimitsTableCell />
</tr>
) : (
<React.Fragment>
<tr>
<AccountLimitsTableCell>
{is_appstore ? (
<Localize i18n_default_text='Total withdrawal limit' />
) : (
<Localize i18n_default_text='Total withdrawal allowed' />
)}
{is_appstore && !is_fully_authenticated && (
<React.Fragment>
<Text
size={isMobile() ? 'xxxs' : 'xxs'}
className='account-management-table__verify'
color='less-prominent'
line_height='xs'
>
{localize(
'To increase limit please verify your identity'
)}
</Text>
<ButtonLink
to='/account/proof-of-identity'
size='small'
className='account-management-table__verify-button'
>
<Text
weight='bold'
color='colored-background'
size={isMobile() ? 'xxxs' : 'xxs'}
>
{localize('Verify')}
</Text>
</ButtonLink>
</React.Fragment>
)}
</AccountLimitsTableCell>
<AccountLimitsTableCell align='right'>
{formatMoney(currency, num_of_days_limit, true)}
</AccountLimitsTableCell>
</tr>
<tr>
<AccountLimitsTableCell>
<Localize i18n_default_text='Total withdrawn' />
</AccountLimitsTableCell>
<AccountLimitsTableCell align='right'>
{formatMoney(
currency,
withdrawal_since_inception_monetary,
true
)}
</AccountLimitsTableCell>
</tr>
<tr>
<AccountLimitsTableCell>
<Localize i18n_default_text='Maximum withdrawal remaining' />
</AccountLimitsTableCell>
<AccountLimitsTableCell align='right'>
{formatMoney(currency, remainder, true)}
</AccountLimitsTableCell>
</tr>
</React.Fragment>
)}
</tbody>
</table>
{(!is_appstore || isMobile()) && (
<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>
)}
</React.Fragment>
<WithdrawalLimitsTable
is_appstore={is_appstore}
num_of_days_limit={num_of_days_limit}
remainder={remainder}
withdrawal_since_inception_monetary={withdrawal_since_inception_monetary}
/>
)}
</ThemedScrollbars>
</div>
Expand Down
Loading

0 comments on commit ed58be9

Please sign in to comment.