1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-23 02:10:12 +01:00

Fix cancel msg signing behavior.

This commit is contained in:
Dan Finlay 2017-02-23 16:00:43 -08:00
parent 1d1d296a1e
commit 961a83769b
5 changed files with 45 additions and 19 deletions

View File

@ -139,6 +139,7 @@ module.exports = class MetamaskController extends EventEmitter {
this.ethStore.subscribe(this.sendUpdate.bind(this)) this.ethStore.subscribe(this.sendUpdate.bind(this))
this.txManager.memStore.subscribe(this.sendUpdate.bind(this)) this.txManager.memStore.subscribe(this.sendUpdate.bind(this))
this.messageManager.memStore.subscribe(this.sendUpdate.bind(this)) this.messageManager.memStore.subscribe(this.sendUpdate.bind(this))
this.personalMessageManager.memStore.subscribe(this.sendUpdate.bind(this))
this.keyringController.memStore.subscribe(this.sendUpdate.bind(this)) this.keyringController.memStore.subscribe(this.sendUpdate.bind(this))
this.preferencesController.store.subscribe(this.sendUpdate.bind(this)) this.preferencesController.store.subscribe(this.sendUpdate.bind(this))
this.currencyController.store.subscribe(this.sendUpdate.bind(this)) this.currencyController.store.subscribe(this.sendUpdate.bind(this))
@ -239,8 +240,6 @@ module.exports = class MetamaskController extends EventEmitter {
const keyringController = this.keyringController const keyringController = this.keyringController
const preferencesController = this.preferencesController const preferencesController = this.preferencesController
const txManager = this.txManager const txManager = this.txManager
const messageManager = this.messageManager
const personalMessageManager = this.personalMessageManager
const noticeController = this.noticeController const noticeController = this.noticeController
return { return {
@ -283,11 +282,11 @@ module.exports = class MetamaskController extends EventEmitter {
// messageManager // messageManager
signMessage: nodeify(this.signMessage).bind(this), signMessage: nodeify(this.signMessage).bind(this),
cancelMessage: messageManager.rejectMsg.bind(messageManager), cancelMessage: this.cancelMessage.bind(this),
// personalMessageManager // personalMessageManager
signPersonalMessage: nodeify(this.signPersonalMessage).bind(this), signPersonalMessage: nodeify(this.signPersonalMessage).bind(this),
cancelPersonalMessage: personalMessageManager.rejectMsg.bind(personalMessageManager), cancelPersonalMessage: this.cancelPersonalMessage.bind(this),
// notices // notices
checkNotices: noticeController.updateNoticesList.bind(noticeController), checkNotices: noticeController.updateNoticesList.bind(noticeController),
@ -437,7 +436,7 @@ module.exports = class MetamaskController extends EventEmitter {
case 'signed': case 'signed':
return cb(null, data.rawSig) return cb(null, data.rawSig)
case 'rejected': case 'rejected':
return cb(new Error('MetaMask Message Signature: User denied transaction signature.')) return cb(new Error('MetaMask Message Signature: User denied message signature.'))
default: default:
return cb(new Error(`MetaMask Message Signature: Unknown problem: ${JSON.stringify(msgParams)}`)) return cb(new Error(`MetaMask Message Signature: Unknown problem: ${JSON.stringify(msgParams)}`))
} }
@ -445,6 +444,10 @@ module.exports = class MetamaskController extends EventEmitter {
} }
newUnsignedPersonalMessage (msgParams, cb) { newUnsignedPersonalMessage (msgParams, cb) {
if (!msgParams.from) {
return cb(new Error('MetaMask Message Signature: from field is required.'))
}
let msgId = this.personalMessageManager.addUnapprovedMessage(msgParams) let msgId = this.personalMessageManager.addUnapprovedMessage(msgParams)
this.sendUpdate() this.sendUpdate()
this.opts.showUnconfirmedMessage() this.opts.showUnconfirmedMessage()
@ -453,7 +456,7 @@ module.exports = class MetamaskController extends EventEmitter {
case 'signed': case 'signed':
return cb(null, data.rawSig) return cb(null, data.rawSig)
case 'rejected': case 'rejected':
return cb(new Error('MetaMask Message Signature: User denied transaction signature.')) return cb(new Error('MetaMask Message Signature: User denied message signature.'))
default: default:
return cb(new Error(`MetaMask Message Signature: Unknown problem: ${JSON.stringify(msgParams)}`)) return cb(new Error(`MetaMask Message Signature: Unknown problem: ${JSON.stringify(msgParams)}`))
} }
@ -479,6 +482,14 @@ module.exports = class MetamaskController extends EventEmitter {
}) })
} }
cancelMessage(msgId, cb) {
const messageManager = this.messageManager
messageManager.rejectMsg(msgId)
if (cb && typeof cb === 'function') {
cb(null, this.getState())
}
}
// Prefixed Style Message Signing Methods: // Prefixed Style Message Signing Methods:
approvePersonalMessage (msgParams, cb) { approvePersonalMessage (msgParams, cb) {
let msgId = this.personalMessageManager.addUnapprovedMessage(msgParams) let msgId = this.personalMessageManager.addUnapprovedMessage(msgParams)
@ -514,6 +525,14 @@ module.exports = class MetamaskController extends EventEmitter {
}) })
} }
cancelPersonalMessage(msgId, cb) {
const messageManager = this.personalMessageManager
messageManager.rejectMsg(msgId)
if (cb && typeof cb === 'function') {
cb(null, this.getState())
}
}
recoverPersonalMessage (msgParams) { recoverPersonalMessage (msgParams) {
const keyringController = this.keyringController const keyringController = this.keyringController
return keyringController.recoverPersonalMessage(msgParams) return keyringController.recoverPersonalMessage(msgParams)

View File

@ -418,7 +418,7 @@ function sendTx (txData) {
function completedTx (id) { function completedTx (id) {
return { return {
type: actions.COMPLETED_TX, type: actions.COMPLETED_TX,
id, value: id,
} }
} }
@ -436,9 +436,9 @@ function cancelMsg (msgData) {
} }
function cancelPersonalMsg (msgData) { function cancelPersonalMsg (msgData) {
log.debug(`background.cancelMessage`) const id = msgData.id
background.cancelPersonalMessage(msgData.id) background.cancelPersonalMessage(id)
return actions.completedTx(msgData.id) return actions.completedTx(id)
} }
function cancelTx (txData) { function cancelTx (txData) {

View File

@ -34,7 +34,7 @@ PendingMsg.prototype.render = function () {
// sign + cancel // sign + cancel
h('.flex-row.flex-space-around', [ h('.flex-row.flex-space-around', [
h('button', { h('button', {
onClick: state.cancelMessage, onClick: state.cancelPersonalMessage,
}, 'Cancel'), }, 'Cancel'),
h('button', { h('button', {
onClick: state.signPersonalMessage, onClick: state.signPersonalMessage,

View File

@ -111,6 +111,7 @@ ConfirmTxScreen.prototype.render = function () {
signMessage: this.signMessage.bind(this, txData), signMessage: this.signMessage.bind(this, txData),
signPersonalMessage: this.signPersonalMessage.bind(this, txData), signPersonalMessage: this.signPersonalMessage.bind(this, txData),
cancelMessage: this.cancelMessage.bind(this, txData), cancelMessage: this.cancelMessage.bind(this, txData),
cancelPersonalMessage: this.cancelPersonalMessage.bind(this, txData),
}), }),
]), ]),
@ -170,7 +171,6 @@ ConfirmTxScreen.prototype.cancelTransaction = function (txData, event) {
ConfirmTxScreen.prototype.signMessage = function (msgData, event) { ConfirmTxScreen.prototype.signMessage = function (msgData, event) {
log.info('conf-tx.js: signing message') log.info('conf-tx.js: signing message')
var params = msgData.msgParams var params = msgData.msgParams
var type = msgData.type
params.metamaskId = msgData.id params.metamaskId = msgData.id
event.stopPropagation() event.stopPropagation()
this.props.dispatch(actions.signMsg(params)) this.props.dispatch(actions.signMsg(params))
@ -190,6 +190,12 @@ ConfirmTxScreen.prototype.cancelMessage = function (msgData, event) {
this.props.dispatch(actions.cancelMsg(msgData)) this.props.dispatch(actions.cancelMsg(msgData))
} }
ConfirmTxScreen.prototype.cancelPersonalMessage = function (msgData, event) {
log.info('canceling personal message')
event.stopPropagation()
this.props.dispatch(actions.cancelPersonalMsg(msgData))
}
ConfirmTxScreen.prototype.goHome = function (event) { ConfirmTxScreen.prototype.goHome = function (event) {
event.stopPropagation() event.stopPropagation()
this.props.dispatch(actions.goHome()) this.props.dispatch(actions.goHome())

View File

@ -9,12 +9,13 @@ function reduceApp (state, action) {
log.debug('App Reducer got ' + action.type) log.debug('App Reducer got ' + action.type)
// clone and defaults // clone and defaults
const selectedAddress = state.metamask.selectedAddress const selectedAddress = state.metamask.selectedAddress
const pendingTxs = hasPendingTxs(state) let pendingTxs = hasPendingTxs(state)
let name = 'accounts' let name = 'accounts'
if (selectedAddress) { if (selectedAddress) {
name = 'accountDetail' name = 'accountDetail'
} }
if (pendingTxs) { if (pendingTxs) {
log.debug('pending txs detected, defaulting to conf-tx view.')
name = 'confTx' name = 'confTx'
} }
@ -310,15 +311,16 @@ function reduceApp (state, action) {
}) })
case actions.COMPLETED_TX: case actions.COMPLETED_TX:
log.debug('reducing COMPLETED_TX') log.debug('reducing COMPLETED_TX for tx ' + action.value)
var { unapprovedTxs, unapprovedMsgs, var { unapprovedTxs, unapprovedMsgs,
unapprovedPersonalMsgs, network } = state.metamask unapprovedPersonalMsgs, network } = state.metamask
var unconfTxList = txHelper(unapprovedTxs, unapprovedMsgs, unapprovedPersonalMsgs, network) var unconfTxList = txHelper(unapprovedTxs, unapprovedMsgs, unapprovedPersonalMsgs, network)
.filter(tx => tx !== tx.id) .filter(tx => tx.id !== action.value )
log.debug(`actions - COMPLETED_TX with ${unconfTxList.length} txs`)
if (unconfTxList && unconfTxList.length > 0) { pendingTxs = unconfTxList.length > 0
if (pendingTxs) {
log.debug('reducer detected txs - rendering confTx view') log.debug('reducer detected txs - rendering confTx view')
return extend(appState, { return extend(appState, {
transForward: false, transForward: false,
@ -583,8 +585,7 @@ function hasPendingTxs (state) {
var unconfTxList = txHelper(unapprovedTxs, unapprovedMsgs, unapprovedPersonalMsgs, network) var unconfTxList = txHelper(unapprovedTxs, unapprovedMsgs, unapprovedPersonalMsgs, network)
var has = unconfTxList.length > 0 var has = unconfTxList.length > 0
log.debug('checking if state has pending txs, concluded ' + has) return has
return unconfTxList.length > 0
} }
function indexForPending (state, txId) { function indexForPending (state, txId) {