2021-02-04 19:15:23 +01:00
|
|
|
import { connect } from 'react-redux';
|
2021-09-17 06:37:50 +02:00
|
|
|
import { addToAddressBook, cancelTx } from '../../../store/actions';
|
2018-04-26 18:38:38 +02:00
|
|
|
import {
|
2021-06-23 23:35:25 +02:00
|
|
|
resetSendState,
|
2021-09-17 06:37:50 +02:00
|
|
|
getSendStage,
|
2018-04-26 18:38:38 +02:00
|
|
|
getSendTo,
|
2019-03-05 16:45:01 +01:00
|
|
|
getSendErrors,
|
2021-06-23 23:35:25 +02:00
|
|
|
isSendFormInvalid,
|
|
|
|
signTransaction,
|
2021-09-17 06:37:50 +02:00
|
|
|
getDraftTransactionID,
|
2021-06-23 23:35:25 +02:00
|
|
|
} from '../../../ducks/send';
|
2021-02-04 19:15:23 +01:00
|
|
|
import { getMostRecentOverviewPage } from '../../../ducks/history/history';
|
2021-04-28 21:53:59 +02:00
|
|
|
import { addHexPrefix } from '../../../../app/scripts/lib/util';
|
2021-06-23 23:35:25 +02:00
|
|
|
import { getSendToAccounts } from '../../../ducks/metamask/metamask';
|
2021-02-04 19:15:23 +01:00
|
|
|
import SendFooter from './send-footer.component';
|
2018-04-26 18:38:38 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(SendFooter);
|
2018-04-26 18:38:38 +02:00
|
|
|
|
2021-06-23 23:35:25 +02:00
|
|
|
function addressIsNew(toAccounts, newAddress) {
|
|
|
|
const newAddressNormalized = newAddress.toLowerCase();
|
|
|
|
const foundMatching = toAccounts.some(
|
|
|
|
({ address }) => address.toLowerCase() === newAddressNormalized,
|
|
|
|
);
|
|
|
|
return !foundMatching;
|
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
function mapStateToProps(state) {
|
2018-04-26 18:38:38 +02:00
|
|
|
return {
|
2021-06-23 23:35:25 +02:00
|
|
|
disabled: isSendFormInvalid(state),
|
2018-04-26 18:38:38 +02:00
|
|
|
to: getSendTo(state),
|
|
|
|
toAccounts: getSendToAccounts(state),
|
2021-09-17 06:37:50 +02:00
|
|
|
sendStage: getSendStage(state),
|
2019-03-05 16:45:01 +01:00
|
|
|
sendErrors: getSendErrors(state),
|
2021-09-17 06:37:50 +02:00
|
|
|
draftTransactionID: getDraftTransactionID(state),
|
2020-06-01 19:54:32 +02:00
|
|
|
mostRecentOverviewPage: getMostRecentOverviewPage(state),
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2018-04-26 18:38:38 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
function mapDispatchToProps(dispatch) {
|
2018-04-26 18:38:38 +02:00
|
|
|
return {
|
2021-06-23 23:35:25 +02:00
|
|
|
resetSendState: () => dispatch(resetSendState()),
|
2021-09-17 06:37:50 +02:00
|
|
|
cancelTx: (t) => dispatch(cancelTx(t)),
|
2021-06-23 23:35:25 +02:00
|
|
|
sign: () => dispatch(signTransaction()),
|
2018-04-26 18:38:38 +02:00
|
|
|
addToAddressBookIfNew: (newAddress, toAccounts, nickname = '') => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const hexPrefixedAddress = addHexPrefix(newAddress);
|
2019-03-29 03:18:53 +01:00
|
|
|
if (addressIsNew(toAccounts, hexPrefixedAddress)) {
|
2018-04-26 18:38:38 +02:00
|
|
|
// TODO: nickname, i.e. addToAddressBook(recipient, nickname)
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(addToAddressBook(hexPrefixedAddress, nickname));
|
2018-04-26 18:38:38 +02:00
|
|
|
}
|
2018-04-27 02:38:14 +02:00
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2018-04-26 18:38:38 +02:00
|
|
|
}
|