Skip to content

Commit

Permalink
prevent unmounting the portfolio component when redirecting to report…
Browse files Browse the repository at this point in the history
…s packge
  • Loading branch information
mahdiyeh-deriv committed Jul 5, 2022
1 parent c9a2c1d commit bdc145e
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 24 deletions.
11 changes: 7 additions & 4 deletions packages/core/src/Stores/portfolio-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -452,10 +452,13 @@ export default class PortfolioStore extends BaseStore {

@action.bound
onUnmount() {
this.disposePreSwitchAccount();
this.disposeSwitchAccount();
this.disposeLogout();
this.clearTable();
const is_reports_path = /^\/reports/.test(window.location.pathname);
if (!is_reports_path) {
this.clearTable();
this.disposePreSwitchAccount();
this.disposeSwitchAccount();
this.disposeLogout();
}
}

getPositionIndexById(contract_id) {
Expand Down
8 changes: 0 additions & 8 deletions packages/core/src/Stores/ui-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ export default class UIStore extends BaseStore {
// Take profit, Stop loss & Deal cancellation checkbox
@observable should_show_cancellation_warning = true;

// Check previous url to don't unmount portfolio when navigate from reports to trader
@observable is_reports_url = false;

// Extensions
@observable footer_extensions = [];
@observable header_extension = undefined;
Expand Down Expand Up @@ -196,11 +193,6 @@ export default class UIStore extends BaseStore {
}
};
@action.bound
setIsReportsUrl(is_reports_url) {
this.is_reports_url = is_reports_url;
}
@action.bound
init(notification_messages) {
this.notification_messages_ui = notification_messages;
Expand Down
3 changes: 0 additions & 3 deletions packages/reports/src/Containers/reports.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,9 @@ const Reports = ({
setVisibilityRealityCheck,
tab_index,
toggleReports,
setIsReportsUrl,
}) => {
React.useEffect(() => {
toggleReports(true);
setIsReportsUrl(true);
return () => {
setVisibilityRealityCheck(1);
toggleReports(false);
Expand Down Expand Up @@ -132,5 +130,4 @@ export default connect(({ client, common, ui }) => ({
setTabIndex: ui.setReportsTabIndex,
tab_index: ui.reports_route_tab_index,
toggleReports: ui.toggleReports,
setIsReportsUrl: ui.setIsReportsUrl,
}))(withRouter(Reports));
10 changes: 1 addition & 9 deletions packages/trader/src/App/Containers/Routes/routes.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ const Routes = ({
passthrough,
setPromptHandler,
setTradeMountingPolicy,
is_reports_url,
setIsReportsUrl,
}) => {
React.useEffect(() => {
if (setPromptHandler) {
Expand Down Expand Up @@ -97,11 +95,7 @@ const Routes = ({
}, []);

React.useEffect(() => {
if (is_reports_url) {
setIsReportsUrl(false);
return;
}
onUnmountPortfolio();
return () => onUnmountPortfolio();
}, [onUnmountPortfolio]);

if (has_error) return <Error {...error} />;
Expand Down Expand Up @@ -131,7 +125,5 @@ export default withRouter(
is_logging_in: client.is_logging_in,
setPromptHandler: ui.setPromptHandler,
setTradeMountingPolicy: modules.trade.setSkipPrePostLifecycle,
is_reports_url: ui.is_reports_url,
setIsReportsUrl: ui.setIsReportsUrl,
}))(Routes)
);

0 comments on commit bdc145e

Please sign in to comment.