Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added logic to manually set server_url and app_id for staging-p2p #133

Merged
merged 2 commits into from
Jun 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions src/constants/url.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -13,9 +13,33 @@ export const DERIV_COM = URLConstants.derivComProduction;
export const HELP_CENTRE = `${URLConstants.derivComProduction}/help-centre/`;
export const RESPONSIBLE = `${URLConstants.derivComProduction}/responsible/`;

const SocketURL = {
[URLConstants.derivP2pProduction]: 'blue.derivws.com',
[URLConstants.derivP2pStaging]: 'red.derivws.com',
};

export const getOauthUrl = () => {
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 === URLConstants.derivP2pStaging) {
localStorage.setItem(
LocalStorageConstants.configServerURL.toString(),
SocketURL[hostname as keyof typeof SocketURL]
);
localStorage.setItem(
LocalStorageConstants.configAppId,
AppIDConstants.domainAppId[hostname as keyof typeof AppIDConstants.domainAppId]
);
}

const storedServerUrl = localStorage.getItem(LocalStorageConstants.configServerURL.toString());
const serverUrl = /qa/.test(storedServerUrl || '') ? storedServerUrl : 'oauth.deriv.com';

const appId = LocalStorageUtils.getValue(LocalStorageConstants.configAppId);
const serverUrl = localStorage.getItem(LocalStorageConstants.configServerURL.toString());

const oauthUrl =
appId && serverUrl
? `https://${serverUrl}/oauth2/authorize?app_id=${appId}&l=EN&&brand=deriv`
Expand Down
Loading