1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-23 18:41:38 +01:00
metamask-extension/ui/app/conf-tx.js

168 lines
5.2 KiB
JavaScript
Raw Normal View History

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')
const txHelper = require('../lib/tx-helper')
2016-06-24 21:48:52 +02:00
const PendingTx = require('./components/pending-tx')
const PendingMsg = require('./components/pending-msg')
2017-02-23 01:23:13 +01:00
const PendingPersonalMsg = require('./components/pending-personal-msg')
const Loading = require('./components/loading')
const contentDivider = h('div', {
style: {
marginLeft: '16px',
marginRight: '16px',
height:'1px',
background:'#E7E7E7',
},
})
module.exports = connect(mapStateToProps)(ConfirmTxScreen)
2016-06-21 22:18:32 +02:00
function mapStateToProps (state) {
return {
identities: state.metamask.identities,
accounts: state.metamask.accounts,
selectedAddress: state.metamask.selectedAddress,
unapprovedTxs: state.metamask.unapprovedTxs,
unapprovedMsgs: state.metamask.unapprovedMsgs,
2017-02-23 01:23:13 +01:00
unapprovedPersonalMsgs: state.metamask.unapprovedPersonalMsgs,
index: state.appState.currentView.context,
warning: state.appState.warning,
2016-09-08 21:56:04 +02:00
network: state.metamask.network,
provider: state.metamask.provider,
conversionRate: state.metamask.conversionRate,
currentCurrency: state.metamask.currentCurrency,
blockGasLimit: state.metamask.currentBlockGasLimit,
}
}
inherits(ConfirmTxScreen, Component)
2016-06-21 22:18:32 +02:00
function ConfirmTxScreen () {
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-08-29 16:50:48 +02:00
const { network, unapprovedTxs, currentCurrency, unapprovedMsgs,
unapprovedPersonalMsgs, conversionRate, blockGasLimit } = props
2017-02-23 01:23:13 +01:00
var unconfTxList = txHelper(unapprovedTxs, unapprovedMsgs, unapprovedPersonalMsgs, network)
2017-03-24 20:50:39 +01:00
var txData = unconfTxList[props.index] || {}
var txParams = txData.params || {}
log.info(`rendering a combined ${unconfTxList.length} unconf msg & txs`)
if (unconfTxList.length === 0) return h(Loading, { isLoading: true })
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),
})
}
function currentTxView (opts) {
log.info('rendering current tx view')
const { txData } = opts
const { txParams, msgParams, type } = txData
if (txParams) {
log.debug('txParams detected, rendering pending tx')
2016-06-24 21:48:52 +02:00
return h(PendingTx, opts)
} else if (msgParams) {
log.debug('msgParams detected, rendering pending msg')
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)
}
}
}
2016-09-15 23:31:45 +02:00
ConfirmTxScreen.prototype.buyEth = function (address, event) {
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)
this.props.dispatch(actions.updateAndApproveTx(txData))
}
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)
event.preventDefault()
this.props.dispatch(actions.cancelTx(txData))
}
2016-06-21 22:18:32 +02:00
ConfirmTxScreen.prototype.signMessage = function (msgData, event) {
log.info('conf-tx.js: signing message')
var params = msgData.msgParams
params.metamaskId = msgData.id
2017-03-22 23:14:33 +01:00
this.stopPropagation(event)
this.props.dispatch(actions.signMsg(params))
}
2017-03-22 23:14:33 +01:00
ConfirmTxScreen.prototype.stopPropagation = function (event) {
if (event.stopPropagation) {
event.stopPropagation()
}
}
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)
this.props.dispatch(actions.signPersonalMsg(params))
}
2016-06-21 22:18:32 +02:00
ConfirmTxScreen.prototype.cancelMessage = function (msgData, event) {
log.info('canceling message')
2017-03-22 23:14:33 +01:00
this.stopPropagation(event)
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))
}
2016-06-21 22:18:32 +02:00
ConfirmTxScreen.prototype.goHome = function (event) {
2017-03-22 23:14:33 +01:00
this.stopPropagation(event)
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)
// }
// }