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 { getAddressBook } from '../../../selectors'
|
2019-07-31 21:56:44 +02:00
|
|
|
import { ENVIRONMENT_TYPE_POPUP } from '../../../../../app/scripts/lib/enums'
|
|
|
|
import { getEnvironmentType } from '../../../../../app/scripts/lib/util'
|
|
|
|
|
|
|
|
import {
|
|
|
|
CONTACT_ADD_ROUTE,
|
|
|
|
CONTACT_EDIT_ROUTE,
|
|
|
|
CONTACT_VIEW_ROUTE,
|
|
|
|
CONTACT_MY_ACCOUNTS_ROUTE,
|
|
|
|
CONTACT_MY_ACCOUNTS_VIEW_ROUTE,
|
|
|
|
CONTACT_MY_ACCOUNTS_EDIT_ROUTE,
|
|
|
|
} from '../../../helpers/constants/routes'
|
2020-08-18 21:18:25 +02:00
|
|
|
import ContactListTab from './contact-list-tab.component'
|
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 pathNameTailIsAddress = pathNameTail.includes('0x')
|
|
|
|
|
|
|
|
const viewingContact = Boolean(pathname.match(CONTACT_VIEW_ROUTE) || pathname.match(CONTACT_MY_ACCOUNTS_VIEW_ROUTE))
|
|
|
|
const editingContact = Boolean(pathname.match(CONTACT_EDIT_ROUTE) || pathname.match(CONTACT_MY_ACCOUNTS_EDIT_ROUTE))
|
|
|
|
const addingContact = Boolean(pathname.match(CONTACT_ADD_ROUTE))
|
|
|
|
const showingMyAccounts = Boolean(
|
|
|
|
pathname.match(CONTACT_MY_ACCOUNTS_ROUTE) ||
|
|
|
|
pathname.match(CONTACT_MY_ACCOUNTS_VIEW_ROUTE) ||
|
2020-07-14 17:20:41 +02:00
|
|
|
pathname.match(CONTACT_MY_ACCOUNTS_EDIT_ROUTE),
|
2019-07-31 21:56:44 +02:00
|
|
|
)
|
|
|
|
const envIsPopup = getEnvironmentType() === ENVIRONMENT_TYPE_POPUP
|
|
|
|
|
|
|
|
const hideAddressBook = envIsPopup && (viewingContact || editingContact || addingContact)
|
|
|
|
|
|
|
|
return {
|
|
|
|
viewingContact,
|
|
|
|
editingContact,
|
|
|
|
addingContact,
|
|
|
|
showingMyAccounts,
|
|
|
|
addressBook: getAddressBook(state),
|
|
|
|
selectedAddress: pathNameTailIsAddress ? pathNameTail : '',
|
|
|
|
hideAddressBook,
|
|
|
|
envIsPopup,
|
|
|
|
showContactContent: !envIsPopup || hideAddressBook,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default compose(
|
|
|
|
withRouter,
|
2020-07-14 17:20:41 +02:00
|
|
|
connect(mapStateToProps),
|
2019-07-31 21:56:44 +02:00
|
|
|
)(ContactListTab)
|