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.txManager.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.preferencesController.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 preferencesController = this.preferencesController
const txManager = this.txManager
const messageManager = this.messageManager
const personalMessageManager = this.personalMessageManager
const noticeController = this.noticeController
return {
@ -283,11 +282,11 @@ module.exports = class MetamaskController extends EventEmitter {
// messageManager
signMessage: nodeify(this.signMessage).bind(this),
cancelMessage: messageManager.rejectMsg.bind(messageManager),
cancelMessage: this.cancelMessage.bind(this),
// personalMessageManager
signPersonalMessage: nodeify(this.signPersonalMessage).bind(this),
cancelPersonalMessage: personalMessageManager.rejectMsg.bind(personalMessageManager),
cancelPersonalMessage: this.cancelPersonalMessage.bind(this),
// notices
checkNotices: noticeController.updateNoticesList.bind(noticeController),
@ -437,7 +436,7 @@ module.exports = class MetamaskController extends EventEmitter {
case 'signed':
return cb(null, data.rawSig)
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:
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) {
if (!msgParams.from) {
return cb(new Error('MetaMask Message Signature: from field is required.'))
}
let msgId = this.personalMessageManager.addUnapprovedMessage(msgParams)
this.sendUpdate()
this.opts.showUnconfirmedMessage()
@ -453,7 +456,7 @@ module.exports = class MetamaskController extends EventEmitter {
case 'signed':
return cb(null, data.rawSig)
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:
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:
approvePersonalMessage (msgParams, cb) {
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) {
const keyringController = this.keyringController
return keyringController.recoverPersonalMessage(msgParams)

View File

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

View File

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

View File

@ -111,6 +111,7 @@ ConfirmTxScreen.prototype.render = function () {
signMessage: this.signMessage.bind(this, txData),
signPersonalMessage: this.signPersonalMessage.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) {
log.info('conf-tx.js: signing message')
var params = msgData.msgParams
var type = msgData.type
params.metamaskId = msgData.id
event.stopPropagation()
this.props.dispatch(actions.signMsg(params))
@ -190,6 +190,12 @@ ConfirmTxScreen.prototype.cancelMessage = function (msgData, event) {
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) {
event.stopPropagation()
this.props.dispatch(actions.goHome())

View File

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