Skip to content

Commit

Permalink
Kate/80001/Remove unused query params from the URL on initialize (bin…
Browse files Browse the repository at this point in the history
…ary-com#7447)

* fix: add check for specific unused params in query

* refactor: rename const, lift them up, move logic to a separate self declared function

* fix: change the passing value for excludeParamsFromUrlQuery function
  • Loading branch information
kate-deriv authored and Carol Sachdeva committed Feb 9, 2023
1 parent 27dcfd3 commit d136c91
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
23 changes: 23 additions & 0 deletions packages/core/src/Stores/client-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
State,
deriv_urls,
filterUrlQuery,
excludeParamsFromUrlQuery,
getPropertyValue,
getUrlBinaryBot,
getUrlSmartTrader,
Expand Down Expand Up @@ -1504,6 +1505,21 @@ export default class ClientStore extends BaseStore {
const redirect_url = search_params?.get('redirect_url');
const code_param = search_params?.get('code');
const action_param = search_params?.get('action');
const unused_params = [
'type',
'acp',
'label',
'server',
'interface',
'cid',
'age',
'utm_source',
'first_name',
'second_name',
'email',
'phone',
'_filteredParams',
];

this.setIsLoggingIn(true);
const authorize_response = await this.setUserLogin(login_new_user);
Expand Down Expand Up @@ -1626,6 +1642,13 @@ export default class ClientStore extends BaseStore {
this.registerReactions();
this.setIsLoggingIn(false);
this.setInitialized(true);

history.replaceState(
null,
null,
window.location.href.replace(`${search}`, excludeParamsFromUrlQuery(search, unused_params))
);

return true;
}

Expand Down
6 changes: 6 additions & 0 deletions packages/shared/src/utils/url/url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,3 +171,9 @@ export const filterUrlQuery = (search_param: string, allowed_keys: string[]) =>
const filtered_queries = [...search_params].filter(kvp => allowed_keys.includes(kvp[0]));
return new URLSearchParams(filtered_queries || '').toString();
};

export const excludeParamsFromUrlQuery = (search_param: string, excluded_keys: string[]) => {
const search_params = new URLSearchParams(search_param);
const filtered_queries = [...search_params].filter(([key]) => !excluded_keys.includes(key));
return new URLSearchParams(filtered_queries || '').toString();
};

0 comments on commit d136c91

Please sign in to comment.