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.
217 lines
6.4 KiB
217 lines
6.4 KiB
9 years ago
|
const inherits = require('util').inherits
|
||
|
const Component = require('react').Component
|
||
|
const h = require('react-hyperscript')
|
||
7 years ago
|
const connect = require('react-redux').connect
|
||
7 years ago
|
const { withRouter } = require('react-router-dom')
|
||
7 years ago
|
const { compose } = require('recompose')
|
||
6 years ago
|
const actions = require('../../store/actions')
|
||
|
const txHelper = require('../../../lib/tx-helper')
|
||
7 years ago
|
const log = require('loglevel')
|
||
7 years ago
|
const R = require('ramda')
|
||
9 years ago
|
|
||
6 years ago
|
const SignatureRequest = require('../../components/app/signature-request')
|
||
|
const Loading = require('../../components/ui/loading-screen')
|
||
|
const { DEFAULT_ROUTE } = require('../../helpers/constants/routes')
|
||
9 years ago
|
|
||
7 years ago
|
module.exports = compose(
|
||
|
withRouter,
|
||
|
connect(mapStateToProps)
|
||
|
)(ConfirmTxScreen)
|
||
9 years ago
|
|
||
9 years ago
|
function mapStateToProps (state) {
|
||
7 years ago
|
const { metamask } = state
|
||
|
const {
|
||
|
unapprovedMsgCount,
|
||
|
unapprovedPersonalMsgCount,
|
||
7 years ago
|
unapprovedTypedMessagesCount,
|
||
7 years ago
|
} = metamask
|
||
|
|
||
9 years ago
|
return {
|
||
|
identities: state.metamask.identities,
|
||
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,
|
||
9 years ago
|
index: state.appState.currentView.context,
|
||
9 years ago
|
warning: state.appState.warning,
|
||
8 years ago
|
network: state.metamask.network,
|
||
8 years ago
|
provider: state.metamask.provider,
|
||
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,
|
||
7 years ago
|
selectedAddressTxList: state.metamask.selectedAddressTxList,
|
||
9 years ago
|
}
|
||
|
}
|
||
|
|
||
|
inherits(ConfirmTxScreen, Component)
|
||
9 years ago
|
function ConfirmTxScreen () {
|
||
9 years ago
|
Component.call(this)
|
||
|
}
|
||
|
|
||
7 years ago
|
ConfirmTxScreen.prototype.getUnapprovedMessagesTotal = function () {
|
||
|
const {
|
||
|
unapprovedMsgCount = 0,
|
||
|
unapprovedPersonalMsgCount = 0,
|
||
|
unapprovedTypedMessagesCount = 0,
|
||
|
} = this.props
|
||
|
|
||
|
return unapprovedTypedMessagesCount + unapprovedMsgCount + unapprovedPersonalMsgCount
|
||
|
}
|
||
|
|
||
7 years ago
|
ConfirmTxScreen.prototype.componentDidMount = function () {
|
||
|
const {
|
||
|
unapprovedTxs = {},
|
||
|
network,
|
||
|
send,
|
||
|
} = this.props
|
||
|
const unconfTxList = txHelper(unapprovedTxs, {}, {}, {}, network)
|
||
|
|
||
7 years ago
|
if (unconfTxList.length === 0 && !send.to && this.getUnapprovedMessagesTotal() === 0) {
|
||
7 years ago
|
this.props.history.push(DEFAULT_ROUTE)
|
||
|
}
|
||
|
}
|
||
|
|
||
7 years ago
|
ConfirmTxScreen.prototype.componentDidUpdate = function (prevProps) {
|
||
|
const {
|
||
7 years ago
|
unapprovedTxs = {},
|
||
7 years ago
|
network,
|
||
|
selectedAddressTxList,
|
||
7 years ago
|
send,
|
||
7 years ago
|
history,
|
||
|
match: { params: { id: transactionId } = {} },
|
||
7 years ago
|
} = this.props
|
||
7 years ago
|
|
||
|
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) || {}
|
||
|
}
|
||
|
|
||
7 years ago
|
const unconfTxList = txHelper(unapprovedTxs, {}, {}, {}, network)
|
||
7 years ago
|
|
||
7 years ago
|
if (prevTx && prevTx.status === 'dropped') {
|
||
7 years ago
|
this.props.dispatch(actions.showModal({
|
||
|
name: 'TRANSACTION_CONFIRMED',
|
||
6 years ago
|
onSubmit: () => history.push(DEFAULT_ROUTE),
|
||
7 years ago
|
}))
|
||
|
|
||
|
return
|
||
|
}
|
||
|
|
||
|
if (unconfTxList.length === 0 && !send.to && this.getUnapprovedMessagesTotal() === 0) {
|
||
7 years ago
|
this.props.history.push(DEFAULT_ROUTE)
|
||
|
}
|
||
|
}
|
||
|
|
||
7 years ago
|
ConfirmTxScreen.prototype.getTxData = function () {
|
||
7 years ago
|
const {
|
||
|
network,
|
||
7 years ago
|
index,
|
||
|
unapprovedTxs,
|
||
|
unapprovedMsgs,
|
||
|
unapprovedPersonalMsgs,
|
||
|
unapprovedTypedMessages,
|
||
|
match: { params: { id: transactionId } = {} },
|
||
|
} = this.props
|
||
|
|
||
|
const unconfTxList = txHelper(
|
||
7 years ago
|
unapprovedTxs,
|
||
|
unapprovedMsgs,
|
||
|
unapprovedPersonalMsgs,
|
||
7 years ago
|
unapprovedTypedMessages,
|
||
7 years ago
|
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,
|
||
7 years ago
|
blockGasLimit,
|
||
|
} = props
|
||
8 years ago
|
|
||
7 years ago
|
var txData = this.getTxData() || {}
|
||
6 years ago
|
const { msgParams } = txData
|
||
|
log.debug('msgParams detected, rendering pending msg')
|
||
|
|
||
|
return msgParams
|
||
|
? h(SignatureRequest, {
|
||
|
// Properties
|
||
|
txData: txData,
|
||
|
key: txData.id,
|
||
|
identities: props.identities,
|
||
|
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)
|
||
7 years ago
|
}
|
||
|
|
||
9 years ago
|
ConfirmTxScreen.prototype.signMessage = function (msgData, event) {
|
||
8 years ago
|
log.info('conf-tx.js: signing message')
|
||
9 years ago
|
var params = msgData.msgParams
|
||
|
params.metamaskId = msgData.id
|
||
8 years ago
|
this.stopPropagation(event)
|
||
7 years ago
|
return this.props.dispatch(actions.signMsg(params))
|
||
9 years ago
|
}
|
||
|
|
||
8 years ago
|
ConfirmTxScreen.prototype.stopPropagation = function (event) {
|
||
|
if (event.stopPropagation) {
|
||
|
event.stopPropagation()
|
||
|
}
|
||
|
}
|
||
|
|
||
8 years ago
|
ConfirmTxScreen.prototype.signPersonalMessage = function (msgData, event) {
|
||
|
log.info('conf-tx.js: signing personal message')
|
||
|
var params = msgData.msgParams
|
||
|
params.metamaskId = msgData.id
|
||
8 years ago
|
this.stopPropagation(event)
|
||
7 years ago
|
return this.props.dispatch(actions.signPersonalMsg(params))
|
||
8 years ago
|
}
|
||
|
|
||
7 years ago
|
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)
|
||
7 years ago
|
return this.props.dispatch(actions.signTypedMsg(params))
|
||
7 years ago
|
}
|
||
|
|
||
9 years ago
|
ConfirmTxScreen.prototype.cancelMessage = function (msgData, event) {
|
||
8 years ago
|
log.info('canceling message')
|
||
8 years ago
|
this.stopPropagation(event)
|
||
7 years ago
|
return this.props.dispatch(actions.cancelMsg(msgData))
|
||
9 years ago
|
}
|
||
|
|
||
8 years ago
|
ConfirmTxScreen.prototype.cancelPersonalMessage = function (msgData, event) {
|
||
|
log.info('canceling personal message')
|
||
8 years ago
|
this.stopPropagation(event)
|
||
7 years ago
|
return this.props.dispatch(actions.cancelPersonalMsg(msgData))
|
||
8 years ago
|
}
|
||
|
|
||
7 years ago
|
ConfirmTxScreen.prototype.cancelTypedMessage = function (msgData, event) {
|
||
|
log.info('canceling typed message')
|
||
|
this.stopPropagation(event)
|
||
7 years ago
|
return this.props.dispatch(actions.cancelTypedMsg(msgData))
|
||
7 years ago
|
}
|