Skip to content

Commit 39c1841

Browse files
authored
Suisin/chore: fix blank screen issue (#18107)
* chore: fix blank screen issue * chore: fix logout scenario redirect issue * chore: empty commit
1 parent c72eaf6 commit 39c1841

File tree

4 files changed

+52
-13
lines changed

4 files changed

+52
-13
lines changed

packages/core/src/App/Containers/Redirect/redirect.jsx

Lines changed: 48 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,26 @@
1-
import { useEffect } from 'react';
1+
import { useEffect, useState } from 'react';
2+
import { useHistory, withRouter } from 'react-router-dom';
3+
import Cookies from 'js-cookie';
24
import PropTypes from 'prop-types';
3-
import { withRouter, useHistory } from 'react-router-dom';
4-
import { loginUrl, routes, redirectToLogin, SessionStore, getDomainName } from '@deriv/shared';
5+
6+
import { useOauth2 } from '@deriv/hooks';
7+
import { getDomainName, loginUrl, redirectToLogin, routes, SessionStore } from '@deriv/shared';
58
import { observer, useStore } from '@deriv/stores';
69
import { getLanguage } from '@deriv/translations';
7-
import { WS } from 'Services';
8-
import { Analytics } from '@deriv-com/analytics';
9-
import Cookies from 'js-cookie';
1010
import { Chat } from '@deriv/utils';
11+
import { Analytics } from '@deriv-com/analytics';
12+
import { requestOidcAuthentication } from '@deriv-com/auth-client';
13+
14+
import { WS } from 'Services';
1115

1216
const Redirect = observer(() => {
1317
const history = useHistory();
1418
const { client, ui } = useStore();
19+
const { isOAuth2Enabled } = useOauth2({});
20+
const [queryCurrency, setQueryCurrency] = useState('USD');
1521

1622
const {
23+
authorize_accounts_list,
1724
currency,
1825
has_wallet,
1926
is_logged_in,
@@ -22,6 +29,8 @@ const Redirect = observer(() => {
2229
setVerificationCode,
2330
verification_code,
2431
setPreventRedirectToHub,
32+
switchAccount,
33+
is_client_store_initialized,
2534
} = client;
2635

2736
const {
@@ -321,10 +330,29 @@ const Redirect = observer(() => {
321330
default:
322331
break;
323332
}
333+
324334
useEffect(() => {
325-
if (!redirected_to_route && history.location.pathname !== routes.traders_hub) {
326-
const account_currency = url_params.get('account');
327-
const client_account_lists = JSON.parse(localStorage.getItem('client.accounts'));
335+
const account_currency = url_params.get('account');
336+
setQueryCurrency(account_currency);
337+
}, []);
338+
339+
useEffect(() => {
340+
const account_currency = queryCurrency;
341+
if (!redirected_to_route && history.location.pathname !== routes.traders_hub && is_client_store_initialized) {
342+
const client_account_lists = JSON.parse(localStorage.getItem('client.accounts') || '{}');
343+
const is_correct_currency = authorize_accounts_list.some(
344+
account => account.currency?.toUpperCase() === account_currency?.toUpperCase()
345+
);
346+
const currency_exists = Object.values(client_account_lists).some(
347+
account => account.currency?.toUpperCase() === account_currency?.toUpperCase()
348+
);
349+
if (!currency_exists && is_correct_currency && authorize_accounts_list.length > 0) {
350+
if (isOAuth2Enabled) {
351+
requestOidcAuthentication({
352+
redirectCallbackUri: `${window.location.origin}/callback`,
353+
});
354+
}
355+
}
328356

329357
if (account_currency) {
330358
let matching_loginid;
@@ -341,7 +369,8 @@ const Redirect = observer(() => {
341369
);
342370
}
343371

344-
if (matching_loginid) {
372+
if (matching_loginid && is_client_store_initialized) {
373+
switchAccount(matching_loginid);
345374
sessionStorage.setItem('active_loginid', matching_loginid);
346375
}
347376
}
@@ -363,16 +392,23 @@ const Redirect = observer(() => {
363392
);
364393

365394
let updated_search = url_query_string;
395+
const params = new URLSearchParams(url_query_string);
396+
params.set('account', queryCurrency);
366397
if (matched_route && matched_route.type) {
367-
updated_search = `${url_query_string}&trade_type=${matched_route.type}`;
398+
updated_search = `${params.toString()}`;
368399
}
369400

401+
sessionStorage.setItem(
402+
'tradershub_redirect_to',
403+
matched_route ? `redirect?${updated_search}` : default_route
404+
);
405+
370406
history.push({
371407
pathname: matched_route ? matched_route.route : default_route,
372408
search: updated_search,
373409
});
374410
}
375-
}, [redirected_to_route, url_query_string, history]);
411+
}, [redirected_to_route, url_query_string, history, is_client_store_initialized, authorize_accounts_list]);
376412

377413
return null;
378414
});

packages/core/src/App/app.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ const AppWithoutTranslation = ({ root_store }) => {
5454
const url_query_string = window.location.search;
5555
const url_params = new URLSearchParams(url_query_string);
5656
const account_currency = url_params.get('account');
57-
const client_account_lists = JSON.parse(localStorage.getItem('client.accounts'));
57+
const client_account_lists = JSON.parse(localStorage.getItem('client.accounts') ?? '{}');
5858

5959
if (account_currency) {
6060
let matching_loginid, matching_wallet_loginid;

packages/core/src/Modules/Callback/CallbackPage.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const CallbackPage = () => {
1616

1717
const redirectTo = sessionStorage.getItem('tradershub_redirect_to');
1818
if (redirectTo) {
19+
sessionStorage.removeItem('tradershub_redirect_to');
1920
window.location.href = redirectTo;
2021
} else {
2122
window.location.href = routes.traders_hub;

packages/core/src/Stores/client-store.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ export default class ClientStore extends BaseStore {
5959
upgrade_info;
6060
email;
6161
accounts = {};
62+
authorize_accounts_list = [];
6263
is_trading_platform_available_account_loaded = false;
6364
trading_platform_available_accounts = [];
6465
ctrader_trading_platform_available_accounts = [];
@@ -1472,6 +1473,7 @@ export default class ClientStore extends BaseStore {
14721473
};
14731474

14741475
updateAccountList(account_list) {
1476+
this.authorize_accounts_list = account_list;
14751477
account_list.forEach(account => {
14761478
if (this.accounts[account.loginid]) {
14771479
this.accounts[account.loginid].excluded_until = account.excluded_until || '';

0 commit comments

Comments
 (0)