|
|
|
@ -1,5 +1,5 @@ |
|
|
|
|
import PropTypes from 'prop-types' |
|
|
|
|
import React, { Component } from 'react' |
|
|
|
|
import { inherits } from 'util' |
|
|
|
|
import { connect } from 'react-redux' |
|
|
|
|
import { withRouter } from 'react-router-dom' |
|
|
|
|
import { compose } from 'recompose' |
|
|
|
@ -12,11 +12,6 @@ import SignatureRequestOriginal from '../../components/app/signature-request-ori |
|
|
|
|
import Loading from '../../components/ui/loading-screen' |
|
|
|
|
import { DEFAULT_ROUTE } from '../../helpers/constants/routes' |
|
|
|
|
|
|
|
|
|
export default compose( |
|
|
|
|
withRouter, |
|
|
|
|
connect(mapStateToProps) |
|
|
|
|
)(ConfirmTxScreen) |
|
|
|
|
|
|
|
|
|
function mapStateToProps (state) { |
|
|
|
|
const { metamask } = state |
|
|
|
|
const { |
|
|
|
@ -45,12 +40,35 @@ function mapStateToProps (state) { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
inherits(ConfirmTxScreen, Component) |
|
|
|
|
function ConfirmTxScreen () { |
|
|
|
|
Component.call(this) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
ConfirmTxScreen.prototype.getUnapprovedMessagesTotal = function () { |
|
|
|
|
class ConfirmTxScreen extends Component { |
|
|
|
|
static propTypes = { |
|
|
|
|
unapprovedMsgCount: PropTypes.number, |
|
|
|
|
unapprovedPersonalMsgCount: PropTypes.number, |
|
|
|
|
unapprovedTypedMessagesCount: PropTypes.number, |
|
|
|
|
network: PropTypes.string, |
|
|
|
|
index: PropTypes.number, |
|
|
|
|
unapprovedTxs: PropTypes.object, |
|
|
|
|
unapprovedMsgs: PropTypes.object, |
|
|
|
|
unapprovedPersonalMsgs: PropTypes.object, |
|
|
|
|
unapprovedTypedMessages: PropTypes.object, |
|
|
|
|
match: PropTypes.shape({ |
|
|
|
|
params: PropTypes.shape({ |
|
|
|
|
id: PropTypes.number, |
|
|
|
|
}), |
|
|
|
|
}), |
|
|
|
|
|
|
|
|
|
selectedAddressTxList: PropTypes.array, |
|
|
|
|
currentCurrency: PropTypes.string, |
|
|
|
|
blockGasLimit: PropTypes.string, |
|
|
|
|
history: PropTypes.object, |
|
|
|
|
identities: PropTypes.object, |
|
|
|
|
dispatch: PropTypes.func.isRequired, |
|
|
|
|
send: PropTypes.shape({ |
|
|
|
|
to: PropTypes.string, |
|
|
|
|
}).isRequired, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
getUnapprovedMessagesTotal () { |
|
|
|
|
const { |
|
|
|
|
unapprovedMsgCount = 0, |
|
|
|
|
unapprovedPersonalMsgCount = 0, |
|
|
|
@ -60,7 +78,90 @@ ConfirmTxScreen.prototype.getUnapprovedMessagesTotal = function () { |
|
|
|
|
return unapprovedTypedMessagesCount + unapprovedMsgCount + unapprovedPersonalMsgCount |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
ConfirmTxScreen.prototype.componentDidMount = function () { |
|
|
|
|
getTxData () { |
|
|
|
|
const { |
|
|
|
|
network, |
|
|
|
|
index, |
|
|
|
|
unapprovedTxs, |
|
|
|
|
unapprovedMsgs, |
|
|
|
|
unapprovedPersonalMsgs, |
|
|
|
|
unapprovedTypedMessages, |
|
|
|
|
match: { params: { id: transactionId } = {} }, |
|
|
|
|
} = this.props |
|
|
|
|
|
|
|
|
|
const unconfTxList = txHelper( |
|
|
|
|
unapprovedTxs, |
|
|
|
|
unapprovedMsgs, |
|
|
|
|
unapprovedPersonalMsgs, |
|
|
|
|
unapprovedTypedMessages, |
|
|
|
|
network |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
log.info(`rendering a combined ${unconfTxList.length} unconf msgs & txs`) |
|
|
|
|
|
|
|
|
|
return transactionId |
|
|
|
|
? R.find(({ id }) => id + '' === transactionId)(unconfTxList) |
|
|
|
|
: unconfTxList[index] |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
signatureSelect (type, version) { |
|
|
|
|
// Temporarily direct only v3 and v4 requests to new code.
|
|
|
|
|
if (type === 'eth_signTypedData' && (version === 'V3' || version === 'V4')) { |
|
|
|
|
return SignatureRequest |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return SignatureRequestOriginal |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
signMessage (msgData, event) { |
|
|
|
|
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)) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
stopPropagation (event) { |
|
|
|
|
if (event.stopPropagation) { |
|
|
|
|
event.stopPropagation() |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
signPersonalMessage (msgData, event) { |
|
|
|
|
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)) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
signTypedMessage (msgData, event) { |
|
|
|
|
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)) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
cancelMessage (msgData, event) { |
|
|
|
|
log.info('canceling message') |
|
|
|
|
this.stopPropagation(event) |
|
|
|
|
return this.props.dispatch(actions.cancelMsg(msgData)) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
cancelPersonalMessage (msgData, event) { |
|
|
|
|
log.info('canceling personal message') |
|
|
|
|
this.stopPropagation(event) |
|
|
|
|
return this.props.dispatch(actions.cancelPersonalMsg(msgData)) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
cancelTypedMessage (msgData, event) { |
|
|
|
|
log.info('canceling typed message') |
|
|
|
|
this.stopPropagation(event) |
|
|
|
|
return this.props.dispatch(actions.cancelTypedMsg(msgData)) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
componentDidMount () { |
|
|
|
|
const { |
|
|
|
|
unapprovedTxs = {}, |
|
|
|
|
network, |
|
|
|
@ -73,7 +174,7 @@ ConfirmTxScreen.prototype.componentDidMount = function () { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
ConfirmTxScreen.prototype.componentDidUpdate = function (prevProps) { |
|
|
|
|
componentDidUpdate (prevProps) { |
|
|
|
|
const { |
|
|
|
|
unapprovedTxs = {}, |
|
|
|
|
network, |
|
|
|
@ -110,46 +211,10 @@ ConfirmTxScreen.prototype.componentDidUpdate = function (prevProps) { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
ConfirmTxScreen.prototype.getTxData = function () { |
|
|
|
|
const { |
|
|
|
|
network, |
|
|
|
|
index, |
|
|
|
|
unapprovedTxs, |
|
|
|
|
unapprovedMsgs, |
|
|
|
|
unapprovedPersonalMsgs, |
|
|
|
|
unapprovedTypedMessages, |
|
|
|
|
match: { params: { id: transactionId } = {} }, |
|
|
|
|
} = this.props |
|
|
|
|
|
|
|
|
|
const unconfTxList = txHelper( |
|
|
|
|
unapprovedTxs, |
|
|
|
|
unapprovedMsgs, |
|
|
|
|
unapprovedPersonalMsgs, |
|
|
|
|
unapprovedTypedMessages, |
|
|
|
|
network |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
log.info(`rendering a combined ${unconfTxList.length} unconf msgs & txs`) |
|
|
|
|
|
|
|
|
|
return transactionId |
|
|
|
|
? R.find(({ id }) => id + '' === transactionId)(unconfTxList) |
|
|
|
|
: unconfTxList[index] |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
ConfirmTxScreen.prototype.signatureSelect = function (type, version) { |
|
|
|
|
// Temporarily direct only v3 and v4 requests to new code.
|
|
|
|
|
if (type === 'eth_signTypedData' && (version === 'V3' || version === 'V4')) { |
|
|
|
|
return SignatureRequest |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return SignatureRequestOriginal |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
ConfirmTxScreen.prototype.render = function () { |
|
|
|
|
render () { |
|
|
|
|
const { |
|
|
|
|
currentCurrency, |
|
|
|
|
blockGasLimit, |
|
|
|
|
conversionRate, |
|
|
|
|
} = this.props |
|
|
|
|
|
|
|
|
|
const txData = this.getTxData() || {} |
|
|
|
@ -167,10 +232,7 @@ ConfirmTxScreen.prototype.render = function () { |
|
|
|
|
<SigComponent |
|
|
|
|
txData={txData} |
|
|
|
|
key={txData.id} |
|
|
|
|
selectedAddress={this.props.selectedAddress} |
|
|
|
|
accounts={this.props.accounts} |
|
|
|
|
identities={this.props.identities} |
|
|
|
|
conversionRate={conversionRate} |
|
|
|
|
currentCurrency={currentCurrency} |
|
|
|
|
blockGasLimit={blockGasLimit} |
|
|
|
|
signMessage={this.signMessage.bind(this, txData)} |
|
|
|
@ -182,51 +244,9 @@ ConfirmTxScreen.prototype.render = function () { |
|
|
|
|
/> |
|
|
|
|
) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
ConfirmTxScreen.prototype.signMessage = function (msgData, event) { |
|
|
|
|
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)) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
ConfirmTxScreen.prototype.stopPropagation = function (event) { |
|
|
|
|
if (event.stopPropagation) { |
|
|
|
|
event.stopPropagation() |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
ConfirmTxScreen.prototype.signPersonalMessage = function (msgData, event) { |
|
|
|
|
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)) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
ConfirmTxScreen.prototype.signTypedMessage = function (msgData, event) { |
|
|
|
|
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)) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
ConfirmTxScreen.prototype.cancelMessage = function (msgData, event) { |
|
|
|
|
log.info('canceling message') |
|
|
|
|
this.stopPropagation(event) |
|
|
|
|
return this.props.dispatch(actions.cancelMsg(msgData)) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
ConfirmTxScreen.prototype.cancelPersonalMessage = function (msgData, event) { |
|
|
|
|
log.info('canceling personal message') |
|
|
|
|
this.stopPropagation(event) |
|
|
|
|
return this.props.dispatch(actions.cancelPersonalMsg(msgData)) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
ConfirmTxScreen.prototype.cancelTypedMessage = function (msgData, event) { |
|
|
|
|
log.info('canceling typed message') |
|
|
|
|
this.stopPropagation(event) |
|
|
|
|
return this.props.dispatch(actions.cancelTypedMsg(msgData)) |
|
|
|
|
} |
|
|
|
|
export default compose( |
|
|
|
|
withRouter, |
|
|
|
|
connect(mapStateToProps) |
|
|
|
|
)(ConfirmTxScreen) |
|
|
|
|