2021-02-04 19:15:23 +01:00
|
|
|
import { compose } from 'redux';
|
|
|
|
import { connect } from 'react-redux';
|
|
|
|
import { withRouter } from 'react-router-dom';
|
|
|
|
import { getAddressBookEntryName } from '../../selectors';
|
|
|
|
import { isValidAddress } from '../../helpers/utils/util';
|
|
|
|
import { ENVIRONMENT_TYPE_POPUP } from '../../../../shared/constants/app';
|
|
|
|
import { getEnvironmentType } from '../../../../app/scripts/lib/util';
|
|
|
|
import { getMostRecentOverviewPage } from '../../ducks/history/history';
|
2019-07-31 21:56:44 +02:00
|
|
|
|
|
|
|
import {
|
2020-10-27 22:55:09 +01:00
|
|
|
ABOUT_US_ROUTE,
|
2019-07-31 21:56:44 +02:00
|
|
|
ADVANCED_ROUTE,
|
2020-05-08 21:45:52 +02:00
|
|
|
ALERTS_ROUTE,
|
2019-07-31 21:56:44 +02:00
|
|
|
CONTACT_LIST_ROUTE,
|
|
|
|
CONTACT_ADD_ROUTE,
|
|
|
|
CONTACT_EDIT_ROUTE,
|
|
|
|
CONTACT_MY_ACCOUNTS_ROUTE,
|
|
|
|
CONTACT_MY_ACCOUNTS_EDIT_ROUTE,
|
|
|
|
CONTACT_MY_ACCOUNTS_VIEW_ROUTE,
|
2020-10-27 23:36:50 +01:00
|
|
|
CONTACT_VIEW_ROUTE,
|
2020-10-27 22:55:09 +01:00
|
|
|
GENERAL_ROUTE,
|
2020-10-28 20:42:42 +01:00
|
|
|
NETWORKS_FORM_ROUTE,
|
2020-10-27 23:36:50 +01:00
|
|
|
NETWORKS_ROUTE,
|
2020-10-27 22:55:09 +01:00
|
|
|
SECURITY_ROUTE,
|
|
|
|
SETTINGS_ROUTE,
|
2021-02-04 19:15:23 +01:00
|
|
|
} from '../../helpers/constants/routes';
|
|
|
|
import Settings from './settings.component';
|
2019-07-31 21:56:44 +02:00
|
|
|
|
|
|
|
const ROUTES_TO_I18N_KEYS = {
|
|
|
|
[ABOUT_US_ROUTE]: 'about',
|
2020-10-27 23:36:50 +01:00
|
|
|
[ADVANCED_ROUTE]: 'advanced',
|
2020-05-08 21:45:52 +02:00
|
|
|
[ALERTS_ROUTE]: 'alerts',
|
2020-10-27 23:36:50 +01:00
|
|
|
[GENERAL_ROUTE]: 'general',
|
2019-07-31 21:56:44 +02:00
|
|
|
[CONTACT_ADD_ROUTE]: 'newContact',
|
|
|
|
[CONTACT_EDIT_ROUTE]: 'editContact',
|
2020-10-27 23:36:50 +01:00
|
|
|
[CONTACT_LIST_ROUTE]: 'contacts',
|
2019-07-31 21:56:44 +02:00
|
|
|
[CONTACT_MY_ACCOUNTS_ROUTE]: 'myAccounts',
|
2020-10-27 23:36:50 +01:00
|
|
|
[CONTACT_VIEW_ROUTE]: 'viewContact',
|
|
|
|
[NETWORKS_ROUTE]: 'networks',
|
2020-10-28 20:42:42 +01:00
|
|
|
[NETWORKS_FORM_ROUTE]: 'networks',
|
2020-10-27 23:36:50 +01:00
|
|
|
[SECURITY_ROUTE]: 'securityAndPrivacy',
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2019-07-31 21:56:44 +02:00
|
|
|
|
|
|
|
const mapStateToProps = (state, ownProps) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const { location } = ownProps;
|
|
|
|
const { pathname } = location;
|
|
|
|
const pathNameTail = pathname.match(/[^/]+$/u)[0];
|
2019-07-31 21:56:44 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const isAddressEntryPage = pathNameTail.includes('0x');
|
|
|
|
const isMyAccountsPage = pathname.match('my-accounts');
|
|
|
|
const isAddContactPage = Boolean(pathname.match(CONTACT_ADD_ROUTE));
|
|
|
|
const isEditContactPage = Boolean(pathname.match(CONTACT_EDIT_ROUTE));
|
2020-11-03 00:41:28 +01:00
|
|
|
const isEditMyAccountsContactPage = Boolean(
|
|
|
|
pathname.match(CONTACT_MY_ACCOUNTS_EDIT_ROUTE),
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
const isNetworksFormPage = Boolean(pathname.match(NETWORKS_FORM_ROUTE));
|
2019-07-31 21:56:44 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const isPopup = getEnvironmentType() === ENVIRONMENT_TYPE_POPUP;
|
|
|
|
const pathnameI18nKey = ROUTES_TO_I18N_KEYS[pathname];
|
2019-07-31 21:56:44 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
let backRoute = SETTINGS_ROUTE;
|
2019-07-31 21:56:44 +02:00
|
|
|
if (isMyAccountsPage && isAddressEntryPage) {
|
2021-02-04 19:15:23 +01:00
|
|
|
backRoute = CONTACT_MY_ACCOUNTS_ROUTE;
|
2019-07-31 21:56:44 +02:00
|
|
|
} else if (isEditContactPage) {
|
2021-02-04 19:15:23 +01:00
|
|
|
backRoute = `${CONTACT_VIEW_ROUTE}/${pathNameTail}`;
|
2019-07-31 21:56:44 +02:00
|
|
|
} else if (isEditMyAccountsContactPage) {
|
2021-02-04 19:15:23 +01:00
|
|
|
backRoute = `${CONTACT_MY_ACCOUNTS_VIEW_ROUTE}/${pathNameTail}`;
|
2019-07-31 21:56:44 +02:00
|
|
|
} else if (isAddressEntryPage || isMyAccountsPage || isAddContactPage) {
|
2021-02-04 19:15:23 +01:00
|
|
|
backRoute = CONTACT_LIST_ROUTE;
|
2020-10-28 20:42:42 +01:00
|
|
|
} else if (isNetworksFormPage) {
|
2021-02-04 19:15:23 +01:00
|
|
|
backRoute = NETWORKS_ROUTE;
|
2019-07-31 21:56:44 +02:00
|
|
|
}
|
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
let initialBreadCrumbRoute;
|
|
|
|
let breadCrumbTextKey;
|
|
|
|
let initialBreadCrumbKey;
|
2019-07-31 21:56:44 +02:00
|
|
|
if (isMyAccountsPage) {
|
2021-02-04 19:15:23 +01:00
|
|
|
initialBreadCrumbRoute = CONTACT_LIST_ROUTE;
|
|
|
|
breadCrumbTextKey = 'myWalletAccounts';
|
|
|
|
initialBreadCrumbKey = ROUTES_TO_I18N_KEYS[initialBreadCrumbRoute];
|
2019-07-31 21:56:44 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
const addressName = getAddressBookEntryName(
|
|
|
|
state,
|
|
|
|
isValidAddress(pathNameTail) ? pathNameTail : '',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2019-07-31 21:56:44 +02:00
|
|
|
|
|
|
|
return {
|
|
|
|
isAddressEntryPage,
|
|
|
|
isMyAccountsPage,
|
|
|
|
backRoute,
|
|
|
|
currentPath: pathname,
|
2020-10-29 00:10:41 +01:00
|
|
|
isPopup,
|
2019-07-31 21:56:44 +02:00
|
|
|
pathnameI18nKey,
|
|
|
|
addressName,
|
|
|
|
initialBreadCrumbRoute,
|
|
|
|
breadCrumbTextKey,
|
|
|
|
initialBreadCrumbKey,
|
2020-06-01 19:54:32 +02:00
|
|
|
mostRecentOverviewPage: getMostRecentOverviewPage(state),
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
|
|
|
};
|
2019-07-31 21:56:44 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
export default compose(withRouter, connect(mapStateToProps))(Settings);
|