Skip to content

Commit

Permalink
Merge pull request #46 from mahdiyeh-fs/mahdiyeh/83434/remove_is_pre_…
Browse files Browse the repository at this point in the history
…appstore_from_localstorage

bugfix: remove localstorage for is_pre_appstore
  • Loading branch information
matin-deriv committed Dec 14, 2022
2 parents c02c153 + 4e8efee commit a32ffb6
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 32 deletions.
Original file line number Diff line number Diff line change
@@ -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 <PlatformContext.Provider value={platform_store} {...props} />;
};

export default PlatformContainer;
export default connect(({ client }) => ({
is_pre_appstore: client.is_pre_appstore,
setIsPreAppStore: client.setIsPreAppStore,
}))(PlatformContainer);
19 changes: 0 additions & 19 deletions packages/core/src/Modules/Endpoint/Endpoint.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
}}
Expand All @@ -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();
}}
Expand Down Expand Up @@ -110,21 +107,6 @@ const Endpoint = () => {
</div>
)}
</Field>
<Field name='is_pre_appstore_enabled'>
{({ field }) => (
<div style={{ marginTop: '4.5rem', marginBottom: '1.6rem' }}>
<Checkbox
{...field}
label='Enable Pre-Appstore'
value={values.is_pre_appstore_enabled}
onChange={e => {
handleChange(e);
setFieldTouched('is_pre_appstore_enabled', true);
}}
/>
</div>
)}
</Field>
<Field name='show_dbot_dashboard'>
{({ field }) => (
<div style={{ marginTop: '4.5rem', marginBottom: '1.6rem' }}>
Expand Down Expand Up @@ -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 ||
Expand Down
23 changes: 22 additions & 1 deletion packages/core/src/Stores/client-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -375,6 +376,7 @@ export default class ClientStore extends BaseStore {
isEuropeCountry: action.bound,
setPrevRealAccountLoginid: action.bound,
switchAccountHandlerForAppstore: action.bound,
setIsPreAppStore: action.bound,
});

reaction(
Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -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' &&
Expand Down Expand Up @@ -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 */

0 comments on commit a32ffb6

Please sign in to comment.