Skip to content

Commit

Permalink
fix: fixed redirection back to dp2p (#7609)
Browse files Browse the repository at this point in the history
* fix: fixed redirection back to dp2p

* fix: pr comment resolved

* fix: show button for idv poi submission

* fix: pr comment fix

* fix: pr comment fix

* fix: added destructuring default value

* fix: style fix

* fix: moved inline function outside

* fix: style fix for redirect button in idv submit

* fix: check for p2p using platform param

* fix: removed unused function

* fix: changed param checking from p2p to dp2p

* fix: persist local storage value until cleared
  • Loading branch information
nada-deriv committed May 30, 2023
1 parent a8943ba commit e4b2c0c
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { localize } from '@deriv/translations';
type TIdvSubmitComplete = {
needs_poa: boolean;
is_from_external: boolean;
redirect_button: React.ReactNode;
redirect_button: React.ReactElement;
};

const IdvSubmitComplete = ({ needs_poa, is_from_external, redirect_button }: TIdvSubmitComplete) => {
Expand All @@ -30,7 +30,7 @@ const IdvSubmitComplete = ({ needs_poa, is_from_external, redirect_button }: TId
{poa_button}
</React.Fragment>
) : (
redirect_button
<div className='proof-of-identity__redirection'>{redirect_button}</div>
)}
</div>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ const ProofOfAddressContainer = ({
onClick={() => {
const url = platforms[from_platform.ref]?.url;
window.location.href = url;
window.localStorage.removeItem('config.platform');
}}
>
<Localize i18n_default_text='Back to {{platform_name}}' values={{ platform_name: from_platform.name }} />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Button, Loading } from '@deriv/components';
import { WS, getPlatformRedirect, platforms } from '@deriv/shared';
import { identity_status_codes, service_code } from './proof-of-identity-utils';

import DemoMessage from 'Components/demo-message';
import ErrorMessage from 'Components/error-component';
import Expired from 'Components/poi/status/expired';
Expand Down Expand Up @@ -98,22 +97,22 @@ const ProofOfIdentityContainer = ({
return <NotRequired />;
}

const redirect_button = should_show_redirect_btn ? (
<Button
primary
className='proof-of-identity__redirect'
onClick={() => {
if (platforms[from_platform.ref].is_hard_redirect) {
const url = platforms[from_platform.ref]?.url;
window.location.href = url;
} else {
routeBackTo(from_platform.route);
}
}}
>
const onClickRedirectButton = () => {
const platform = platforms[from_platform.ref];
const { is_hard_redirect = false, url = '' } = platform ?? {};
if (is_hard_redirect) {
window.location.href = url;
window.localStorage.removeItem('config.platform');
} else {
routeBackTo(from_platform.route);
}
};

const redirect_button = should_show_redirect_btn && (
<Button primary className='proof-of-identity__redirect' onClick={onClickRedirectButton}>
<Localize i18n_default_text='Back to {{platform_name}}' values={{ platform_name: from_platform.name }} />
</Button>
) : null;
);

if (
identity_status === identity_status_codes.none ||
Expand Down
14 changes: 13 additions & 1 deletion packages/account/src/Styles/account.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2276,6 +2276,19 @@ $MIN_HEIGHT_FLOATING: calc(
}
}

&__redirection {
.dc-btn {
margin-top: 3.2rem;
height: 4rem;

@include mobile {
margin: 1.6rem 0;
padding: 1.6rem;
width: 100%;
}
}
}

&__country-text {
margin-bottom: 1.6rem;
}
Expand All @@ -2284,7 +2297,6 @@ $MIN_HEIGHT_FLOATING: calc(
@include mobile {
width: 94%;
text-align: center;
margin-bottom: 9rem;
}
}

Expand Down
7 changes: 5 additions & 2 deletions packages/core/src/Stores/common-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,11 @@ export default class CommonStore extends BaseStore {
const search = window.location.search;
if (search) {
const url_params = new URLSearchParams(search);
this.platform = url_params.get('platform') || '';
localStorage.setItem('config.platform', this.platform);
const platform = url_params.get('platform');
if (platform) {
this.platform = platform;
localStorage.setItem('config.platform', this.platform);
}
}
}

Expand Down
10 changes: 9 additions & 1 deletion packages/p2p/src/components/verification/verification.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,15 @@ const Verification = ({ should_wrap }) => {
general_store.poi_status === 'verified'
? () => {}
: () => {
window.location.href = `${routes.proof_of_identity}?ext_platform_url=${routes.cashier_p2p}`;
const search = window.location.search;
let updated_url = `${routes.proof_of_identity}?ext_platform_url=${routes.cashier_p2p}`;
if (search) {
const url_params = new URLSearchParams(search);
const updated_url_params = new URLSearchParams(updated_url);
url_params.forEach((value, key) => updated_url_params.append(key, value));
updated_url = `${updated_url}&${url_params.toString()}`;
}
window.location.href = updated_url;
},
},
];
Expand Down
11 changes: 3 additions & 8 deletions packages/shared/src/utils/platform/platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ export const isDXtrade = () =>

export const isNavigationFromDerivGO = () => localStorage.getItem('config.platform') === 'derivgo';

export const isNavigationFromP2P = () => localStorage.getItem('config.platform') === 'dp2p';

export const getPathname = () => {
const { is_pathname_bot } = isBot();
if (is_pathname_bot) return platform_name.DBot;
Expand Down Expand Up @@ -115,8 +117,7 @@ export const getPlatformRedirect = (routing_history: TRoutingHistory) => {
return { name: platform_name.DXtrade, route: routes.dxtrade };
if (isNavigationFromExternalPlatform(routing_history, routes.smarttrader))
return { name: platform_name.SmartTrader, route: routes.smarttrader };
if (isNavigationFromP2P(routing_history, routes.cashier_p2p))
return { name: 'P2P', route: routes.cashier_p2p, ref: 'p2p' };
if (isNavigationFromP2P()) return { name: 'P2P', route: routes.cashier_p2p, ref: 'p2p' };
if (isNavigationFromExternalPlatform(routing_history, routes.binarybot))
return { name: platform_name.BinaryBot, route: routes.binarybot };
if (isNavigationFromDerivGO()) return { name: platform_name.DerivGO, route: '', ref: 'derivgo' };
Expand Down Expand Up @@ -165,12 +166,6 @@ export const isNavigationFromPlatform = (
return false;
};

export const isNavigationFromP2P = (routing_history: TRoutingHistory, platform_route: string) => {
const routing_history_index = routing_history.length > 1 ? 1 : 0;
const history_item = routing_history[routing_history_index];
return history_item?.pathname === platform_route;
};

export const isNavigationFromExternalPlatform = (routing_history: TRoutingHistory, platform_route: string) => {
/*
* Check if the client is navigating from external platform(SmartTrader or BinaryBot)
Expand Down

1 comment on commit e4b2c0c

@vercel
Copy link

@vercel vercel bot commented on e4b2c0c May 30, 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.vercel.app
binary.sx
deriv-app.binary.sx
deriv-app-git-master.binary.sx

Please sign in to comment.