You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
53 lines
1.5 KiB
53 lines
1.5 KiB
4 years ago
|
import { compose } from 'redux';
|
||
|
import { connect } from 'react-redux';
|
||
|
import { withRouter } from 'react-router-dom';
|
||
|
import { getAddressBookEntry } from '../../../../selectors';
|
||
5 years ago
|
import {
|
||
|
CONTACT_VIEW_ROUTE,
|
||
|
CONTACT_LIST_ROUTE,
|
||
4 years ago
|
} from '../../../../helpers/constants/routes';
|
||
4 years ago
|
import {
|
||
|
addToAddressBook,
|
||
|
removeFromAddressBook,
|
||
4 years ago
|
} from '../../../../store/actions';
|
||
|
import EditContact from './edit-contact.component';
|
||
5 years ago
|
|
||
|
const mapStateToProps = (state, ownProps) => {
|
||
4 years ago
|
const { location } = ownProps;
|
||
|
const { pathname } = location;
|
||
|
const pathNameTail = pathname.match(/[^/]+$/u)[0];
|
||
|
const pathNameTailIsAddress = pathNameTail.includes('0x');
|
||
4 years ago
|
const address = pathNameTailIsAddress
|
||
|
? pathNameTail.toLowerCase()
|
||
4 years ago
|
: ownProps.match.params.id;
|
||
5 years ago
|
|
||
4 years ago
|
const contact =
|
||
4 years ago
|
getAddressBookEntry(state, address) || state.metamask.identities[address];
|
||
|
const { memo, name } = contact || {};
|
||
5 years ago
|
|
||
4 years ago
|
const { chainId } = state.metamask.provider;
|
||
5 years ago
|
|
||
5 years ago
|
return {
|
||
4 years ago
|
address: contact ? address : null,
|
||
5 years ago
|
chainId,
|
||
5 years ago
|
name,
|
||
|
memo,
|
||
4 years ago
|
viewRoute: CONTACT_VIEW_ROUTE,
|
||
|
listRoute: CONTACT_LIST_ROUTE,
|
||
4 years ago
|
};
|
||
|
};
|
||
5 years ago
|
|
||
5 years ago
|
const mapDispatchToProps = (dispatch) => {
|
||
5 years ago
|
return {
|
||
4 years ago
|
addToAddressBook: (recipient, nickname, memo) =>
|
||
|
dispatch(addToAddressBook(recipient, nickname, memo)),
|
||
|
removeFromAddressBook: (chainId, addressToRemove) =>
|
||
|
dispatch(removeFromAddressBook(chainId, addressToRemove)),
|
||
4 years ago
|
};
|
||
|
};
|
||
5 years ago
|
|
||
|
export default compose(
|
||
|
withRouter,
|
||
4 years ago
|
connect(mapStateToProps, mapDispatchToProps),
|
||
4 years ago
|
)(EditContact);
|