2021-02-04 19:15:23 +01:00
|
|
|
import { connect } from 'react-redux';
|
|
|
|
import { clearConfirmTransaction } from '../../../ducks/confirm-transaction/confirm-transaction.duck';
|
|
|
|
import { accountsWithSendEtherInfoSelector } from '../../../selectors';
|
|
|
|
import { getAccountByAddress } from '../../../helpers/utils/util';
|
2021-04-28 21:53:59 +02:00
|
|
|
import { MESSAGE_TYPE } from '../../../../shared/constants/app';
|
2021-02-04 19:15:23 +01:00
|
|
|
import SignatureRequest from './signature-request.component';
|
2019-11-04 13:40:46 +01:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
function mapStateToProps(state) {
|
2019-11-04 13:40:46 +01:00
|
|
|
return {
|
2020-03-06 22:34:56 +01:00
|
|
|
// not forwarded to component
|
|
|
|
allAccounts: accountsWithSendEtherInfoSelector(state),
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2019-11-04 13:40:46 +01:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
function mapDispatchToProps(dispatch) {
|
2019-11-04 13:40:46 +01:00
|
|
|
return {
|
|
|
|
clearConfirmTransaction: () => dispatch(clearConfirmTransaction()),
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2019-11-04 13:40:46 +01:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
function mergeProps(stateProps, dispatchProps, ownProps) {
|
2021-02-04 19:15:23 +01:00
|
|
|
const { allAccounts } = stateProps;
|
2019-11-04 13:40:46 +01:00
|
|
|
const {
|
|
|
|
signPersonalMessage,
|
|
|
|
signTypedMessage,
|
|
|
|
cancelPersonalMessage,
|
|
|
|
cancelTypedMessage,
|
|
|
|
signMessage,
|
|
|
|
cancelMessage,
|
|
|
|
txData,
|
2021-02-04 19:15:23 +01:00
|
|
|
} = ownProps;
|
2019-11-04 13:40:46 +01:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
const {
|
|
|
|
type,
|
|
|
|
msgParams: { from },
|
2021-02-04 19:15:23 +01:00
|
|
|
} = txData;
|
2020-03-06 22:34:56 +01:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const fromAccount = getAccountByAddress(allAccounts, from);
|
2019-11-04 13:40:46 +01:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
let cancel;
|
|
|
|
let sign;
|
2019-11-04 13:40:46 +01:00
|
|
|
|
2020-06-04 21:22:45 +02:00
|
|
|
if (type === MESSAGE_TYPE.PERSONAL_SIGN) {
|
2021-02-04 19:15:23 +01:00
|
|
|
cancel = cancelPersonalMessage;
|
|
|
|
sign = signPersonalMessage;
|
2020-06-04 21:22:45 +02:00
|
|
|
} else if (type === MESSAGE_TYPE.ETH_SIGN_TYPED_DATA) {
|
2021-02-04 19:15:23 +01:00
|
|
|
cancel = cancelTypedMessage;
|
|
|
|
sign = signTypedMessage;
|
2020-06-04 21:22:45 +02:00
|
|
|
} else if (type === MESSAGE_TYPE.ETH_SIGN) {
|
2021-02-04 19:15:23 +01:00
|
|
|
cancel = cancelMessage;
|
|
|
|
sign = signMessage;
|
2019-11-04 13:40:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
...ownProps,
|
2020-03-06 22:34:56 +01:00
|
|
|
...dispatchProps,
|
|
|
|
fromAccount,
|
2019-11-04 13:40:46 +01:00
|
|
|
txData,
|
|
|
|
cancel,
|
|
|
|
sign,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2019-11-04 13:40:46 +01:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export default connect(
|
|
|
|
mapStateToProps,
|
|
|
|
mapDispatchToProps,
|
|
|
|
mergeProps,
|
2021-02-04 19:15:23 +01:00
|
|
|
)(SignatureRequest);
|