Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Amina/82217 account switcher trading hub #4

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/appstore/src/modules/trading-hub/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const TradingHub: React.FC = () => {
is_eu_country,
is_populating_mt5_account_list,
is_populating_dxtrade_account_list,
loginid,
switchAccountHandlerForAppstore,
} = client;
const {
setAccountType,
Expand Down Expand Up @@ -107,6 +107,7 @@ const TradingHub: React.FC = () => {
name: string;
};
}) => {
switchAccountHandlerForAppstore(tab_account_type);
setTabAccountType(event.target.value as TAccountCategory);
};
const platformTypeChange = (event: {
Expand Down
30 changes: 30 additions & 0 deletions packages/core/src/Stores/client-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ export default class ClientStore extends BaseStore {

is_mt5_account_list_updated = false;

prev_real_account_loginid = '';

constructor(root_store) {
const local_storage_properties = ['device_data'];
super({ root_store, local_storage_properties, store_name });
Expand Down Expand Up @@ -196,6 +198,7 @@ export default class ClientStore extends BaseStore {
mt5_trading_servers: observable,
dxtrade_trading_servers: observable,
is_cfd_poi_completed: observable,
prev_real_account_loginid: observable,
balance: computed,
account_open_date: computed,
is_reality_check_visible: computed,
Expand Down Expand Up @@ -361,6 +364,8 @@ export default class ClientStore extends BaseStore {
setTwoFAStatus: action.bound,
getTwoFAStatus: action.bound,
isEuropeCountry: action.bound,
setPrevRealAccountLoginid: action.bound,
switchAccountHandlerForAppstore: action.bound,
});

reaction(
Expand Down Expand Up @@ -1388,6 +1393,9 @@ export default class ClientStore extends BaseStore {
this.setIsLoggingIn(true);
this.root_store.notifications.removeNotifications(true);
this.root_store.notifications.removeAllNotificationMessages(true);
if (!this.is_virtual && /VRTC/.test(loginid)) {
this.setPrevRealAccountLoginid(this.loginid);
}
this.setSwitched(loginid);
this.responsePayoutCurrencies(await WS.authorized.payoutCurrencies());
}
Expand Down Expand Up @@ -1497,6 +1505,9 @@ export default class ClientStore extends BaseStore {
window.location.replace(urlForLanguage(authorize_response.authorize.preferred_language));
}
if (this.citizen) this.onSetCitizen(this.citizen);
if (!this.is_virtual) {
this.setPrevRealAccountLoginid(this.loginid);
}
}

this.selectCurrency('');
Expand Down Expand Up @@ -2438,5 +2449,24 @@ export default class ClientStore extends BaseStore {
});
});
}

setPrevRealAccountLoginid = logind => {
this.prev_real_account_loginid = logind;
};

async switchAccountHandlerForAppstore(tab_current_account_type) {
if (tab_current_account_type === 'demo' && this.hasAnyRealAccount()) {
if (this.prev_real_account_loginid) {
await this.switchAccount(this.prev_real_account_loginid);
} else {
await this.switchAccount(
this.account_list.find(acc => acc.is_virtual === 0 && !acc.is_disabled).loginid
);
}
} else if (tab_current_account_type === 'real') {
this.setPrevRealAccountLoginid(this.loginid);
await this.switchAccount(this.virtual_account_loginid);
}
}
}
/* eslint-enable */