2021-02-04 19:15:23 +01:00
|
|
|
import { compose } from 'redux';
|
|
|
|
import { connect } from 'react-redux';
|
|
|
|
import { withRouter } from 'react-router-dom';
|
2021-11-04 07:58:32 +01:00
|
|
|
import { getAddressBookEntryOrAccountName } from '../../selectors';
|
2021-04-28 21:53:59 +02:00
|
|
|
import { ENVIRONMENT_TYPE_POPUP } from '../../../shared/constants/app';
|
|
|
|
import { getEnvironmentType } from '../../../app/scripts/lib/util';
|
2021-02-04 19:15:23 +01:00
|
|
|
import { getMostRecentOverviewPage } from '../../ducks/history/history';
|
2021-05-17 21:00:59 +02:00
|
|
|
import {
|
|
|
|
isValidHexAddress,
|
|
|
|
isBurnAddress,
|
|
|
|
} from '../../../shared/modules/hexstring-utils';
|
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,
|
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-09-20 18:22:04 +02:00
|
|
|
EXPERIMENTAL_ROUTE,
|
2021-10-25 22:38:43 +02:00
|
|
|
ADD_NETWORK_ROUTE,
|
2022-02-15 01:02:51 +01:00
|
|
|
SNAPS_LIST_ROUTE,
|
|
|
|
SNAPS_VIEW_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',
|
2022-02-15 01:02:51 +01:00
|
|
|
[SNAPS_LIST_ROUTE]: 'snaps',
|
|
|
|
[SNAPS_VIEW_ROUTE]: 'snaps',
|
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',
|
2021-10-25 22:38:43 +02:00
|
|
|
[ADD_NETWORK_ROUTE]: 'networks',
|
2020-10-27 23:36:50 +01:00
|
|
|
[SECURITY_ROUTE]: 'securityAndPrivacy',
|
2021-09-20 18:22:04 +02:00
|
|
|
[EXPERIMENTAL_ROUTE]: 'experimental',
|
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;
|
2021-12-02 13:18:09 +01:00
|
|
|
const {
|
|
|
|
metamask: { conversionDate },
|
|
|
|
} = state;
|
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const pathNameTail = pathname.match(/[^/]+$/u)[0];
|
|
|
|
const isAddressEntryPage = pathNameTail.includes('0x');
|
2022-02-15 01:02:51 +01:00
|
|
|
const isSnapViewPage = Boolean(pathname.match(SNAPS_VIEW_ROUTE));
|
2021-02-04 19:15:23 +01:00
|
|
|
const isAddContactPage = Boolean(pathname.match(CONTACT_ADD_ROUTE));
|
|
|
|
const isEditContactPage = Boolean(pathname.match(CONTACT_EDIT_ROUTE));
|
2021-10-25 22:38:43 +02:00
|
|
|
const isNetworksFormPage =
|
|
|
|
Boolean(pathname.match(NETWORKS_FORM_ROUTE)) ||
|
|
|
|
Boolean(pathname.match(ADD_NETWORK_ROUTE));
|
|
|
|
const addNewNetwork = Boolean(pathname.match(ADD_NETWORK_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;
|
2021-04-27 20:25:58 +02:00
|
|
|
if (isEditContactPage) {
|
2021-02-04 19:15:23 +01:00
|
|
|
backRoute = `${CONTACT_VIEW_ROUTE}/${pathNameTail}`;
|
2021-04-27 20:25:58 +02:00
|
|
|
} else if (isAddressEntryPage || 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;
|
2022-02-15 01:02:51 +01:00
|
|
|
} else if (isSnapViewPage) {
|
|
|
|
backRoute = SNAPS_LIST_ROUTE;
|
2019-07-31 21:56:44 +02:00
|
|
|
}
|
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
let initialBreadCrumbRoute;
|
|
|
|
let initialBreadCrumbKey;
|
2019-07-31 21:56:44 +02:00
|
|
|
|
2021-11-04 07:58:32 +01:00
|
|
|
const addressName = getAddressBookEntryOrAccountName(
|
2020-11-03 00:41:28 +01:00
|
|
|
state,
|
2021-05-17 21:00:59 +02:00
|
|
|
!isBurnAddress(pathNameTail) &&
|
|
|
|
isValidHexAddress(pathNameTail, { mixedCaseUseChecksum: true })
|
|
|
|
? pathNameTail
|
|
|
|
: '',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2019-07-31 21:56:44 +02:00
|
|
|
|
|
|
|
return {
|
|
|
|
isAddressEntryPage,
|
|
|
|
backRoute,
|
|
|
|
currentPath: pathname,
|
2020-10-29 00:10:41 +01:00
|
|
|
isPopup,
|
2019-07-31 21:56:44 +02:00
|
|
|
pathnameI18nKey,
|
|
|
|
addressName,
|
|
|
|
initialBreadCrumbRoute,
|
|
|
|
initialBreadCrumbKey,
|
2020-06-01 19:54:32 +02:00
|
|
|
mostRecentOverviewPage: getMostRecentOverviewPage(state),
|
2021-10-25 22:38:43 +02:00
|
|
|
addNewNetwork,
|
2021-12-02 13:18:09 +01:00
|
|
|
conversionDate,
|
2022-02-15 01:02:51 +01:00
|
|
|
isSnapViewPage,
|
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);
|