2016-04-14 00:28:44 +02:00
|
|
|
const inherits = require('util').inherits
|
|
|
|
const Component = require('react').Component
|
|
|
|
const h = require('react-hyperscript')
|
2018-03-29 17:00:44 +02:00
|
|
|
const connect = require('react-redux').connect
|
2018-04-04 01:59:32 +02:00
|
|
|
const { withRouter } = require('react-router-dom')
|
2017-11-29 05:24:35 +01:00
|
|
|
const { compose } = require('recompose')
|
2019-03-22 00:03:30 +01:00
|
|
|
const actions = require('../../store/actions')
|
|
|
|
const txHelper = require('../../../lib/tx-helper')
|
2018-04-12 23:06:59 +02:00
|
|
|
const log = require('loglevel')
|
2018-05-29 19:23:06 +02:00
|
|
|
const R = require('ramda')
|
2016-05-03 23:32:22 +02:00
|
|
|
|
2019-03-22 00:03:30 +01:00
|
|
|
const SignatureRequest = require('../../components/app/signature-request')
|
|
|
|
const Loading = require('../../components/ui/loading-screen')
|
|
|
|
const { DEFAULT_ROUTE } = require('../../helpers/constants/routes')
|
|
|
|
const { getMetaMaskAccounts } = require('../../selectors/selectors')
|
2016-04-14 00:28:44 +02:00
|
|
|
|
2017-11-29 05:24:35 +01:00
|
|
|
module.exports = compose(
|
|
|
|
withRouter,
|
|
|
|
connect(mapStateToProps)
|
|
|
|
)(ConfirmTxScreen)
|
2016-04-14 00:28:44 +02:00
|
|
|
|
2016-06-21 22:18:32 +02:00
|
|
|
function mapStateToProps (state) {
|
2017-12-05 04:27:42 +01:00
|
|
|
const { metamask } = state
|
|
|
|
const {
|
|
|
|
unapprovedMsgCount,
|
|
|
|
unapprovedPersonalMsgCount,
|
2018-04-04 01:59:32 +02:00
|
|
|
unapprovedTypedMessagesCount,
|
2017-12-05 04:27:42 +01:00
|
|
|
} = metamask
|
|
|
|
|
2016-04-14 00:28:44 +02:00
|
|
|
return {
|
|
|
|
identities: state.metamask.identities,
|
2018-11-30 23:51:24 +01:00
|
|
|
accounts: getMetaMaskAccounts(state),
|
2017-01-31 00:08:31 +01:00
|
|
|
selectedAddress: state.metamask.selectedAddress,
|
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,
|
2016-04-14 00:28:44 +02:00
|
|
|
index: state.appState.currentView.context,
|
2016-05-03 23:32:22 +02:00
|
|
|
warning: state.appState.warning,
|
2016-09-08 21:56:04 +02:00
|
|
|
network: state.metamask.network,
|
2017-01-04 23:30:14 +01:00
|
|
|
provider: state.metamask.provider,
|
2017-05-12 21:41:31 +02:00
|
|
|
conversionRate: state.metamask.conversionRate,
|
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-09-13 23:31:48 +02:00
|
|
|
computedBalances: state.metamask.computedBalances,
|
2017-12-05 04:27:42 +01:00
|
|
|
unapprovedMsgCount,
|
|
|
|
unapprovedPersonalMsgCount,
|
2018-04-04 01:59:32 +02:00
|
|
|
unapprovedTypedMessagesCount,
|
2017-12-07 05:48:41 +01:00
|
|
|
send: state.metamask.send,
|
2018-03-20 18:58:48 +01:00
|
|
|
selectedAddressTxList: state.metamask.selectedAddressTxList,
|
2016-04-14 00:28:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
inherits(ConfirmTxScreen, Component)
|
2016-06-21 22:18:32 +02:00
|
|
|
function ConfirmTxScreen () {
|
2016-04-14 00:28:44 +02:00
|
|
|
Component.call(this)
|
|
|
|
}
|
|
|
|
|
2018-04-04 01:59:32 +02:00
|
|
|
ConfirmTxScreen.prototype.getUnapprovedMessagesTotal = function () {
|
|
|
|
const {
|
|
|
|
unapprovedMsgCount = 0,
|
|
|
|
unapprovedPersonalMsgCount = 0,
|
|
|
|
unapprovedTypedMessagesCount = 0,
|
|
|
|
} = this.props
|
|
|
|
|
|
|
|
return unapprovedTypedMessagesCount + unapprovedMsgCount + unapprovedPersonalMsgCount
|
|
|
|
}
|
|
|
|
|
2018-04-03 10:03:31 +02:00
|
|
|
ConfirmTxScreen.prototype.componentDidMount = function () {
|
|
|
|
const {
|
|
|
|
unapprovedTxs = {},
|
|
|
|
network,
|
|
|
|
send,
|
|
|
|
} = this.props
|
|
|
|
const unconfTxList = txHelper(unapprovedTxs, {}, {}, {}, network)
|
|
|
|
|
2018-04-04 01:59:32 +02:00
|
|
|
if (unconfTxList.length === 0 && !send.to && this.getUnapprovedMessagesTotal() === 0) {
|
2018-04-03 10:03:31 +02:00
|
|
|
this.props.history.push(DEFAULT_ROUTE)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-20 18:58:48 +01:00
|
|
|
ConfirmTxScreen.prototype.componentDidUpdate = function (prevProps) {
|
|
|
|
const {
|
2018-04-03 10:03:31 +02:00
|
|
|
unapprovedTxs = {},
|
2018-03-20 18:58:48 +01:00
|
|
|
network,
|
|
|
|
selectedAddressTxList,
|
2018-04-03 10:03:31 +02:00
|
|
|
send,
|
2018-05-29 19:23:06 +02:00
|
|
|
history,
|
|
|
|
match: { params: { id: transactionId } = {} },
|
2018-03-20 18:58:48 +01:00
|
|
|
} = this.props
|
2018-05-29 19:23:06 +02:00
|
|
|
|
|
|
|
let prevTx
|
|
|
|
|
|
|
|
if (transactionId) {
|
|
|
|
prevTx = R.find(({ id }) => id + '' === transactionId)(selectedAddressTxList)
|
|
|
|
} else {
|
|
|
|
const { index: prevIndex, unapprovedTxs: prevUnapprovedTxs } = prevProps
|
|
|
|
const prevUnconfTxList = txHelper(prevUnapprovedTxs, {}, {}, {}, network)
|
|
|
|
const prevTxData = prevUnconfTxList[prevIndex] || {}
|
|
|
|
prevTx = selectedAddressTxList.find(({ id }) => id === prevTxData.id) || {}
|
|
|
|
}
|
|
|
|
|
2018-03-20 18:58:48 +01:00
|
|
|
const unconfTxList = txHelper(unapprovedTxs, {}, {}, {}, network)
|
2017-11-29 05:24:35 +01:00
|
|
|
|
2018-06-25 21:06:57 +02:00
|
|
|
if (prevTx && prevTx.status === 'dropped') {
|
2018-05-29 19:23:06 +02:00
|
|
|
this.props.dispatch(actions.showModal({
|
|
|
|
name: 'TRANSACTION_CONFIRMED',
|
2018-09-17 19:34:29 +02:00
|
|
|
onSubmit: () => history.push(DEFAULT_ROUTE),
|
2018-05-29 19:23:06 +02:00
|
|
|
}))
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if (unconfTxList.length === 0 && !send.to && this.getUnapprovedMessagesTotal() === 0) {
|
2017-11-29 05:24:35 +01:00
|
|
|
this.props.history.push(DEFAULT_ROUTE)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-29 19:23:06 +02:00
|
|
|
ConfirmTxScreen.prototype.getTxData = function () {
|
2017-09-28 07:32:07 +02:00
|
|
|
const {
|
|
|
|
network,
|
2018-05-29 19:23:06 +02:00
|
|
|
index,
|
|
|
|
unapprovedTxs,
|
|
|
|
unapprovedMsgs,
|
|
|
|
unapprovedPersonalMsgs,
|
|
|
|
unapprovedTypedMessages,
|
|
|
|
match: { params: { id: transactionId } = {} },
|
|
|
|
} = this.props
|
|
|
|
|
|
|
|
const unconfTxList = txHelper(
|
2017-09-28 07:32:07 +02:00
|
|
|
unapprovedTxs,
|
|
|
|
unapprovedMsgs,
|
|
|
|
unapprovedPersonalMsgs,
|
2017-10-19 07:58:46 +02:00
|
|
|
unapprovedTypedMessages,
|
2018-05-29 19:23:06 +02:00
|
|
|
network
|
|
|
|
)
|
|
|
|
|
|
|
|
log.info(`rendering a combined ${unconfTxList.length} unconf msgs & txs`)
|
|
|
|
|
|
|
|
return transactionId
|
|
|
|
? R.find(({ id }) => id + '' === transactionId)(unconfTxList)
|
|
|
|
: unconfTxList[index]
|
|
|
|
}
|
|
|
|
|
|
|
|
ConfirmTxScreen.prototype.render = function () {
|
|
|
|
const props = this.props
|
|
|
|
const {
|
|
|
|
currentCurrency,
|
2017-09-28 07:32:07 +02:00
|
|
|
conversionRate,
|
|
|
|
blockGasLimit,
|
|
|
|
} = props
|
2017-01-17 08:59:25 +01:00
|
|
|
|
2018-05-29 19:23:06 +02:00
|
|
|
var txData = this.getTxData() || {}
|
2018-07-14 22:43:55 +02:00
|
|
|
const { msgParams } = txData
|
|
|
|
log.debug('msgParams detected, rendering pending msg')
|
|
|
|
|
|
|
|
return msgParams
|
|
|
|
? h(SignatureRequest, {
|
|
|
|
// Properties
|
|
|
|
txData: txData,
|
|
|
|
key: txData.id,
|
|
|
|
selectedAddress: props.selectedAddress,
|
|
|
|
accounts: props.accounts,
|
|
|
|
identities: props.identities,
|
|
|
|
conversionRate,
|
|
|
|
currentCurrency,
|
|
|
|
blockGasLimit,
|
|
|
|
// Actions
|
|
|
|
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),
|
|
|
|
})
|
|
|
|
: h(Loading)
|
2017-09-08 00:03:25 +02:00
|
|
|
}
|
|
|
|
|
2016-06-21 22:18:32 +02:00
|
|
|
ConfirmTxScreen.prototype.signMessage = function (msgData, event) {
|
2017-02-23 23:23:45 +01:00
|
|
|
log.info('conf-tx.js: signing message')
|
2016-05-03 23:32:22 +02:00
|
|
|
var params = msgData.msgParams
|
|
|
|
params.metamaskId = msgData.id
|
2017-03-22 23:14:33 +01:00
|
|
|
this.stopPropagation(event)
|
2018-03-30 23:51:11 +02:00
|
|
|
return this.props.dispatch(actions.signMsg(params))
|
2016-05-03 23:32:22 +02:00
|
|
|
}
|
|
|
|
|
2017-03-22 23:14:33 +01:00
|
|
|
ConfirmTxScreen.prototype.stopPropagation = function (event) {
|
|
|
|
if (event.stopPropagation) {
|
|
|
|
event.stopPropagation()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-23 23:23:45 +01:00
|
|
|
ConfirmTxScreen.prototype.signPersonalMessage = function (msgData, event) {
|
|
|
|
log.info('conf-tx.js: signing personal message')
|
|
|
|
var params = msgData.msgParams
|
|
|
|
params.metamaskId = msgData.id
|
2017-03-22 23:14:33 +01:00
|
|
|
this.stopPropagation(event)
|
2018-03-30 23:51:11 +02:00
|
|
|
return this.props.dispatch(actions.signPersonalMsg(params))
|
2017-02-23 23:23:45 +01:00
|
|
|
}
|
|
|
|
|
2017-09-29 18:24:08 +02:00
|
|
|
ConfirmTxScreen.prototype.signTypedMessage = function (msgData, event) {
|
|
|
|
log.info('conf-tx.js: signing typed message')
|
|
|
|
var params = msgData.msgParams
|
|
|
|
params.metamaskId = msgData.id
|
|
|
|
this.stopPropagation(event)
|
2018-03-30 23:51:11 +02:00
|
|
|
return this.props.dispatch(actions.signTypedMsg(params))
|
2017-09-29 18:24:08 +02:00
|
|
|
}
|
|
|
|
|
2016-06-21 22:18:32 +02:00
|
|
|
ConfirmTxScreen.prototype.cancelMessage = function (msgData, event) {
|
2017-02-23 23:23:45 +01:00
|
|
|
log.info('canceling message')
|
2017-03-22 23:14:33 +01:00
|
|
|
this.stopPropagation(event)
|
2018-03-30 23:51:11 +02:00
|
|
|
return this.props.dispatch(actions.cancelMsg(msgData))
|
2016-05-03 23:32:22 +02:00
|
|
|
}
|
|
|
|
|
2017-02-24 01:00:43 +01:00
|
|
|
ConfirmTxScreen.prototype.cancelPersonalMessage = function (msgData, event) {
|
|
|
|
log.info('canceling personal message')
|
2017-03-22 23:14:33 +01:00
|
|
|
this.stopPropagation(event)
|
2018-03-30 23:51:11 +02:00
|
|
|
return this.props.dispatch(actions.cancelPersonalMsg(msgData))
|
2017-02-24 01:00:43 +01:00
|
|
|
}
|
|
|
|
|
2017-09-29 18:24:08 +02:00
|
|
|
ConfirmTxScreen.prototype.cancelTypedMessage = function (msgData, event) {
|
|
|
|
log.info('canceling typed message')
|
|
|
|
this.stopPropagation(event)
|
2018-03-30 23:51:11 +02:00
|
|
|
return this.props.dispatch(actions.cancelTypedMsg(msgData))
|
2017-09-29 18:24:08 +02:00
|
|
|
}
|