Skip to content

Commit

Permalink
Merge pull request #2145 from Nuzhy-Deriv/nuzhy/domain-list
Browse files Browse the repository at this point in the history
Nuzhy/_/Domain list AppID
  • Loading branch information
prince-deriv authored Nov 6, 2024
2 parents da8c3be + de0c192 commit 6e49004
Showing 1 changed file with 35 additions and 19 deletions.
54 changes: 35 additions & 19 deletions public/scripts/freshchat-temp.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,51 @@
class FreshChat {
const DERIV_APP = "app.deriv.com";
const STAGING_DERIV_APP = "staging-app.deriv.com";
const UAT_DERIV_APP = "uat-app.deriv.com";

const SMART_TRADER = "smarttrader.deriv.com";
const STAGING_SMART_TRADER = "staging-smarttrader.deriv.com";

const DOMAIN_LIST_APP_ID = {
[DERIV_APP]: "16929",
"app.deriv.be": "16929",
"app.deriv.me": "16929",
[STAGING_DERIV_APP]: "16930",
"staging-app.deriv.me": "16930",
"staging-app.deriv.be": "16930",
[UAT_DERIV_APP]: "16929",
"test-app.deriv.com": "16929",

[SMART_TRADER]: "22168",
"smarttrader.deriv.me": "22168",
"smarttrader.deriv.be": "22168",
[STAGING_SMART_TRADER]: "22169",
"staging-smarttrader.deriv.be": "22169",
"staging-smarttrader.deriv.me": "22169",
};

const getAppID = () => {
const host = window.location.hostname;
return DOMAIN_LIST_APP_ID[host] || "16929";
};

class FreshChat {
constructor({ token = null, hideButton = false } = {}) {
this.authToken = token;
this.hideButton = hideButton;
this.hostname = localStorage.getItem("config.server_url") || this.getServerUrl().url;
this.appId = localStorage.getItem("config.app_id") || this.getServerUrl().appId;
this.getServerUrl().appId;
const config_url = localStorage.getItem("config.server_url");
const config_appID = localStorage.getItem("config.app_id");
this.hostname = config_url && config_url.trim() !== "" ? config_url : "green.derivws.com";
this.appId = config_appID && config_appID.trim() !== "" ? config_appID : getAppID();
this.init();
}

getServerUrl = () => {
const urlParts = window.location.hostname.split('.');

if (urlParts.length <= 2) return { url: null, appId: null };

const subdomain = urlParts.slice(0, -2).join(".");
const mappings = {
app: { url: "green.derivws.com", appId: 16929 },
smarttrader: { url: "green.derivws.com", appId: 22168 }
};

return mappings[subdomain] || { url: null, appId: null };
};

static async initialize(options) {
return new FreshChat(options);
}

init = async () => {
let jwt = null;
if (this.authToken && this.appId && this.hostname) {
if (this.authToken) {
jwt = await this.fetchJWTToken({
token: this.authToken,
appId: this.appId,
Expand Down

0 comments on commit 6e49004

Please sign in to comment.