Skip to content

Commit

Permalink
Merge pull request #2205 from Nuzhy-Deriv/nuzhy/fcwidget-check
Browse files Browse the repository at this point in the history
nuzhy/_/condition to check fcWidget
  • Loading branch information
prince-deriv authored Nov 22, 2024
2 parents 380dcb2 + 1a38399 commit b1f8c9e
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 12 deletions.
8 changes: 6 additions & 2 deletions public/scripts/freshchat/freshchat-1.0.1.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,12 @@ class FreshChat {
constructor({ token = null, hideButton = false } = {}) {
this.authToken = token;
this.hideButton = hideButton;
const config_url = localStorage.getItem("config.server_url")?.replace(/^['"]+|['"]+$/g, "");
const config_appID = localStorage.getItem("config.app_id")?.replace(/^['"]+|['"]+$/g, "");
const config_url = localStorage
.getItem("config.server_url")
?.replace(/^['"]+|['"]+$/g, "");
const config_appID = localStorage
.getItem("config.app_id")
?.replace(/^['"]+|['"]+$/g, "");
this.hostname =
config_url && config_url.trim() !== "" ? config_url : "green.derivws.com";
this.appId =
Expand Down
25 changes: 19 additions & 6 deletions public/scripts/freshchat/v1.0.2.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,12 @@ class FreshChat {
constructor({ token = null, hideButton = false } = {}) {
this.authToken = token;
this.hideButton = hideButton;
const config_url = localStorage.getItem("config.server_url")?.replace(/^['"]+|['"]+$/g, "");
const config_appID = localStorage.getItem("config.app_id")?.replace(/^['"]+|['"]+$/g, "");
const config_url = localStorage
.getItem("config.server_url")
?.replace(/^['"]+|['"]+$/g, "");
const config_appID = localStorage
.getItem("config.app_id")
?.replace(/^['"]+|['"]+$/g, "");
this.hostname =
config_url && config_url.trim() !== "" ? config_url : "green.derivws.com";
this.appId =
Expand All @@ -46,7 +50,11 @@ class FreshChat {
}

static async initialize(options) {
return new FreshChat(options);
try {
return new FreshChat(options);
} catch (error) {
console.warn("Error initializing FreshChat:", error);
}
}

init = async () => {
Expand Down Expand Up @@ -81,9 +89,14 @@ class FreshChat {

script.onload = function () {
if (jwt) {
window.fcWidget?.user?.setProperties({
cf_user_jwt: jwt,
});
const checkWidget = setInterval(() => {
if (window.fcWidget?.user) {
window.fcWidget.user?.setProperties({
cf_user_jwt: jwt,
});
clearInterval(checkWidget);
}
}, 500);
}
};
};
Expand Down
17 changes: 13 additions & 4 deletions public/scripts/freshchat/v1.0.3.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@ class FreshChat {
}

static async initialize(options) {
return new FreshChat(options);
try {
return new FreshChat(options);
} catch (error) {
console.warn("Error initializing FreshChat:", error);
}
}

init = async () => {
Expand Down Expand Up @@ -89,9 +93,14 @@ class FreshChat {

script.onload = function () {
if (jwt) {
window.fcWidget?.user?.setProperties({
cf_user_jwt: jwt,
});
const checkWidget = setInterval(() => {
if (window.fcWidget?.user) {
window.fcWidget.user?.setProperties({
cf_user_jwt: jwt,
});
clearInterval(checkWidget);
}
}, 500);
}
};
};
Expand Down

0 comments on commit b1f8c9e

Please sign in to comment.