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,
|
2023-02-09 18:45:52 +01:00
|
|
|
currentNetworkTxListSelector,
|
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,
|
2022-05-04 18:54:46 +02:00
|
|
|
addHistoryEntry,
|
2021-06-23 23:35:25 +02:00
|
|
|
} from '../../../../ducks/send';
|
|
|
|
import {
|
2022-11-21 16:19:11 +01:00
|
|
|
getDomainResolution,
|
|
|
|
getDomainError,
|
|
|
|
getDomainWarning,
|
|
|
|
} from '../../../../ducks/domains';
|
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) {
|
2022-11-21 16:19:11 +01:00
|
|
|
const domainResolution = getDomainResolution(state);
|
2019-07-31 21:56:44 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
let addressBookEntryName = '';
|
2022-11-21 16:19:11 +01:00
|
|
|
if (domainResolution) {
|
|
|
|
const addressBookEntry = getAddressBookEntry(state, domainResolution) || {};
|
2021-02-04 19:15:23 +01:00
|
|
|
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
|
|
|
|
2023-02-09 18:45:52 +01:00
|
|
|
const txList = [...currentNetworkTxListSelector(state)].reverse();
|
|
|
|
|
|
|
|
const nonContacts = addressBook
|
|
|
|
.filter(({ name }) => !name)
|
|
|
|
.map((nonContact) => {
|
|
|
|
const nonContactTx = txList.find(
|
|
|
|
(transaction) =>
|
|
|
|
transaction.txParams.to === nonContact.address.toLowerCase(),
|
|
|
|
);
|
|
|
|
return { ...nonContact, timestamp: nonContactTx?.time };
|
|
|
|
});
|
|
|
|
|
|
|
|
nonContacts.sort((a, b) => {
|
|
|
|
return b.timestamp - a.timestamp;
|
|
|
|
});
|
|
|
|
|
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)),
|
2022-11-21 16:19:11 +01:00
|
|
|
domainResolution,
|
|
|
|
domainError: getDomainError(state),
|
|
|
|
domainWarning: getDomainWarning(state),
|
2023-02-09 18:45:52 +01:00
|
|
|
nonContacts,
|
2020-11-07 00:16:51 +01:00
|
|
|
ownedAccounts,
|
2022-07-31 20:26:40 +02:00
|
|
|
isUsingMyAccountsForRecipientSearch:
|
|
|
|
getIsUsingMyAccountForRecipientSearch(state),
|
2021-06-23 23:35:25 +02:00
|
|
|
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 {
|
2022-05-04 18:54:46 +02:00
|
|
|
addHistoryEntry: (entry) => dispatch(addHistoryEntry(entry)),
|
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
|
|
|
}
|