2020-02-24 23:58:26 +01:00
|
|
|
import { compose } from 'redux'
|
2019-07-31 21:56:44 +02:00
|
|
|
import { connect } from 'react-redux'
|
|
|
|
import { withRouter } from 'react-router-dom'
|
2020-05-02 21:41:17 +02:00
|
|
|
import { getAddressBookEntryName } from '../../selectors'
|
2019-07-31 21:56:44 +02:00
|
|
|
import { isValidAddress } from '../../helpers/utils/util'
|
2020-10-29 06:45:08 +01:00
|
|
|
import { ENVIRONMENT_TYPE_POPUP } from '../../../../app/scripts/lib/enums'
|
2019-07-31 21:56:44 +02:00
|
|
|
import { getEnvironmentType } from '../../../../app/scripts/lib/util'
|
2020-06-01 19:54:32 +02:00
|
|
|
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,
|
2019-07-31 21:56:44 +02:00
|
|
|
} from '../../helpers/constants/routes'
|
2020-08-18 21:18:25 +02:00
|
|
|
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',
|
2019-07-31 21:56:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const mapStateToProps = (state, ownProps) => {
|
|
|
|
const { location } = ownProps
|
|
|
|
const { pathname } = location
|
2020-08-14 13:48:42 +02:00
|
|
|
const pathNameTail = pathname.match(/[^/]+$/u)[0]
|
2019-07-31 21:56:44 +02: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),
|
|
|
|
)
|
2020-10-28 20:42:42 +01:00
|
|
|
const isNetworksFormPage = Boolean(pathname.match(NETWORKS_FORM_ROUTE))
|
2019-07-31 21:56:44 +02:00
|
|
|
|
2020-10-29 00:10:41 +01:00
|
|
|
const isPopup = getEnvironmentType() === ENVIRONMENT_TYPE_POPUP
|
2019-07-31 21:56:44 +02:00
|
|
|
const pathnameI18nKey = ROUTES_TO_I18N_KEYS[pathname]
|
|
|
|
|
2020-10-27 23:36:50 +01:00
|
|
|
let backRoute = SETTINGS_ROUTE
|
2019-07-31 21:56:44 +02:00
|
|
|
if (isMyAccountsPage && isAddressEntryPage) {
|
|
|
|
backRoute = CONTACT_MY_ACCOUNTS_ROUTE
|
|
|
|
} else if (isEditContactPage) {
|
|
|
|
backRoute = `${CONTACT_VIEW_ROUTE}/${pathNameTail}`
|
|
|
|
} else if (isEditMyAccountsContactPage) {
|
|
|
|
backRoute = `${CONTACT_MY_ACCOUNTS_VIEW_ROUTE}/${pathNameTail}`
|
|
|
|
} else if (isAddressEntryPage || isMyAccountsPage || isAddContactPage) {
|
|
|
|
backRoute = CONTACT_LIST_ROUTE
|
2020-10-28 20:42:42 +01:00
|
|
|
} else if (isNetworksFormPage) {
|
|
|
|
backRoute = NETWORKS_ROUTE
|
2019-07-31 21:56:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
let initialBreadCrumbRoute
|
|
|
|
let breadCrumbTextKey
|
|
|
|
let initialBreadCrumbKey
|
|
|
|
if (isMyAccountsPage) {
|
|
|
|
initialBreadCrumbRoute = CONTACT_LIST_ROUTE
|
|
|
|
breadCrumbTextKey = 'myWalletAccounts'
|
|
|
|
initialBreadCrumbKey = ROUTES_TO_I18N_KEYS[initialBreadCrumbRoute]
|
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
const addressName = getAddressBookEntryName(
|
|
|
|
state,
|
|
|
|
isValidAddress(pathNameTail) ? pathNameTail : '',
|
|
|
|
)
|
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),
|
2019-07-31 21:56:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export default compose(withRouter, connect(mapStateToProps))(Settings)
|