Skip to content

Commit

Permalink
fix: update config url, appId
Browse files Browse the repository at this point in the history
  • Loading branch information
Nuzhy-Deriv committed Nov 4, 2024
1 parent 2541de9 commit 6738289
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions public/scripts/freshchat-temp.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,35 @@
class FreshChat {
hostname = localStorage.getItem("config.server_url") || "green.derivws.com";
appId = localStorage.getItem("config.app_id") || 16929;

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;
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) {
if (this.authToken && this.appId && this.hostname) {
jwt = await this.fetchJWTToken({
token: this.authToken,
appId: this.appId,
Expand Down

0 comments on commit 6738289

Please sign in to comment.