You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
286 lines
8.0 KiB
286 lines
8.0 KiB
4 years ago
|
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';
|
||
4 years ago
|
import txHelper from '../../helpers/utils/tx-helper';
|
||
4 years ago
|
import SignatureRequest from '../../components/app/signature-request';
|
||
|
import SignatureRequestOriginal from '../../components/app/signature-request-original';
|
||
|
import Loading from '../../components/ui/loading-screen';
|
||
|
import { getMostRecentOverviewPage } from '../../ducks/history/history';
|
||
4 years ago
|
import { MESSAGE_TYPE } from '../../../shared/constants/app';
|
||
|
import { TRANSACTION_STATUSES } from '../../../shared/constants/transaction';
|
||
9 years ago
|
|
||
4 years ago
|
function mapStateToProps(state) {
|
||
4 years ago
|
const { metamask, appState } = state;
|
||
7 years ago
|
const {
|
||
|
unapprovedMsgCount,
|
||
|
unapprovedPersonalMsgCount,
|
||
7 years ago
|
unapprovedTypedMessagesCount,
|
||
4 years ago
|
} = metamask;
|
||
|
const { txId } = appState;
|
||
7 years ago
|
|
||
9 years ago
|
return {
|
||
|
identities: state.metamask.identities,
|
||
5 years ago
|
mostRecentOverviewPage: getMostRecentOverviewPage(state),
|
||
8 years ago
|
unapprovedTxs: state.metamask.unapprovedTxs,
|
||
|
unapprovedMsgs: state.metamask.unapprovedMsgs,
|
||
8 years ago
|
unapprovedPersonalMsgs: state.metamask.unapprovedPersonalMsgs,
|
||
7 years ago
|
unapprovedTypedMessages: state.metamask.unapprovedTypedMessages,
|
||
5 years ago
|
index: txId,
|
||
9 years ago
|
warning: state.appState.warning,
|
||
8 years ago
|
network: state.metamask.network,
|
||
4 years ago
|
chainId: state.metamask.provider.chainId,
|
||
8 years ago
|
currentCurrency: state.metamask.currentCurrency,
|
||
8 years ago
|
blockGasLimit: state.metamask.currentBlockGasLimit,
|
||
7 years ago
|
unapprovedMsgCount,
|
||
|
unapprovedPersonalMsgCount,
|
||
7 years ago
|
unapprovedTypedMessagesCount,
|
||
7 years ago
|
send: state.metamask.send,
|
||
5 years ago
|
currentNetworkTxList: state.metamask.currentNetworkTxList,
|
||
4 years ago
|
};
|
||
9 years ago
|
}
|
||
|
|
||
5 years ago
|
class ConfirmTxScreen extends Component {
|
||
|
static propTypes = {
|
||
5 years ago
|
mostRecentOverviewPage: PropTypes.string.isRequired,
|
||
5 years ago
|
unapprovedMsgCount: PropTypes.number,
|
||
|
unapprovedPersonalMsgCount: PropTypes.number,
|
||
|
unapprovedTypedMessagesCount: PropTypes.number,
|
||
|
network: PropTypes.string,
|
||
4 years ago
|
chainId: PropTypes.string,
|
||
5 years ago
|
index: PropTypes.number,
|
||
|
unapprovedTxs: PropTypes.object,
|
||
|
unapprovedMsgs: PropTypes.object,
|
||
|
unapprovedPersonalMsgs: PropTypes.object,
|
||
|
unapprovedTypedMessages: PropTypes.object,
|
||
|
match: PropTypes.shape({
|
||
|
params: PropTypes.shape({
|
||
5 years ago
|
id: PropTypes.string,
|
||
5 years ago
|
}),
|
||
|
}),
|
||
|
|
||
5 years ago
|
currentNetworkTxList: PropTypes.array,
|
||
5 years ago
|
currentCurrency: PropTypes.string,
|
||
|
blockGasLimit: PropTypes.string,
|
||
|
history: PropTypes.object,
|
||
|
identities: PropTypes.object,
|
||
|
dispatch: PropTypes.func.isRequired,
|
||
|
send: PropTypes.shape({
|
||
|
to: PropTypes.string,
|
||
|
}).isRequired,
|
||
4 years ago
|
};
|
||
7 years ago
|
|
||
4 years ago
|
getUnapprovedMessagesTotal() {
|
||
5 years ago
|
const {
|
||
|
unapprovedMsgCount = 0,
|
||
|
unapprovedPersonalMsgCount = 0,
|
||
|
unapprovedTypedMessagesCount = 0,
|
||
4 years ago
|
} = this.props;
|
||
5 years ago
|
|
||
4 years ago
|
return (
|
||
|
unapprovedTypedMessagesCount +
|
||
|
unapprovedMsgCount +
|
||
|
unapprovedPersonalMsgCount
|
||
4 years ago
|
);
|
||
7 years ago
|
}
|
||
|
|
||
4 years ago
|
getTxData() {
|
||
5 years ago
|
const {
|
||
|
network,
|
||
|
index,
|
||
|
unapprovedTxs,
|
||
|
unapprovedMsgs,
|
||
|
unapprovedPersonalMsgs,
|
||
|
unapprovedTypedMessages,
|
||
|
match: { params: { id: transactionId } = {} },
|
||
4 years ago
|
chainId,
|
||
4 years ago
|
} = this.props;
|
||
5 years ago
|
|
||
|
const unconfTxList = txHelper(
|
||
|
unapprovedTxs,
|
||
|
unapprovedMsgs,
|
||
|
unapprovedPersonalMsgs,
|
||
|
unapprovedTypedMessages,
|
||
4 years ago
|
network,
|
||
4 years ago
|
chainId,
|
||
4 years ago
|
);
|
||
7 years ago
|
|
||
4 years ago
|
log.info(`rendering a combined ${unconfTxList.length} unconf msgs & txs`);
|
||
7 years ago
|
|
||
5 years ago
|
return transactionId
|
||
4 years ago
|
? unconfTxList.find(({ id }) => `${id}` === transactionId)
|
||
4 years ago
|
: unconfTxList[index];
|
||
7 years ago
|
}
|
||
|
|
||
4 years ago
|
signatureSelect(type, version) {
|
||
5 years ago
|
// Temporarily direct only v3 and v4 requests to new code.
|
||
4 years ago
|
if (
|
||
|
type === MESSAGE_TYPE.ETH_SIGN_TYPED_DATA &&
|
||
|
(version === 'V3' || version === 'V4')
|
||
|
) {
|
||
4 years ago
|
return SignatureRequest;
|
||
5 years ago
|
}
|
||
|
|
||
4 years ago
|
return SignatureRequestOriginal;
|
||
7 years ago
|
}
|
||
|
|
||
4 years ago
|
signMessage(msgData, event) {
|
||
4 years ago
|
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));
|
||
5 years ago
|
}
|
||
7 years ago
|
|
||
4 years ago
|
stopPropagation(event) {
|
||
5 years ago
|
if (event.stopPropagation) {
|
||
4 years ago
|
event.stopPropagation();
|
||
5 years ago
|
}
|
||
5 years ago
|
}
|
||
|
|
||
4 years ago
|
signPersonalMessage(msgData, event) {
|
||
4 years ago
|
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));
|
||
5 years ago
|
}
|
||
5 years ago
|
|
||
4 years ago
|
signTypedMessage(msgData, event) {
|
||
4 years ago
|
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));
|
||
5 years ago
|
}
|
||
8 years ago
|
|
||
4 years ago
|
cancelMessage(msgData, event) {
|
||
4 years ago
|
log.info('canceling message');
|
||
|
this.stopPropagation(event);
|
||
|
return this.props.dispatch(actions.cancelMsg(msgData));
|
||
5 years ago
|
}
|
||
6 years ago
|
|
||
4 years ago
|
cancelPersonalMessage(msgData, event) {
|
||
4 years ago
|
log.info('canceling personal message');
|
||
|
this.stopPropagation(event);
|
||
|
return this.props.dispatch(actions.cancelPersonalMsg(msgData));
|
||
5 years ago
|
}
|
||
|
|
||
4 years ago
|
cancelTypedMessage(msgData, event) {
|
||
4 years ago
|
log.info('canceling typed message');
|
||
|
this.stopPropagation(event);
|
||
|
return this.props.dispatch(actions.cancelTypedMsg(msgData));
|
||
5 years ago
|
}
|
||
7 years ago
|
|
||
4 years ago
|
componentDidMount() {
|
||
5 years ago
|
const {
|
||
|
unapprovedTxs = {},
|
||
5 years ago
|
history,
|
||
|
mostRecentOverviewPage,
|
||
5 years ago
|
network,
|
||
4 years ago
|
chainId,
|
||
5 years ago
|
send,
|
||
4 years ago
|
} = this.props;
|
||
4 years ago
|
const unconfTxList = txHelper(unapprovedTxs, {}, {}, {}, network, chainId);
|
||
5 years ago
|
|
||
4 years ago
|
if (
|
||
|
unconfTxList.length === 0 &&
|
||
|
!send.to &&
|
||
|
this.getUnapprovedMessagesTotal() === 0
|
||
|
) {
|
||
4 years ago
|
history.push(mostRecentOverviewPage);
|
||
5 years ago
|
}
|
||
|
}
|
||
9 years ago
|
|
||
4 years ago
|
componentDidUpdate(prevProps) {
|
||
5 years ago
|
const {
|
||
|
unapprovedTxs = {},
|
||
|
network,
|
||
4 years ago
|
chainId,
|
||
5 years ago
|
currentNetworkTxList,
|
||
5 years ago
|
send,
|
||
|
history,
|
||
|
match: { params: { id: transactionId } = {} },
|
||
5 years ago
|
mostRecentOverviewPage,
|
||
4 years ago
|
} = this.props;
|
||
5 years ago
|
|
||
4 years ago
|
let prevTx;
|
||
5 years ago
|
|
||
|
if (transactionId) {
|
||
4 years ago
|
prevTx = currentNetworkTxList.find(({ id }) => `${id}` === transactionId);
|
||
5 years ago
|
} else {
|
||
4 years ago
|
const { index: prevIndex, unapprovedTxs: prevUnapprovedTxs } = prevProps;
|
||
4 years ago
|
const prevUnconfTxList = txHelper(
|
||
|
prevUnapprovedTxs,
|
||
|
{},
|
||
|
{},
|
||
|
{},
|
||
|
network,
|
||
|
chainId,
|
||
|
);
|
||
4 years ago
|
const prevTxData = prevUnconfTxList[prevIndex] || {};
|
||
|
prevTx =
|
||
|
currentNetworkTxList.find(({ id }) => id === prevTxData.id) || {};
|
||
5 years ago
|
}
|
||
|
|
||
4 years ago
|
const unconfTxList = txHelper(unapprovedTxs, {}, {}, {}, network, chainId);
|
||
5 years ago
|
|
||
4 years ago
|
if (prevTx && prevTx.status === TRANSACTION_STATUSES.DROPPED) {
|
||
4 years ago
|
this.props.dispatch(
|
||
|
actions.showModal({
|
||
|
name: 'TRANSACTION_CONFIRMED',
|
||
|
onSubmit: () => history.push(mostRecentOverviewPage),
|
||
|
}),
|
||
4 years ago
|
);
|
||
5 years ago
|
|
||
4 years ago
|
return;
|
||
5 years ago
|
}
|
||
|
|
||
4 years ago
|
if (
|
||
|
unconfTxList.length === 0 &&
|
||
|
!send.to &&
|
||
|
this.getUnapprovedMessagesTotal() === 0
|
||
|
) {
|
||
4 years ago
|
this.props.history.push(mostRecentOverviewPage);
|
||
5 years ago
|
}
|
||
8 years ago
|
}
|
||
|
|
||
4 years ago
|
render() {
|
||
4 years ago
|
const { currentCurrency, blockGasLimit } = this.props;
|
||
8 years ago
|
|
||
4 years ago
|
const txData = this.getTxData() || {};
|
||
4 years ago
|
const {
|
||
|
msgParams,
|
||
|
type,
|
||
|
msgParams: { version },
|
||
4 years ago
|
} = txData;
|
||
|
log.debug('msgParams detected, rendering pending msg');
|
||
7 years ago
|
|
||
5 years ago
|
if (!msgParams) {
|
||
4 years ago
|
return <Loading />;
|
||
5 years ago
|
}
|
||
9 years ago
|
|
||
4 years ago
|
const SigComponent = this.signatureSelect(type, version);
|
||
5 years ago
|
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)}
|
||
|
/>
|
||
4 years ago
|
);
|
||
5 years ago
|
}
|
||
8 years ago
|
}
|
||
|
|
||
4 years ago
|
export default compose(withRouter, connect(mapStateToProps))(ConfirmTxScreen);
|