2021-02-04 19:15:23 +01:00
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import React, { Component } from 'react';
|
|
|
|
import { connect } from 'react-redux';
|
|
|
|
import { withRouter } from 'react-router-dom';
|
|
|
|
import { compose } from 'redux';
|
|
|
|
import log from 'loglevel';
|
|
|
|
import * as actions from '../../store/actions';
|
2021-04-28 21:53:59 +02:00
|
|
|
import txHelper from '../../helpers/utils/tx-helper';
|
2021-02-04 19:15:23 +01:00
|
|
|
import SignatureRequest from '../../components/app/signature-request';
|
2022-08-03 16:56:11 +02:00
|
|
|
import SignatureRequestSIWE from '../../components/app/signature-request-siwe';
|
2021-02-04 19:15:23 +01:00
|
|
|
import SignatureRequestOriginal from '../../components/app/signature-request-original';
|
|
|
|
import Loading from '../../components/ui/loading-screen';
|
|
|
|
import { getMostRecentOverviewPage } from '../../ducks/history/history';
|
2021-04-28 21:53:59 +02:00
|
|
|
import { MESSAGE_TYPE } from '../../../shared/constants/app';
|
|
|
|
import { TRANSACTION_STATUSES } from '../../../shared/constants/transaction';
|
2021-06-23 23:35:25 +02:00
|
|
|
import { getSendTo } from '../../ducks/send';
|
2016-05-03 23:32:22 +02:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
function mapStateToProps(state) {
|
2021-02-04 19:15:23 +01:00
|
|
|
const { metamask, appState } = state;
|
2017-12-05 04:27:42 +01:00
|
|
|
const {
|
|
|
|
unapprovedMsgCount,
|
|
|
|
unapprovedPersonalMsgCount,
|
2018-04-04 01:59:32 +02:00
|
|
|
unapprovedTypedMessagesCount,
|
2021-02-04 19:15:23 +01:00
|
|
|
} = metamask;
|
|
|
|
const { txId } = appState;
|
2017-12-05 04:27:42 +01:00
|
|
|
|
2016-04-14 00:28:44 +02:00
|
|
|
return {
|
|
|
|
identities: state.metamask.identities,
|
2020-06-01 19:54:32 +02:00
|
|
|
mostRecentOverviewPage: getMostRecentOverviewPage(state),
|
2017-01-28 01:11:59 +01:00
|
|
|
unapprovedTxs: state.metamask.unapprovedTxs,
|
|
|
|
unapprovedMsgs: state.metamask.unapprovedMsgs,
|
2017-02-23 01:23:13 +01:00
|
|
|
unapprovedPersonalMsgs: state.metamask.unapprovedPersonalMsgs,
|
2017-09-29 18:24:08 +02:00
|
|
|
unapprovedTypedMessages: state.metamask.unapprovedTypedMessages,
|
2020-02-06 17:38:14 +01:00
|
|
|
index: txId,
|
2016-05-03 23:32:22 +02:00
|
|
|
warning: state.appState.warning,
|
2016-09-08 21:56:04 +02:00
|
|
|
network: state.metamask.network,
|
2021-03-01 16:15:42 +01:00
|
|
|
chainId: state.metamask.provider.chainId,
|
2017-05-16 20:34:53 +02:00
|
|
|
currentCurrency: state.metamask.currentCurrency,
|
2017-06-03 00:18:14 +02:00
|
|
|
blockGasLimit: state.metamask.currentBlockGasLimit,
|
2017-12-05 04:27:42 +01:00
|
|
|
unapprovedMsgCount,
|
|
|
|
unapprovedPersonalMsgCount,
|
2018-04-04 01:59:32 +02:00
|
|
|
unapprovedTypedMessagesCount,
|
2021-06-23 23:35:25 +02:00
|
|
|
sendTo: getSendTo(state),
|
2020-03-06 22:34:56 +01:00
|
|
|
currentNetworkTxList: state.metamask.currentNetworkTxList,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2016-04-14 00:28:44 +02:00
|
|
|
}
|
|
|
|
|
2020-01-13 18:02:54 +01:00
|
|
|
class ConfirmTxScreen extends Component {
|
|
|
|
static propTypes = {
|
2020-06-01 19:54:32 +02:00
|
|
|
mostRecentOverviewPage: PropTypes.string.isRequired,
|
2020-01-13 18:02:54 +01:00
|
|
|
unapprovedMsgCount: PropTypes.number,
|
|
|
|
unapprovedPersonalMsgCount: PropTypes.number,
|
|
|
|
unapprovedTypedMessagesCount: PropTypes.number,
|
|
|
|
network: PropTypes.string,
|
2021-03-01 16:15:42 +01:00
|
|
|
chainId: PropTypes.string,
|
2020-01-13 18:02:54 +01:00
|
|
|
index: PropTypes.number,
|
|
|
|
unapprovedTxs: PropTypes.object,
|
|
|
|
unapprovedMsgs: PropTypes.object,
|
|
|
|
unapprovedPersonalMsgs: PropTypes.object,
|
|
|
|
unapprovedTypedMessages: PropTypes.object,
|
|
|
|
match: PropTypes.shape({
|
|
|
|
params: PropTypes.shape({
|
2020-03-06 22:34:56 +01:00
|
|
|
id: PropTypes.string,
|
2020-01-13 18:02:54 +01:00
|
|
|
}),
|
|
|
|
}),
|
|
|
|
|
2020-03-06 22:34:56 +01:00
|
|
|
currentNetworkTxList: PropTypes.array,
|
2020-01-13 18:02:54 +01:00
|
|
|
currentCurrency: PropTypes.string,
|
|
|
|
blockGasLimit: PropTypes.string,
|
|
|
|
history: PropTypes.object,
|
|
|
|
identities: PropTypes.object,
|
|
|
|
dispatch: PropTypes.func.isRequired,
|
2021-06-23 23:35:25 +02:00
|
|
|
sendTo: PropTypes.string,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2018-04-03 10:03:31 +02:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
getUnapprovedMessagesTotal() {
|
2020-01-13 18:02:54 +01:00
|
|
|
const {
|
|
|
|
unapprovedMsgCount = 0,
|
|
|
|
unapprovedPersonalMsgCount = 0,
|
|
|
|
unapprovedTypedMessagesCount = 0,
|
2021-02-04 19:15:23 +01:00
|
|
|
} = this.props;
|
2020-01-13 18:02:54 +01:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
return (
|
|
|
|
unapprovedTypedMessagesCount +
|
|
|
|
unapprovedMsgCount +
|
|
|
|
unapprovedPersonalMsgCount
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2018-05-29 19:23:06 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
getTxData() {
|
2020-01-13 18:02:54 +01:00
|
|
|
const {
|
|
|
|
network,
|
|
|
|
index,
|
|
|
|
unapprovedTxs,
|
|
|
|
unapprovedMsgs,
|
|
|
|
unapprovedPersonalMsgs,
|
|
|
|
unapprovedTypedMessages,
|
|
|
|
match: { params: { id: transactionId } = {} },
|
2021-03-01 16:15:42 +01:00
|
|
|
chainId,
|
2021-02-04 19:15:23 +01:00
|
|
|
} = this.props;
|
2020-01-13 18:02:54 +01:00
|
|
|
|
|
|
|
const unconfTxList = txHelper(
|
|
|
|
unapprovedTxs,
|
|
|
|
unapprovedMsgs,
|
|
|
|
unapprovedPersonalMsgs,
|
|
|
|
unapprovedTypedMessages,
|
2020-07-14 17:20:41 +02:00
|
|
|
network,
|
2021-03-01 16:15:42 +01:00
|
|
|
chainId,
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2017-11-29 05:24:35 +01:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
log.info(`rendering a combined ${unconfTxList.length} unconf msgs & txs`);
|
2018-05-29 19:23:06 +02:00
|
|
|
|
2020-01-13 18:02:54 +01:00
|
|
|
return transactionId
|
2020-08-19 18:27:05 +02:00
|
|
|
? unconfTxList.find(({ id }) => `${id}` === transactionId)
|
2021-02-04 19:15:23 +01:00
|
|
|
: unconfTxList[index];
|
2018-05-29 19:23:06 +02:00
|
|
|
}
|
|
|
|
|
2022-08-03 16:56:11 +02:00
|
|
|
signatureSelect(txData) {
|
|
|
|
const {
|
|
|
|
type,
|
|
|
|
msgParams: { version, siwe },
|
|
|
|
} = txData;
|
|
|
|
|
2020-01-13 18:02:54 +01:00
|
|
|
// Temporarily direct only v3 and v4 requests to new code.
|
2020-11-03 00:41:28 +01:00
|
|
|
if (
|
|
|
|
type === MESSAGE_TYPE.ETH_SIGN_TYPED_DATA &&
|
|
|
|
(version === 'V3' || version === 'V4')
|
|
|
|
) {
|
2021-02-04 19:15:23 +01:00
|
|
|
return SignatureRequest;
|
2020-01-13 18:02:54 +01:00
|
|
|
}
|
|
|
|
|
2022-08-03 16:56:11 +02:00
|
|
|
if (process.env.SIWE_V1 && siwe?.isSIWEMessage) {
|
|
|
|
return SignatureRequestSIWE;
|
|
|
|
}
|
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
return SignatureRequestOriginal;
|
2017-11-29 05:24:35 +01:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
signMessage(msgData, event) {
|
2021-02-04 19:15:23 +01:00
|
|
|
log.info('conf-tx.js: signing message');
|
|
|
|
const params = msgData.msgParams;
|
|
|
|
params.metamaskId = msgData.id;
|
|
|
|
this.stopPropagation(event);
|
|
|
|
return this.props.dispatch(actions.signMsg(params));
|
2020-01-13 18:02:54 +01:00
|
|
|
}
|
2018-05-29 19:23:06 +02:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
stopPropagation(event) {
|
2021-09-21 20:58:39 +02:00
|
|
|
if (event?.stopPropagation) {
|
2021-02-04 19:15:23 +01:00
|
|
|
event.stopPropagation();
|
2020-01-13 18:02:54 +01:00
|
|
|
}
|
2019-11-04 13:40:46 +01:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
signPersonalMessage(msgData, event) {
|
2021-02-04 19:15:23 +01:00
|
|
|
log.info('conf-tx.js: signing personal message');
|
|
|
|
const params = msgData.msgParams;
|
|
|
|
params.metamaskId = msgData.id;
|
|
|
|
this.stopPropagation(event);
|
|
|
|
return this.props.dispatch(actions.signPersonalMsg(params));
|
2020-01-13 18:02:54 +01:00
|
|
|
}
|
2019-11-04 13:40:46 +01:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
signTypedMessage(msgData, event) {
|
2021-02-04 19:15:23 +01:00
|
|
|
log.info('conf-tx.js: signing typed message');
|
|
|
|
const params = msgData.msgParams;
|
|
|
|
params.metamaskId = msgData.id;
|
|
|
|
this.stopPropagation(event);
|
|
|
|
return this.props.dispatch(actions.signTypedMsg(params));
|
2020-01-13 18:02:54 +01:00
|
|
|
}
|
2017-01-17 08:59:25 +01:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
cancelMessage(msgData, event) {
|
2021-02-04 19:15:23 +01:00
|
|
|
log.info('canceling message');
|
|
|
|
this.stopPropagation(event);
|
|
|
|
return this.props.dispatch(actions.cancelMsg(msgData));
|
2020-01-13 18:02:54 +01:00
|
|
|
}
|
2018-07-14 22:43:55 +02:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
cancelPersonalMessage(msgData, event) {
|
2021-02-04 19:15:23 +01:00
|
|
|
log.info('canceling personal message');
|
|
|
|
this.stopPropagation(event);
|
|
|
|
return this.props.dispatch(actions.cancelPersonalMsg(msgData));
|
2019-11-25 14:33:30 +01:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
cancelTypedMessage(msgData, event) {
|
2021-02-04 19:15:23 +01:00
|
|
|
log.info('canceling typed message');
|
|
|
|
this.stopPropagation(event);
|
|
|
|
return this.props.dispatch(actions.cancelTypedMsg(msgData));
|
2020-01-13 18:02:54 +01:00
|
|
|
}
|
2017-09-08 00:03:25 +02:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
componentDidMount() {
|
2020-01-13 18:02:54 +01:00
|
|
|
const {
|
|
|
|
unapprovedTxs = {},
|
2020-06-01 19:54:32 +02:00
|
|
|
history,
|
|
|
|
mostRecentOverviewPage,
|
2020-01-13 18:02:54 +01:00
|
|
|
network,
|
2021-03-01 16:15:42 +01:00
|
|
|
chainId,
|
2021-06-23 23:35:25 +02:00
|
|
|
sendTo,
|
2021-02-04 19:15:23 +01:00
|
|
|
} = this.props;
|
2021-03-01 16:15:42 +01:00
|
|
|
const unconfTxList = txHelper(unapprovedTxs, {}, {}, {}, network, chainId);
|
2020-01-13 18:02:54 +01:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
if (
|
|
|
|
unconfTxList.length === 0 &&
|
2021-06-23 23:35:25 +02:00
|
|
|
!sendTo &&
|
2020-11-03 00:41:28 +01:00
|
|
|
this.getUnapprovedMessagesTotal() === 0
|
|
|
|
) {
|
2021-02-04 19:15:23 +01:00
|
|
|
history.push(mostRecentOverviewPage);
|
2020-01-13 18:02:54 +01:00
|
|
|
}
|
|
|
|
}
|
2016-05-03 23:32:22 +02:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
componentDidUpdate(prevProps) {
|
2020-01-13 18:02:54 +01:00
|
|
|
const {
|
|
|
|
unapprovedTxs = {},
|
|
|
|
network,
|
2021-03-01 16:15:42 +01:00
|
|
|
chainId,
|
2020-03-06 22:34:56 +01:00
|
|
|
currentNetworkTxList,
|
2021-06-23 23:35:25 +02:00
|
|
|
sendTo,
|
2020-01-13 18:02:54 +01:00
|
|
|
history,
|
|
|
|
match: { params: { id: transactionId } = {} },
|
2020-06-01 19:54:32 +02:00
|
|
|
mostRecentOverviewPage,
|
2021-02-04 19:15:23 +01:00
|
|
|
} = this.props;
|
2020-01-13 18:02:54 +01:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
let prevTx;
|
2020-01-13 18:02:54 +01:00
|
|
|
|
|
|
|
if (transactionId) {
|
2021-02-04 19:15:23 +01:00
|
|
|
prevTx = currentNetworkTxList.find(({ id }) => `${id}` === transactionId);
|
2020-01-13 18:02:54 +01:00
|
|
|
} else {
|
2021-02-04 19:15:23 +01:00
|
|
|
const { index: prevIndex, unapprovedTxs: prevUnapprovedTxs } = prevProps;
|
2021-03-01 16:15:42 +01:00
|
|
|
const prevUnconfTxList = txHelper(
|
|
|
|
prevUnapprovedTxs,
|
|
|
|
{},
|
|
|
|
{},
|
|
|
|
{},
|
|
|
|
network,
|
|
|
|
chainId,
|
|
|
|
);
|
2021-02-04 19:15:23 +01:00
|
|
|
const prevTxData = prevUnconfTxList[prevIndex] || {};
|
|
|
|
prevTx =
|
|
|
|
currentNetworkTxList.find(({ id }) => id === prevTxData.id) || {};
|
2020-01-13 18:02:54 +01:00
|
|
|
}
|
|
|
|
|
2021-03-01 16:15:42 +01:00
|
|
|
const unconfTxList = txHelper(unapprovedTxs, {}, {}, {}, network, chainId);
|
2020-01-13 18:02:54 +01:00
|
|
|
|
2020-11-07 08:38:12 +01:00
|
|
|
if (prevTx && prevTx.status === TRANSACTION_STATUSES.DROPPED) {
|
2020-11-03 00:41:28 +01:00
|
|
|
this.props.dispatch(
|
|
|
|
actions.showModal({
|
|
|
|
name: 'TRANSACTION_CONFIRMED',
|
|
|
|
onSubmit: () => history.push(mostRecentOverviewPage),
|
|
|
|
}),
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-01-13 18:02:54 +01:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
return;
|
2020-01-13 18:02:54 +01:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
if (
|
|
|
|
unconfTxList.length === 0 &&
|
2021-06-23 23:35:25 +02:00
|
|
|
!sendTo &&
|
2020-11-03 00:41:28 +01:00
|
|
|
this.getUnapprovedMessagesTotal() === 0
|
|
|
|
) {
|
2021-02-04 19:15:23 +01:00
|
|
|
this.props.history.push(mostRecentOverviewPage);
|
2020-01-13 18:02:54 +01:00
|
|
|
}
|
2017-03-22 23:14:33 +01:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
render() {
|
2021-02-04 19:15:23 +01:00
|
|
|
const { currentCurrency, blockGasLimit } = this.props;
|
2017-02-23 23:23:45 +01:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const txData = this.getTxData() || {};
|
2022-08-03 16:56:11 +02:00
|
|
|
const { msgParams } = txData;
|
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
log.debug('msgParams detected, rendering pending msg');
|
2017-09-29 18:24:08 +02:00
|
|
|
|
2020-01-13 18:02:54 +01:00
|
|
|
if (!msgParams) {
|
2021-02-04 19:15:23 +01:00
|
|
|
return <Loading />;
|
2020-01-13 18:02:54 +01:00
|
|
|
}
|
2016-05-03 23:32:22 +02:00
|
|
|
|
2022-08-03 16:56:11 +02:00
|
|
|
const SigComponent = this.signatureSelect(txData);
|
2020-01-13 18:02:54 +01:00
|
|
|
return (
|
|
|
|
<SigComponent
|
|
|
|
txData={txData}
|
|
|
|
key={txData.id}
|
|
|
|
identities={this.props.identities}
|
|
|
|
currentCurrency={currentCurrency}
|
|
|
|
blockGasLimit={blockGasLimit}
|
|
|
|
signMessage={this.signMessage.bind(this, txData)}
|
|
|
|
signPersonalMessage={this.signPersonalMessage.bind(this, txData)}
|
|
|
|
signTypedMessage={this.signTypedMessage.bind(this, txData)}
|
|
|
|
cancelMessage={this.cancelMessage.bind(this, txData)}
|
|
|
|
cancelPersonalMessage={this.cancelPersonalMessage.bind(this, txData)}
|
|
|
|
cancelTypedMessage={this.cancelTypedMessage.bind(this, txData)}
|
|
|
|
/>
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-01-13 18:02:54 +01:00
|
|
|
}
|
2017-02-24 01:00:43 +01:00
|
|
|
}
|
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
export default compose(withRouter, connect(mapStateToProps))(ConfirmTxScreen);
|