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_VIEW_ROUTE,
|
|
|
|
CONTACT_LIST_ROUTE,
|
2021-02-04 19:15:23 +01:00
|
|
|
} from '../../../../helpers/constants/routes';
|
2020-11-03 00:41:28 +01:00
|
|
|
import {
|
|
|
|
addToAddressBook,
|
|
|
|
removeFromAddressBook,
|
|
|
|
setAccountLabel,
|
2021-02-04 19:15:23 +01:00
|
|
|
} from '../../../../store/actions';
|
|
|
|
import EditContact from './edit-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
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const { chainId } = state.metamask.provider;
|
2019-10-29 18:53:51 +01:00
|
|
|
|
2019-07-31 21:56:44 +02:00
|
|
|
return {
|
2020-07-20 16:55:47 +02:00
|
|
|
address: contact ? address : null,
|
2019-10-29 18:53:51 +01:00
|
|
|
chainId,
|
2019-07-31 21:56:44 +02:00
|
|
|
name,
|
|
|
|
memo,
|
2021-04-27 20:25:58 +02:00
|
|
|
viewRoute: CONTACT_VIEW_ROUTE,
|
|
|
|
listRoute: CONTACT_LIST_ROUTE,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
|
|
|
};
|
2019-07-31 21:56:44 +02:00
|
|
|
|
2020-02-15 21:34:12 +01:00
|
|
|
const mapDispatchToProps = (dispatch) => {
|
2019-07-31 21:56:44 +02:00
|
|
|
return {
|
2020-11-03 00:41:28 +01:00
|
|
|
addToAddressBook: (recipient, nickname, memo) =>
|
|
|
|
dispatch(addToAddressBook(recipient, nickname, memo)),
|
|
|
|
removeFromAddressBook: (chainId, addressToRemove) =>
|
|
|
|
dispatch(removeFromAddressBook(chainId, addressToRemove)),
|
|
|
|
setAccountLabel: (address, label) =>
|
|
|
|
dispatch(setAccountLabel(address, label)),
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
|
|
|
};
|
2019-07-31 21:56:44 +02:00
|
|
|
|
|
|
|
export default compose(
|
|
|
|
withRouter,
|
2020-07-14 17:20:41 +02:00
|
|
|
connect(mapStateToProps, mapDispatchToProps),
|
2021-02-04 19:15:23 +01:00
|
|
|
)(EditContact);
|