2016-04-14 00:28:44 +02:00
|
|
|
const inherits = require('util').inherits
|
|
|
|
const Component = require('react').Component
|
|
|
|
const h = require('react-hyperscript')
|
|
|
|
const connect = require('react-redux').connect
|
|
|
|
const actions = require('./actions')
|
2016-05-03 23:32:22 +02:00
|
|
|
const txHelper = require('../lib/tx-helper')
|
|
|
|
|
2016-06-24 21:48:52 +02:00
|
|
|
const PendingTx = require('./components/pending-tx')
|
2016-05-03 23:32:22 +02:00
|
|
|
const PendingMsg = require('./components/pending-msg')
|
2017-02-23 01:23:13 +01:00
|
|
|
const PendingPersonalMsg = require('./components/pending-personal-msg')
|
2017-09-29 18:24:08 +02:00
|
|
|
const PendingTypedMsg = require('./components/pending-typed-msg')
|
2017-02-28 21:00:07 +01:00
|
|
|
const Loading = require('./components/loading')
|
2016-04-14 00:28:44 +02:00
|
|
|
|
2017-09-28 07:32:07 +02:00
|
|
|
// const contentDivider = h('div', {
|
|
|
|
// style: {
|
|
|
|
// marginLeft: '16px',
|
|
|
|
// marginRight: '16px',
|
|
|
|
// height:'1px',
|
|
|
|
// background:'#E7E7E7',
|
|
|
|
// },
|
|
|
|
// })
|
2017-08-31 09:28:45 +02:00
|
|
|
|
2016-04-14 00:28:44 +02:00
|
|
|
module.exports = connect(mapStateToProps)(ConfirmTxScreen)
|
|
|
|
|
2016-06-21 22:18:32 +02:00
|
|
|
function mapStateToProps (state) {
|
2016-04-14 00:28:44 +02:00
|
|
|
return {
|
|
|
|
identities: state.metamask.identities,
|
|
|
|
accounts: state.metamask.accounts,
|
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,
|
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)
|
|
|
|
}
|
|
|
|
|
2016-06-21 22:18:32 +02:00
|
|
|
ConfirmTxScreen.prototype.render = function () {
|
2017-02-23 01:23:13 +01:00
|
|
|
const props = this.props
|
2017-09-28 07:32:07 +02:00
|
|
|
const {
|
|
|
|
network,
|
|
|
|
unapprovedTxs,
|
|
|
|
currentCurrency,
|
|
|
|
unapprovedMsgs,
|
|
|
|
unapprovedPersonalMsgs,
|
2017-10-19 07:58:46 +02:00
|
|
|
unapprovedTypedMessages,
|
2017-09-28 07:32:07 +02:00
|
|
|
conversionRate,
|
|
|
|
blockGasLimit,
|
|
|
|
// provider,
|
|
|
|
// computedBalances,
|
|
|
|
} = props
|
2017-01-17 08:59:25 +01:00
|
|
|
|
2017-09-29 18:24:08 +02:00
|
|
|
var unconfTxList = txHelper(unapprovedTxs, unapprovedMsgs, unapprovedPersonalMsgs, unapprovedTypedMessages, network)
|
2017-03-24 20:50:39 +01:00
|
|
|
|
|
|
|
var txData = unconfTxList[props.index] || {}
|
2017-01-17 08:59:25 +01:00
|
|
|
var txParams = txData.params || {}
|
2017-06-05 20:40:20 +02:00
|
|
|
|
2017-09-28 07:32:07 +02:00
|
|
|
// var isNotification = isPopupOrNotification() === 'notification'
|
|
|
|
/*
|
|
|
|
Client is using the flag above to render the following in conf screen
|
|
|
|
// subtitle and nav
|
|
|
|
h('.section-title.flex-row.flex-center', [
|
|
|
|
!isNotification ? h('i.fa.fa-arrow-left.fa-lg.cursor-pointer', {
|
|
|
|
onClick: this.goHome.bind(this),
|
|
|
|
}) : null,
|
|
|
|
h('h2.page-subtitle', 'Confirm Transaction'),
|
|
|
|
isNotification ? h(NetworkIndicator, {
|
|
|
|
network: network,
|
|
|
|
provider: provider,
|
|
|
|
}) : null,
|
|
|
|
]),
|
|
|
|
*/
|
2017-02-21 08:33:21 +01:00
|
|
|
|
|
|
|
log.info(`rendering a combined ${unconfTxList.length} unconf msg & txs`)
|
2017-10-20 06:06:14 +02:00
|
|
|
if (unconfTxList.length === 0) return h(Loading)
|
2017-01-15 07:59:05 +01:00
|
|
|
|
2017-07-30 07:17:56 +02:00
|
|
|
return currentTxView({
|
|
|
|
// Properties
|
|
|
|
txData: txData,
|
|
|
|
key: txData.id,
|
|
|
|
selectedAddress: props.selectedAddress,
|
|
|
|
accounts: props.accounts,
|
|
|
|
identities: props.identities,
|
|
|
|
conversionRate,
|
|
|
|
currentCurrency,
|
|
|
|
blockGasLimit,
|
|
|
|
// Actions
|
|
|
|
buyEth: this.buyEth.bind(this, txParams.from || props.selectedAddress),
|
|
|
|
sendTransaction: this.sendTransaction.bind(this),
|
|
|
|
cancelTransaction: this.cancelTransaction.bind(this, txData),
|
|
|
|
signMessage: this.signMessage.bind(this, txData),
|
|
|
|
signPersonalMessage: this.signPersonalMessage.bind(this, txData),
|
|
|
|
cancelMessage: this.cancelMessage.bind(this, txData),
|
|
|
|
cancelPersonalMessage: this.cancelPersonalMessage.bind(this, txData),
|
|
|
|
})
|
2017-09-18 20:28:10 +02:00
|
|
|
|
2016-04-14 00:28:44 +02:00
|
|
|
}
|
|
|
|
|
2016-05-03 23:32:22 +02:00
|
|
|
function currentTxView (opts) {
|
2017-02-23 20:18:49 +01:00
|
|
|
log.info('rendering current tx view')
|
2017-01-17 08:59:25 +01:00
|
|
|
const { txData } = opts
|
2017-02-23 20:18:49 +01:00
|
|
|
const { txParams, msgParams, type } = txData
|
2017-01-17 08:59:25 +01:00
|
|
|
|
|
|
|
if (txParams) {
|
2017-02-21 08:33:21 +01:00
|
|
|
log.debug('txParams detected, rendering pending tx')
|
2016-06-24 21:48:52 +02:00
|
|
|
return h(PendingTx, opts)
|
2017-01-17 08:59:25 +01:00
|
|
|
} else if (msgParams) {
|
2017-02-21 08:33:21 +01:00
|
|
|
log.debug('msgParams detected, rendering pending msg')
|
2017-02-23 20:18:49 +01:00
|
|
|
|
|
|
|
if (type === 'eth_sign') {
|
|
|
|
log.debug('rendering eth_sign message')
|
|
|
|
return h(PendingMsg, opts)
|
|
|
|
} else if (type === 'personal_sign') {
|
|
|
|
log.debug('rendering personal_sign message')
|
|
|
|
return h(PendingPersonalMsg, opts)
|
2017-09-29 18:24:08 +02:00
|
|
|
} else if (type === 'eth_signTypedData') {
|
|
|
|
log.debug('rendering eth_signTypedData message')
|
|
|
|
return h(PendingTypedMsg, opts)
|
2017-02-23 20:18:49 +01:00
|
|
|
}
|
2016-05-03 23:32:22 +02:00
|
|
|
}
|
2017-10-20 06:06:14 +02:00
|
|
|
return h(Loading)
|
2016-05-03 23:32:22 +02:00
|
|
|
}
|
2017-02-17 21:08:54 +01:00
|
|
|
|
2016-09-15 23:31:45 +02:00
|
|
|
ConfirmTxScreen.prototype.buyEth = function (address, event) {
|
2017-04-24 12:35:45 +02:00
|
|
|
event.preventDefault()
|
2016-09-15 23:31:45 +02:00
|
|
|
this.props.dispatch(actions.buyEthView(address))
|
|
|
|
}
|
|
|
|
|
|
|
|
ConfirmTxScreen.prototype.sendTransaction = function (txData, event) {
|
2017-03-22 23:14:33 +01:00
|
|
|
this.stopPropagation(event)
|
2017-03-28 20:46:33 +02:00
|
|
|
this.props.dispatch(actions.updateAndApproveTx(txData))
|
2016-04-14 00:28:44 +02:00
|
|
|
}
|
|
|
|
|
2016-06-21 22:18:32 +02:00
|
|
|
ConfirmTxScreen.prototype.cancelTransaction = function (txData, event) {
|
2017-03-22 23:14:33 +01:00
|
|
|
this.stopPropagation(event)
|
2017-03-23 23:01:05 +01:00
|
|
|
event.preventDefault()
|
2016-04-14 00:28:44 +02:00
|
|
|
this.props.dispatch(actions.cancelTx(txData))
|
|
|
|
}
|
|
|
|
|
2017-09-08 00:03:25 +02:00
|
|
|
ConfirmTxScreen.prototype.cancelAllTransactions = function (unconfTxList, event) {
|
|
|
|
this.stopPropagation(event)
|
|
|
|
event.preventDefault()
|
|
|
|
this.props.dispatch(actions.cancelAllTx(unconfTxList))
|
|
|
|
}
|
|
|
|
|
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)
|
2016-05-03 23:32:22 +02:00
|
|
|
this.props.dispatch(actions.signMsg(params))
|
|
|
|
}
|
|
|
|
|
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)
|
2017-02-23 23:23:45 +01:00
|
|
|
this.props.dispatch(actions.signPersonalMsg(params))
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
this.props.dispatch(actions.signTypedMsg(params))
|
|
|
|
}
|
|
|
|
|
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)
|
2016-05-03 23:32:22 +02:00
|
|
|
this.props.dispatch(actions.cancelMsg(msgData))
|
|
|
|
}
|
|
|
|
|
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)
|
2017-02-24 01:00:43 +01:00
|
|
|
this.props.dispatch(actions.cancelPersonalMsg(msgData))
|
|
|
|
}
|
|
|
|
|
2017-09-29 18:24:08 +02:00
|
|
|
ConfirmTxScreen.prototype.cancelTypedMessage = function (msgData, event) {
|
|
|
|
log.info('canceling typed message')
|
|
|
|
this.stopPropagation(event)
|
|
|
|
this.props.dispatch(actions.cancelTypedMsg(msgData))
|
|
|
|
}
|
|
|
|
|
2016-06-21 22:18:32 +02:00
|
|
|
ConfirmTxScreen.prototype.goHome = function (event) {
|
2017-03-22 23:14:33 +01:00
|
|
|
this.stopPropagation(event)
|
2016-05-03 23:32:22 +02:00
|
|
|
this.props.dispatch(actions.goHome())
|
|
|
|
}
|
|
|
|
|
2017-08-29 16:50:48 +02:00
|
|
|
// function warningIfExists (warning) {
|
|
|
|
// if (warning &&
|
|
|
|
// // Do not display user rejections on this screen:
|
|
|
|
// warning.indexOf('User denied transaction signature') === -1) {
|
|
|
|
// return h('.error', {
|
|
|
|
// style: {
|
|
|
|
// margin: 'auto',
|
|
|
|
// },
|
|
|
|
// }, warning)
|
|
|
|
// }
|
|
|
|
// }
|