Skip to content

Commit

Permalink
Hirad/TRAH-4545/redirection from os to legacy (#17780)
Browse files Browse the repository at this point in the history
* chore: updating redirections for OutSystems redirection

* chore: adding poa and poi redirections

* chore: removed smart_trader

* chore: improving the code

* chore: changing variable names

* chore: added trade_type

* chore: added redirection for trade_types

* chore: adding some values to the redirection

* chore: added os settings redirection
  • Loading branch information
hirad-deriv authored Dec 12, 2024
1 parent c761926 commit 007ce3d
Showing 1 changed file with 28 additions and 3 deletions.
31 changes: 28 additions & 3 deletions packages/core/src/App/Containers/Redirect/redirect.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const Redirect = observer(() => {

const url_query_string = window.location.search;
const url_params = new URLSearchParams(url_query_string);
let redirected_to_route = false;

// TODO: remove this after oauth2 migration
// get data from cookies and populate local storage for clients
Expand Down Expand Up @@ -56,7 +57,6 @@ const Redirect = observer(() => {
window.LiveChatWidget?.call('maximize');
};

let redirected_to_route = false;
const action_param = url_params.get('action');
const code_param = url_params.get('code') || verification_code[action_param];
const ext_platform_url = url_params.get('ext_platform_url');
Expand Down Expand Up @@ -307,9 +307,34 @@ const Redirect = observer(() => {
}
useEffect(() => {
if (!redirected_to_route && history.location.pathname !== routes.traders_hub) {
const route_mappings = [
{ pattern: /accumulator/i, route: routes.trade, type: 'accumulator' },
{ pattern: /turbos/i, route: routes.trade, type: 'turboslong' },
{ pattern: /vanilla/i, route: routes.trade, type: 'vanillalongcall' },
{ pattern: /multiplier/i, route: routes.trade, type: 'multiplier' },
{ pattern: /proof-of-address/i, route: routes.proof_of_address, platform: 'tradershub_os' },
{ pattern: /proof-of-identity/i, route: routes.proof_of_identity, platform: 'tradershub_os' },
{ pattern: /personal-details/i, route: routes.personal_details, platform: 'tradershub_os' },
{ pattern: /dbot/i, route: routes.bot },
];

const default_route = routes.traders_hub;

const matched_route = route_mappings.find(({ pattern }) =>
pattern.test(url_query_string || history.location.search)
);

let updated_search = url_query_string;
if (matched_route && matched_route.type) {
updated_search = `${url_query_string}&trade_type=${matched_route.type}`;
}
if (matched_route && matched_route.platform) {
updated_search = `${url_query_string}&platform=${matched_route.platform}`;
}

history.push({
pathname: routes.traders_hub,
search: url_query_string,
pathname: matched_route ? matched_route.route : default_route,
search: updated_search,
});
}
}, [redirected_to_route, url_query_string, history]);
Expand Down

0 comments on commit 007ce3d

Please sign in to comment.