From 2f71676fb7150620b29f528c8ebb84ff7b235022 Mon Sep 17 00:00:00 2001 From: aswathy-deriv Date: Thu, 29 Feb 2024 11:19:47 +0400 Subject: [PATCH] fix: sonar cloud issues --- src/common/websocket/config.ts | 85 +++++++++++++++++++++++++--------- 1 file changed, 64 insertions(+), 21 deletions(-) diff --git a/src/common/websocket/config.ts b/src/common/websocket/config.ts index 92dc95cda3c..74358d77655 100644 --- a/src/common/websocket/config.ts +++ b/src/common/websocket/config.ts @@ -71,46 +71,89 @@ const isLive = () => isProduction() || isStaging() || isBeta() const isLocalHost = () => isBrowser() && domain_config.local.hostname === window.location.hostname const url = isBrowser() && window.location.href const is_academy = isBrowser() && url.includes('academy') + +// const getAppId = (): null | number | string => { +// let app_id = null +// const user_app_id = '' // you can insert Application ID of your registered application here +// const url_app_id = window.sessionStorage.getItem('app_id') +// const config_app_id = window.localStorage.getItem('config.app_id') + +// if (isBrowser()) { +// const url_params = new URLSearchParams(window.location.search || '') +// const url_param_app_id = url_params.get('app_id') +// if (url_param_app_id) { +// window.sessionStorage.setItem('app_id', url_param_app_id) +// } + +// if (is_academy) { +// app_id = 37228 +// } else { +// if (url_app_id) { +// app_id = url_app_id +// } else if (config_app_id) { +// app_id = config_app_id +// } else if (isStaging()) { +// window.localStorage.removeItem('config.default_app_id') +// app_id = domain_config.staging.app_id +// } else if (isBeta()) { +// window.localStorage.removeItem('config.default_app_id') +// app_id = domain_config.beta.app_id +// } else if (user_app_id.length) { +// window.localStorage.setItem('config.default_app_id', user_app_id) // it's being used in endpoint chrome extension - please do not remove +// app_id = user_app_id +// } else if (isLocalHost()) { +// app_id = domain_config.local.app_id +// } else { +// window.localStorage.removeItem('config.default_app_id') +// app_id = isProduction() ? prod_app_id : domain_config.test.app_id +// } +// } +// } +// return app_id +// } const getAppId = (): null | number | string => { let app_id = null const user_app_id = '' // you can insert Application ID of your registered application here + if (isBrowser()) { const url_params = new URLSearchParams(window.location.search || '') const url_param_app_id = url_params.get('app_id') + let storage_app_id = null + if (url_param_app_id) { window.sessionStorage.setItem('app_id', url_param_app_id) + storage_app_id = url_param_app_id + } else { + storage_app_id = window.sessionStorage.getItem('app_id') } - const url_app_id = window.sessionStorage.getItem('app_id') const config_app_id = window.localStorage.getItem('config.app_id') if (is_academy) { app_id = 37228 + } else if (storage_app_id) { + app_id = storage_app_id + } else if (config_app_id) { + app_id = config_app_id + } else if (isStaging()) { + window.localStorage.removeItem('config.default_app_id') + app_id = domain_config.staging.app_id + } else if (isBeta()) { + window.localStorage.removeItem('config.default_app_id') + app_id = domain_config.beta.app_id + } else if (user_app_id.length) { + window.localStorage.setItem('config.default_app_id', user_app_id) + app_id = user_app_id + } else if (isLocalHost()) { + app_id = domain_config.local.app_id } else { - if (url_app_id) { - app_id = url_app_id - } else if (config_app_id) { - app_id = config_app_id - } else if (isStaging()) { - window.localStorage.removeItem('config.default_app_id') - app_id = domain_config.staging.app_id - } else if (isBeta()) { - window.localStorage.removeItem('config.default_app_id') - app_id = domain_config.beta.app_id - } else if (user_app_id.length) { - window.localStorage.setItem('config.default_app_id', user_app_id) // it's being used in endpoint chrome extension - please do not remove - app_id = user_app_id - } else if (isLocalHost()) { - app_id = domain_config.local.app_id - } else { - window.localStorage.removeItem('config.default_app_id') - app_id = isProduction() ? prod_app_id : domain_config.test.app_id - } + window.localStorage.removeItem('config.default_app_id') + app_id = isProduction() ? prod_app_id : domain_config.test.app_id } } + return app_id } - const getSocketURL = () => { let server_url