2021-02-04 19:15:23 +01:00
|
|
|
import { connect } from 'react-redux';
|
2019-07-31 21:56:44 +02:00
|
|
|
import {
|
|
|
|
getAddressBook,
|
|
|
|
getAddressBookEntry,
|
2021-12-10 17:46:24 +01:00
|
|
|
getMetaMaskAccountsOrdered,
|
2021-02-04 19:15:23 +01:00
|
|
|
} from '../../../../selectors';
|
2020-05-04 21:06:28 +02:00
|
|
|
|
2021-06-23 23:35:25 +02:00
|
|
|
import {
|
|
|
|
updateRecipient,
|
|
|
|
updateRecipientUserInput,
|
|
|
|
useMyAccountsForRecipientSearch,
|
|
|
|
useContactListForRecipientSearch,
|
|
|
|
getIsUsingMyAccountForRecipientSearch,
|
|
|
|
getRecipientUserInput,
|
|
|
|
getRecipient,
|
|
|
|
} from '../../../../ducks/send';
|
|
|
|
import {
|
|
|
|
getEnsResolution,
|
|
|
|
getEnsError,
|
|
|
|
getEnsWarning,
|
|
|
|
} from '../../../../ducks/ens';
|
2021-02-04 19:15:23 +01:00
|
|
|
import AddRecipient from './add-recipient.component';
|
2019-07-31 21:56:44 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(AddRecipient);
|
2019-07-31 21:56:44 +02:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
function mapStateToProps(state) {
|
2021-06-23 23:35:25 +02:00
|
|
|
const ensResolution = getEnsResolution(state);
|
2019-07-31 21:56:44 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
let addressBookEntryName = '';
|
2019-07-31 21:56:44 +02:00
|
|
|
if (ensResolution) {
|
2021-02-04 19:15:23 +01:00
|
|
|
const addressBookEntry = getAddressBookEntry(state, ensResolution) || {};
|
|
|
|
addressBookEntryName = addressBookEntry.name;
|
2019-07-31 21:56:44 +02:00
|
|
|
}
|
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const addressBook = getAddressBook(state);
|
2019-07-31 21:56:44 +02:00
|
|
|
|
2021-12-10 17:46:24 +01:00
|
|
|
const ownedAccounts = getMetaMaskAccountsOrdered(state);
|
2020-11-07 00:16:51 +01:00
|
|
|
|
2019-07-31 21:56:44 +02:00
|
|
|
return {
|
|
|
|
addressBook,
|
|
|
|
addressBookEntryName,
|
2020-08-19 18:27:05 +02:00
|
|
|
contacts: addressBook.filter(({ name }) => Boolean(name)),
|
2020-11-07 00:16:51 +01:00
|
|
|
ensResolution,
|
2021-06-23 23:35:25 +02:00
|
|
|
ensError: getEnsError(state),
|
|
|
|
ensWarning: getEnsWarning(state),
|
2019-07-31 21:56:44 +02:00
|
|
|
nonContacts: addressBook.filter(({ name }) => !name),
|
2020-11-07 00:16:51 +01:00
|
|
|
ownedAccounts,
|
2021-06-23 23:35:25 +02:00
|
|
|
isUsingMyAccountsForRecipientSearch: getIsUsingMyAccountForRecipientSearch(
|
|
|
|
state,
|
|
|
|
),
|
|
|
|
userInput: getRecipientUserInput(state),
|
|
|
|
recipient: getRecipient(state),
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2019-07-31 21:56:44 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
function mapDispatchToProps(dispatch) {
|
2019-07-31 21:56:44 +02:00
|
|
|
return {
|
2021-06-23 23:35:25 +02:00
|
|
|
updateRecipient: ({ address, nickname }) =>
|
|
|
|
dispatch(updateRecipient({ address, nickname })),
|
|
|
|
updateRecipientUserInput: (newInput) =>
|
|
|
|
dispatch(updateRecipientUserInput(newInput)),
|
|
|
|
useMyAccountsForRecipientSearch: () =>
|
|
|
|
dispatch(useMyAccountsForRecipientSearch()),
|
|
|
|
useContactListForRecipientSearch: () =>
|
|
|
|
dispatch(useContactListForRecipientSearch()),
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2019-07-31 21:56:44 +02:00
|
|
|
}
|