From 232f914b1d746216e0a82f4f1123b280da36bf0a Mon Sep 17 00:00:00 2001 From: shayan khaleghparast Date: Fri, 14 Jun 2024 17:02:26 +0800 Subject: [PATCH 1/2] feat: added logic to manually set server_url and app_id for staging-p2p --- src/constants/url.ts | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/src/constants/url.ts b/src/constants/url.ts index f50ce1a2..74e06310 100644 --- a/src/constants/url.ts +++ b/src/constants/url.ts @@ -1,4 +1,4 @@ -import { LocalStorageConstants, LocalStorageUtils, URLConstants, URLUtils } from '@deriv-com/utils'; +import { AppIDConstants, LocalStorageConstants, LocalStorageUtils, URLConstants, URLUtils } from '@deriv-com/utils'; export const BUY_SELL_URL = '/buy-sell'; export const ORDERS_URL = '/orders'; @@ -13,9 +13,32 @@ export const DERIV_COM = URLConstants.derivComProduction; export const HELP_CENTRE = `${URLConstants.derivComProduction}/help-centre/`; export const RESPONSIBLE = `${URLConstants.derivComProduction}/responsible/`; +const SocketURL = { + 'p2p.deriv.com': 'blue.derivws.com', + 'staging-p2p.deriv.com': 'red.derivws.com', +}; + export const getOauthUrl = () => { - const appId = LocalStorageUtils.getValue(LocalStorageConstants.configAppId); + const hostname = window.location.hostname; + + // since we don't have official app_id for staging, + // we will use the red server with app_id=62019 for the staging-p2p.deriv.com for now + // to fix the login issue + if (hostname === 'staging-p2p.deriv.com') { + localStorage.setItem( + LocalStorageConstants.configServerURL.toString(), + SocketURL[hostname as keyof typeof SocketURL] + ); + localStorage.setItem( + LocalStorageConstants.configAppId, + AppIDConstants.domainAppId[hostname as keyof typeof AppIDConstants.domainAppId] + ); + } + const serverUrl = localStorage.getItem(LocalStorageConstants.configServerURL.toString()); + + const appId = LocalStorageUtils.getValue(LocalStorageConstants.configAppId); + const oauthUrl = appId && serverUrl ? `https://${serverUrl}/oauth2/authorize?app_id=${appId}&l=EN&&brand=deriv` From 56a316702615744291972a28be34a1e4cc3f9bf4 Mon Sep 17 00:00:00 2001 From: shayan khaleghparast Date: Fri, 14 Jun 2024 17:49:53 +0800 Subject: [PATCH 2/2] chore: resolved pr comments --- src/constants/url.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/constants/url.ts b/src/constants/url.ts index 74e06310..f5f53e62 100644 --- a/src/constants/url.ts +++ b/src/constants/url.ts @@ -14,17 +14,17 @@ export const HELP_CENTRE = `${URLConstants.derivComProduction}/help-centre/`; export const RESPONSIBLE = `${URLConstants.derivComProduction}/responsible/`; const SocketURL = { - 'p2p.deriv.com': 'blue.derivws.com', - 'staging-p2p.deriv.com': 'red.derivws.com', + [URLConstants.derivP2pProduction]: 'blue.derivws.com', + [URLConstants.derivP2pStaging]: 'red.derivws.com', }; export const getOauthUrl = () => { - const hostname = window.location.hostname; + const hostname = window.location.origin; // since we don't have official app_id for staging, // we will use the red server with app_id=62019 for the staging-p2p.deriv.com for now // to fix the login issue - if (hostname === 'staging-p2p.deriv.com') { + if (hostname === URLConstants.derivP2pStaging) { localStorage.setItem( LocalStorageConstants.configServerURL.toString(), SocketURL[hostname as keyof typeof SocketURL] @@ -35,7 +35,8 @@ export const getOauthUrl = () => { ); } - const serverUrl = localStorage.getItem(LocalStorageConstants.configServerURL.toString()); + const storedServerUrl = localStorage.getItem(LocalStorageConstants.configServerURL.toString()); + const serverUrl = /qa/.test(storedServerUrl || '') ? storedServerUrl : 'oauth.deriv.com'; const appId = LocalStorageUtils.getValue(LocalStorageConstants.configAppId);