2021-02-04 19:15:23 +01:00
|
|
|
import { compose } from 'redux';
|
|
|
|
import { connect } from 'react-redux';
|
|
|
|
import { withRouter } from 'react-router-dom';
|
|
|
|
import { getAddressBookEntry } from '../../../../selectors';
|
|
|
|
import { checksumAddress } from '../../../../helpers/utils/util';
|
2019-07-31 21:56:44 +02:00
|
|
|
import {
|
|
|
|
CONTACT_EDIT_ROUTE,
|
2020-07-20 16:55:47 +02:00
|
|
|
CONTACT_LIST_ROUTE,
|
2019-07-31 21:56:44 +02:00
|
|
|
CONTACT_MY_ACCOUNTS_EDIT_ROUTE,
|
2020-07-20 16:55:47 +02:00
|
|
|
CONTACT_MY_ACCOUNTS_ROUTE,
|
2019-07-31 21:56:44 +02:00
|
|
|
CONTACT_MY_ACCOUNTS_VIEW_ROUTE,
|
2021-02-04 19:15:23 +01:00
|
|
|
} from '../../../../helpers/constants/routes';
|
|
|
|
import ViewContact from './view-contact.component';
|
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];
|
|
|
|
const pathNameTailIsAddress = pathNameTail.includes('0x');
|
2020-11-03 00:41:28 +01:00
|
|
|
const address = pathNameTailIsAddress
|
|
|
|
? pathNameTail.toLowerCase()
|
2021-02-04 19:15:23 +01:00
|
|
|
: ownProps.match.params.id;
|
2019-07-31 21:56:44 +02:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
const contact =
|
2021-02-04 19:15:23 +01:00
|
|
|
getAddressBookEntry(state, address) || state.metamask.identities[address];
|
|
|
|
const { memo, name } = contact || {};
|
2019-07-31 21:56:44 +02:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
const showingMyAccounts = Boolean(
|
|
|
|
pathname.match(CONTACT_MY_ACCOUNTS_VIEW_ROUTE),
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2019-07-31 21:56:44 +02:00
|
|
|
|
|
|
|
return {
|
|
|
|
name,
|
2020-07-20 16:55:47 +02:00
|
|
|
address: contact ? address : null,
|
2019-07-31 21:56:44 +02:00
|
|
|
checkSummedAddress: checksumAddress(address),
|
|
|
|
memo,
|
2020-11-03 00:41:28 +01:00
|
|
|
editRoute: showingMyAccounts
|
|
|
|
? CONTACT_MY_ACCOUNTS_EDIT_ROUTE
|
|
|
|
: CONTACT_EDIT_ROUTE,
|
|
|
|
listRoute: showingMyAccounts
|
|
|
|
? CONTACT_MY_ACCOUNTS_ROUTE
|
|
|
|
: CONTACT_LIST_ROUTE,
|
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))(ViewContact);
|