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';
|
2019-07-31 21:56:44 +02:00
|
|
|
import {
|
|
|
|
CONTACT_EDIT_ROUTE,
|
2020-07-20 16:55:47 +02:00
|
|
|
CONTACT_LIST_ROUTE,
|
2021-02-04 19:15:23 +01:00
|
|
|
} from '../../../../helpers/constants/routes';
|
2021-05-17 23:19:39 +02:00
|
|
|
import { toChecksumHexAddress } from '../../../../../shared/modules/hexstring-utils';
|
2021-02-04 19:15:23 +01:00
|
|
|
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
|
|
|
|
|
|
|
return {
|
|
|
|
name,
|
2020-07-20 16:55:47 +02:00
|
|
|
address: contact ? address : null,
|
2021-05-17 23:19:39 +02:00
|
|
|
checkSummedAddress: toChecksumHexAddress(address),
|
2019-07-31 21:56:44 +02:00
|
|
|
memo,
|
2021-04-27 20:25:58 +02:00
|
|
|
editRoute: CONTACT_EDIT_ROUTE,
|
|
|
|
listRoute: 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);
|