diff --git a/packages/core/src/App/Containers/PlatformContainer/PlatformContainer.jsx b/packages/core/src/App/Containers/PlatformContainer/PlatformContainer.jsx index 89238573b7bb..63cb12c4b7b1 100644 --- a/packages/core/src/App/Containers/PlatformContainer/PlatformContainer.jsx +++ b/packages/core/src/App/Containers/PlatformContainer/PlatformContainer.jsx @@ -1,32 +1,26 @@ import React from 'react'; import { PlatformContext } from '@deriv/shared'; +import { connect } from 'Stores/connect'; const DERIV_APPSTORE_KEY = 'is_appstore'; -const DERIV_PRE_APPSTORE_KEY = 'is_pre_appstore'; -const PlatformContainer = ({ ...props }) => { +const PlatformContainer = ({ is_pre_appstore, setIsPreAppStore, ...props }) => { // TODO: set is_appstore based on a flag from BE. const is_appstore_storage = window.localStorage.getItem(DERIV_APPSTORE_KEY) === 'true'; const [is_appstore, setIsAppStore] = React.useState(is_appstore_storage); - // TODO: set is_pre_appstore based on a flag from BE. - const is_pre_appstore_storage = window.localStorage.getItem(DERIV_PRE_APPSTORE_KEY) === 'true'; - const [is_pre_appstore, setIsPreAppStore] = React.useState(is_pre_appstore_storage); - - React.useEffect(() => { - window.localStorage.setItem(DERIV_PRE_APPSTORE_KEY, is_pre_appstore); - }, [is_pre_appstore]); - const platform_store = { is_appstore, setIsAppStore, DERIV_APPSTORE_KEY, is_pre_appstore, setIsPreAppStore, - DERIV_PRE_APPSTORE_KEY, }; return ; }; -export default PlatformContainer; +export default connect(({ client }) => ({ + is_pre_appstore: client.is_pre_appstore, + setIsPreAppStore: client.setIsPreAppStore, +}))(PlatformContainer); diff --git a/packages/core/src/Modules/Endpoint/Endpoint.jsx b/packages/core/src/Modules/Endpoint/Endpoint.jsx index f7fa2a6a4d8c..6129d8e3c88c 100644 --- a/packages/core/src/Modules/Endpoint/Endpoint.jsx +++ b/packages/core/src/Modules/Endpoint/Endpoint.jsx @@ -32,7 +32,6 @@ const Endpoint = () => { app_id: getAppId(), server: getSocketURL(), is_appstore_enabled: platform_store.is_appstore, - is_pre_appstore_enabled: platform_store.is_pre_appstore, show_dbot_dashboard: dbot_dashboard_storage !== undefined && dbot_dashboard_storage !== 'false', is_debug_service_worker_enabled: !!getDebugServiceWorker(), }} @@ -56,11 +55,9 @@ const Endpoint = () => { localStorage.setItem('config.app_id', values.app_id); localStorage.setItem('config.server_url', values.server); localStorage.setItem(platform_store.DERIV_APPSTORE_KEY, values.is_appstore_enabled); - localStorage.setItem(platform_store.DERIV_PRE_APPSTORE_KEY, values.is_pre_appstore_enabled); LocalStore.set('show_dbot_dashboard', values.show_dbot_dashboard); localStorage.setItem('debug_service_worker', values.is_debug_service_worker_enabled ? 1 : 0); platform_store.setIsAppStore(values.is_appstore_enabled); - platform_store.setIsPreAppStore(values.is_pre_appstore_enabled); window.localStorage.removeItem('config.platform'); location.reload(); }} @@ -110,21 +107,6 @@ const Endpoint = () => { )} - - {({ field }) => ( -
- { - handleChange(e); - setFieldTouched('is_pre_appstore_enabled', true); - }} - /> -
- )} -
{({ field }) => (
@@ -162,7 +144,6 @@ const Endpoint = () => { (!touched.server && !touched.app_id && !touched.is_appstore_enabled && - !touched.is_pre_appstore_enabled && !touched.show_dbot_dashboard && !touched.is_debug_service_worker_enabled) || !values.server || diff --git a/packages/core/src/Stores/client-store.js b/packages/core/src/Stores/client-store.js index 0f7e3bc88644..8f831f8d4488 100644 --- a/packages/core/src/Stores/client-store.js +++ b/packages/core/src/Stores/client-store.js @@ -286,6 +286,7 @@ export default class ClientStore extends BaseStore { is_eu_country: computed, is_options_blocked: computed, is_multipliers_only: computed, + is_pre_appstore: computed, resetLocalStorageValues: action.bound, getBasicUpgradeInfo: action.bound, setMT5DisabledSignupTypes: action.bound, @@ -375,6 +376,7 @@ export default class ClientStore extends BaseStore { isEuropeCountry: action.bound, setPrevRealAccountLoginid: action.bound, switchAccountHandlerForAppstore: action.bound, + setIsPreAppStore: action.bound, }); reaction( @@ -934,6 +936,11 @@ export default class ClientStore extends BaseStore { return this.isBotAllowed(); } + get is_pre_appstore() { + const { trading_hub } = this.account_settings; + return !!trading_hub; + } + getIsMarketTypeMatching = (account, market_type) => market_type === 'synthetic' ? account.market_type === market_type || account.market_type === 'gaming' @@ -2030,7 +2037,7 @@ export default class ClientStore extends BaseStore { const is_client_logging_in = login_new_user ? login_new_user.token1 : obj_params.token1; if (is_client_logging_in) { - const is_pre_appstore = window.localStorage.getItem('is_pre_appstore'); + const is_pre_appstore = !!this.account_settings.trading_hub; const redirect_url = sessionStorage.getItem('redirect_url'); if ( is_pre_appstore === 'true' && @@ -2507,5 +2514,19 @@ export default class ClientStore extends BaseStore { await this.switchAccount(this.virtual_account_loginid); } } + + setIsPreAppStore(is_pre_appstore) { + const trading_hub = is_pre_appstore ? 1 : 0; + if (this.is_pre_appstore !== is_pre_appstore) { + WS.setSettings({ + set_settings: 1, + trading_hub, + }).then(response => { + if (!response.error) { + this.account_settings = { ...this.account_settings, trading_hub }; + } + }); + } + } } /* eslint-enable */