1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00

Got personal_sign working

Also fixed bug where signing would not close popup.
This commit is contained in:
Dan Finlay 2017-02-23 14:23:45 -08:00
parent 7ec25526b7
commit 4697aca02c
11 changed files with 175 additions and 69 deletions

View File

@ -15,6 +15,10 @@ const firstTimeState = require('./first-time-state')
const STORAGE_KEY = 'metamask-config' const STORAGE_KEY = 'metamask-config'
const METAMASK_DEBUG = 'GULP_METAMASK_DEBUG' const METAMASK_DEBUG = 'GULP_METAMASK_DEBUG'
const log = require('loglevel')
window.log = log
log.setDefaultLevel(METAMASK_DEBUG ? 'debug' : 'warn')
let popupIsOpen = false let popupIsOpen = false
// state persistence // state persistence

View File

@ -4,7 +4,7 @@ const ethUtil = require('ethereumjs-util')
const createId = require('./random-id') const createId = require('./random-id')
module.exports = class MessageManager extends EventEmitter{ module.exports = class PersonalMessageManager extends EventEmitter{
constructor (opts) { constructor (opts) {
super() super()
this.memStore = new ObservableStore({ this.memStore = new ObservableStore({
@ -82,7 +82,7 @@ module.exports = class MessageManager extends EventEmitter{
_setMsgStatus (msgId, status) { _setMsgStatus (msgId, status) {
const msg = this.getMsg(msgId) const msg = this.getMsg(msgId)
if (!msg) throw new Error('MessageManager - Message not found for id: "${msgId}".') if (!msg) throw new Error('PersonalMessageManager - Message not found for id: "${msgId}".')
msg.status = status msg.status = status
this._updateMsg(msg) this._updateMsg(msg)
this.emit(`${msgId}:${status}`, msg) this.emit(`${msgId}:${status}`, msg)

View File

@ -170,8 +170,7 @@ module.exports = class MetamaskController extends EventEmitter {
processMessage: this.newUnsignedMessage.bind(this), processMessage: this.newUnsignedMessage.bind(this),
// new style msg signing // new style msg signing
approvePersonalMessage: this.approvePersonalMessage.bind(this), processPersonalMessage: this.newUnsignedPersonalMessage.bind(this),
signPersonalMessage: nodeify(this.signPersonalMessage).bind(this),
personalRecoverSigner: nodeify(this.recoverPersonalMessage).bind(this), personalRecoverSigner: nodeify(this.recoverPersonalMessage).bind(this),
}) })
return provider return provider
@ -283,11 +282,11 @@ module.exports = class MetamaskController extends EventEmitter {
cancelTransaction: txManager.cancelTransaction.bind(txManager), cancelTransaction: txManager.cancelTransaction.bind(txManager),
// messageManager // messageManager
signMessage: this.signMessage.bind(this), signMessage: nodeify(this.signMessage).bind(this),
cancelMessage: messageManager.rejectMsg.bind(messageManager), cancelMessage: messageManager.rejectMsg.bind(messageManager),
// personalMessageManager // personalMessageManager
signPersonalMessage: this.signPersonalMessage.bind(this), signPersonalMessage: nodeify(this.signPersonalMessage).bind(this),
cancelPersonalMessage: personalMessageManager.rejectMsg.bind(personalMessageManager), cancelPersonalMessage: personalMessageManager.rejectMsg.bind(personalMessageManager),
// notices // notices
@ -445,22 +444,39 @@ module.exports = class MetamaskController extends EventEmitter {
}) })
} }
newUnsignedPersonalMessage (msgParams, cb) {
let msgId = this.personalMessageManager.addUnapprovedMessage(msgParams)
this.sendUpdate()
this.opts.showUnconfirmedMessage()
this.personalMessageManager.once(`${msgId}:finished`, (data) => {
switch (data.status) {
case 'signed':
return cb(null, data.rawSig)
case 'rejected':
return cb(new Error('MetaMask Message Signature: User denied transaction signature.'))
default:
return cb(new Error(`MetaMask Message Signature: Unknown problem: ${JSON.stringify(msgParams)}`))
}
})
}
signMessage (msgParams, cb) { signMessage (msgParams, cb) {
log.info('MetaMaskController - signMessage')
const msgId = msgParams.metamaskId const msgId = msgParams.metamaskId
promiseToCallback(
// sets the status op the message to 'approved' // sets the status op the message to 'approved'
// and removes the metamaskId for signing // and removes the metamaskId for signing
this.messageManager.approveMessage(msgParams) return this.messageManager.approveMessage(msgParams)
.then((cleanMsgParams) => { .then((cleanMsgParams) => {
// signs the message // signs the message
return this.keyringController.signMessage(cleanMsgParams) return this.keyringController.signMessage(cleanMsgParams)
}) })
.then((rawSig) => { .then((rawSig) => {
// tells the listener that the message has been signed // tells the listener that the message has been signed
// and can be returned to the dapp // and can be returned to the dapp
this.messageManager.setMsgStatusSigned(msgId, rawSig) this.messageManager.setMsgStatusSigned(msgId, rawSig)
}) return this.getState()
)(cb) })
} }
// Prefixed Style Message Signing Methods: // Prefixed Style Message Signing Methods:
@ -481,6 +497,7 @@ module.exports = class MetamaskController extends EventEmitter {
} }
signPersonalMessage (msgParams) { signPersonalMessage (msgParams) {
log.info('MetaMaskController - signPersonalMessage')
const msgId = msgParams.metamaskId const msgId = msgParams.metamaskId
// sets the status op the message to 'approved' // sets the status op the message to 'approved'
// and removes the metamaskId for signing // and removes the metamaskId for signing
@ -493,7 +510,7 @@ module.exports = class MetamaskController extends EventEmitter {
// tells the listener that the message has been signed // tells the listener that the message has been signed
// and can be returned to the dapp // and can be returned to the dapp
this.personalMessageManager.setMsgStatusSigned(msgId, rawSig) this.personalMessageManager.setMsgStatusSigned(msgId, rawSig)
return rawSig return this.getState()
}) })
} }

View File

@ -180,7 +180,7 @@ function tryUnlockMetamask (password) {
return (dispatch) => { return (dispatch) => {
dispatch(actions.showLoadingIndication()) dispatch(actions.showLoadingIndication())
dispatch(actions.unlockInProgress()) dispatch(actions.unlockInProgress())
if (global.METAMASK_DEBUG) console.log(`background.submitPassword`) log.debug(`background.submitPassword`)
background.submitPassword(password, (err) => { background.submitPassword(password, (err) => {
dispatch(actions.hideLoadingIndication()) dispatch(actions.hideLoadingIndication())
if (err) { if (err) {
@ -208,7 +208,7 @@ function transitionBackward () {
function confirmSeedWords () { function confirmSeedWords () {
return (dispatch) => { return (dispatch) => {
dispatch(actions.showLoadingIndication()) dispatch(actions.showLoadingIndication())
if (global.METAMASK_DEBUG) console.log(`background.clearSeedWordCache`) log.debug(`background.clearSeedWordCache`)
background.clearSeedWordCache((err, account) => { background.clearSeedWordCache((err, account) => {
dispatch(actions.hideLoadingIndication()) dispatch(actions.hideLoadingIndication())
if (err) { if (err) {
@ -224,7 +224,7 @@ function confirmSeedWords () {
function createNewVaultAndRestore (password, seed) { function createNewVaultAndRestore (password, seed) {
return (dispatch) => { return (dispatch) => {
dispatch(actions.showLoadingIndication()) dispatch(actions.showLoadingIndication())
if (global.METAMASK_DEBUG) console.log(`background.createNewVaultAndRestore`) log.debug(`background.createNewVaultAndRestore`)
background.createNewVaultAndRestore(password, seed, (err) => { background.createNewVaultAndRestore(password, seed, (err) => {
dispatch(actions.hideLoadingIndication()) dispatch(actions.hideLoadingIndication())
if (err) return dispatch(actions.displayWarning(err.message)) if (err) return dispatch(actions.displayWarning(err.message))
@ -236,12 +236,12 @@ function createNewVaultAndRestore (password, seed) {
function createNewVaultAndKeychain (password) { function createNewVaultAndKeychain (password) {
return (dispatch) => { return (dispatch) => {
dispatch(actions.showLoadingIndication()) dispatch(actions.showLoadingIndication())
if (global.METAMASK_DEBUG) console.log(`background.createNewVaultAndKeychain`) log.debug(`background.createNewVaultAndKeychain`)
background.createNewVaultAndKeychain(password, (err) => { background.createNewVaultAndKeychain(password, (err) => {
if (err) { if (err) {
return dispatch(actions.displayWarning(err.message)) return dispatch(actions.displayWarning(err.message))
} }
if (global.METAMASK_DEBUG) console.log(`background.placeSeedWords`) log.debug(`background.placeSeedWords`)
background.placeSeedWords((err) => { background.placeSeedWords((err) => {
if (err) { if (err) {
return dispatch(actions.displayWarning(err.message)) return dispatch(actions.displayWarning(err.message))
@ -262,10 +262,10 @@ function revealSeedConfirmation () {
function requestRevealSeed (password) { function requestRevealSeed (password) {
return (dispatch) => { return (dispatch) => {
dispatch(actions.showLoadingIndication()) dispatch(actions.showLoadingIndication())
if (global.METAMASK_DEBUG) console.log(`background.submitPassword`) log.debug(`background.submitPassword`)
background.submitPassword(password, (err) => { background.submitPassword(password, (err) => {
if (err) return dispatch(actions.displayWarning(err.message)) if (err) return dispatch(actions.displayWarning(err.message))
if (global.METAMASK_DEBUG) console.log(`background.placeSeedWords`) log.debug(`background.placeSeedWords`)
background.placeSeedWords((err) => { background.placeSeedWords((err) => {
if (err) return dispatch(actions.displayWarning(err.message)) if (err) return dispatch(actions.displayWarning(err.message))
dispatch(actions.hideLoadingIndication()) dispatch(actions.hideLoadingIndication())
@ -277,7 +277,7 @@ function requestRevealSeed (password) {
function addNewKeyring (type, opts) { function addNewKeyring (type, opts) {
return (dispatch) => { return (dispatch) => {
dispatch(actions.showLoadingIndication()) dispatch(actions.showLoadingIndication())
if (global.METAMASK_DEBUG) console.log(`background.addNewKeyring`) log.debug(`background.addNewKeyring`)
background.addNewKeyring(type, opts, (err) => { background.addNewKeyring(type, opts, (err) => {
dispatch(actions.hideLoadingIndication()) dispatch(actions.hideLoadingIndication())
if (err) return dispatch(actions.displayWarning(err.message)) if (err) return dispatch(actions.displayWarning(err.message))
@ -289,11 +289,11 @@ function addNewKeyring (type, opts) {
function importNewAccount (strategy, args) { function importNewAccount (strategy, args) {
return (dispatch) => { return (dispatch) => {
dispatch(actions.showLoadingIndication('This may take a while, be patient.')) dispatch(actions.showLoadingIndication('This may take a while, be patient.'))
if (global.METAMASK_DEBUG) console.log(`background.importAccountWithStrategy`) log.debug(`background.importAccountWithStrategy`)
background.importAccountWithStrategy(strategy, args, (err) => { background.importAccountWithStrategy(strategy, args, (err) => {
dispatch(actions.hideLoadingIndication()) dispatch(actions.hideLoadingIndication())
if (err) return dispatch(actions.displayWarning(err.message)) if (err) return dispatch(actions.displayWarning(err.message))
if (global.METAMASK_DEBUG) console.log(`background.getState`) log.debug(`background.getState`)
background.getState((err, newState) => { background.getState((err, newState) => {
if (err) { if (err) {
return dispatch(actions.displayWarning(err.message)) return dispatch(actions.displayWarning(err.message))
@ -315,7 +315,7 @@ function navigateToNewAccountScreen() {
} }
function addNewAccount () { function addNewAccount () {
if (global.METAMASK_DEBUG) console.log(`background.addNewAccount`) log.debug(`background.addNewAccount`)
return callBackgroundThenUpdate(background.addNewAccount) return callBackgroundThenUpdate(background.addNewAccount)
} }
@ -328,7 +328,7 @@ function showInfoPage () {
function setCurrentFiat (currencyCode) { function setCurrentFiat (currencyCode) {
return (dispatch) => { return (dispatch) => {
dispatch(this.showLoadingIndication()) dispatch(this.showLoadingIndication())
if (global.METAMASK_DEBUG) console.log(`background.setCurrentFiat`) log.debug(`background.setCurrentFiat`)
background.setCurrentCurrency(currencyCode, (err, data) => { background.setCurrentCurrency(currencyCode, (err, data) => {
dispatch(this.hideLoadingIndication()) dispatch(this.hideLoadingIndication())
if (err) { if (err) {
@ -348,28 +348,38 @@ function setCurrentFiat (currencyCode) {
} }
function signMsg (msgData) { function signMsg (msgData) {
log.debug('action - signMsg')
return (dispatch) => { return (dispatch) => {
dispatch(actions.showLoadingIndication()) dispatch(actions.showLoadingIndication())
if (global.METAMASK_DEBUG) console.log(`background.signMessage`) log.debug(`actions calling background.signMessage`)
background.signMessage(msgData, (err) => { background.signMessage(msgData, (err, newState) => {
log.debug('signMessage called back')
dispatch(actions.updateMetamaskState(newState))
dispatch(actions.hideLoadingIndication()) dispatch(actions.hideLoadingIndication())
if (err) log.error(err)
if (err) return dispatch(actions.displayWarning(err.message)) if (err) return dispatch(actions.displayWarning(err.message))
dispatch(actions.completedTx(msgData.metamaskId)) dispatch(actions.completedTx(msgData.metamaskId))
}) })
} }
} }
function signPersonalMsg (msgData) { function signPersonalMsg (msgData) {
log.debug('action - signPersonalMsg')
return (dispatch) => { return (dispatch) => {
dispatch(actions.showLoadingIndication()) dispatch(actions.showLoadingIndication())
if (global.METAMASK_DEBUG) console.log(`background.signMessage`) log.debug(`actions calling background.signPersonalMessage`)
background.signPersonalMessage(msgData, (err) => { background.signPersonalMessage(msgData, (err, newState) => {
log.debug('signPersonalMessage called back')
dispatch(actions.updateMetamaskState(newState))
dispatch(actions.hideLoadingIndication()) dispatch(actions.hideLoadingIndication())
if (err) log.error(err)
if (err) return dispatch(actions.displayWarning(err.message)) if (err) return dispatch(actions.displayWarning(err.message))
dispatch(actions.completedTx(msgData.metamaskId)) dispatch(actions.completedTx(msgData.metamaskId))
}) })
} }
@ -377,7 +387,7 @@ function signPersonalMsg (msgData) {
function signTx (txData) { function signTx (txData) {
return (dispatch) => { return (dispatch) => {
if (global.METAMASK_DEBUG) console.log(`background.setGasMultiplier`) log.debug(`background.setGasMultiplier`)
background.setGasMultiplier(txData.gasMultiplier, (err) => { background.setGasMultiplier(txData.gasMultiplier, (err) => {
if (err) return dispatch(actions.displayWarning(err.message)) if (err) return dispatch(actions.displayWarning(err.message))
web3.eth.sendTransaction(txData, (err, data) => { web3.eth.sendTransaction(txData, (err, data) => {
@ -392,8 +402,9 @@ function signTx (txData) {
} }
function sendTx (txData) { function sendTx (txData) {
log.info('actions: sendTx')
return (dispatch) => { return (dispatch) => {
if (global.METAMASK_DEBUG) console.log(`background.approveTransaction`) log.debug(`actions calling background.approveTransaction`)
background.approveTransaction(txData.id, (err) => { background.approveTransaction(txData.id, (err) => {
if (err) { if (err) {
dispatch(actions.txError(err)) dispatch(actions.txError(err))
@ -419,19 +430,19 @@ function txError (err) {
} }
function cancelMsg (msgData) { function cancelMsg (msgData) {
if (global.METAMASK_DEBUG) console.log(`background.cancelMessage`) log.debug(`background.cancelMessage`)
background.cancelMessage(msgData.id) background.cancelMessage(msgData.id)
return actions.completedTx(msgData.id) return actions.completedTx(msgData.id)
} }
function cancelPersonalMsg (msgData) { function cancelPersonalMsg (msgData) {
if (global.METAMASK_DEBUG) console.log(`background.cancelMessage`) log.debug(`background.cancelMessage`)
background.cancelPersonalMessage(msgData.id) background.cancelPersonalMessage(msgData.id)
return actions.completedTx(msgData.id) return actions.completedTx(msgData.id)
} }
function cancelTx (txData) { function cancelTx (txData) {
if (global.METAMASK_DEBUG) console.log(`background.cancelTransaction`) log.debug(`background.cancelTransaction`)
background.cancelTransaction(txData.id) background.cancelTransaction(txData.id)
return actions.completedTx(txData.id) return actions.completedTx(txData.id)
} }
@ -527,14 +538,14 @@ function updateMetamaskState (newState) {
} }
function lockMetamask () { function lockMetamask () {
if (global.METAMASK_DEBUG) console.log(`background.setLocked`) log.debug(`background.setLocked`)
return callBackgroundThenUpdate(background.setLocked) return callBackgroundThenUpdate(background.setLocked)
} }
function showAccountDetail (address) { function showAccountDetail (address) {
return (dispatch) => { return (dispatch) => {
dispatch(actions.showLoadingIndication()) dispatch(actions.showLoadingIndication())
if (global.METAMASK_DEBUG) console.log(`background.setSelectedAddress`) log.debug(`background.setSelectedAddress`)
background.setSelectedAddress(address, (err) => { background.setSelectedAddress(address, (err) => {
dispatch(actions.hideLoadingIndication()) dispatch(actions.hideLoadingIndication())
if (err) { if (err) {
@ -607,7 +618,7 @@ function goBackToInitView () {
function markNoticeRead (notice) { function markNoticeRead (notice) {
return (dispatch) => { return (dispatch) => {
dispatch(this.showLoadingIndication()) dispatch(this.showLoadingIndication())
if (global.METAMASK_DEBUG) console.log(`background.markNoticeRead`) log.debug(`background.markNoticeRead`)
background.markNoticeRead(notice, (err, notice) => { background.markNoticeRead(notice, (err, notice) => {
dispatch(this.hideLoadingIndication()) dispatch(this.hideLoadingIndication())
if (err) { if (err) {
@ -639,7 +650,7 @@ function clearNotices () {
} }
function markAccountsFound() { function markAccountsFound() {
if (global.METAMASK_DEBUG) console.log(`background.markAccountsFound`) log.debug(`background.markAccountsFound`)
return callBackgroundThenUpdate(background.markAccountsFound) return callBackgroundThenUpdate(background.markAccountsFound)
} }
@ -648,7 +659,7 @@ function markAccountsFound() {
// //
function setRpcTarget (newRpc) { function setRpcTarget (newRpc) {
if (global.METAMASK_DEBUG) console.log(`background.setRpcTarget`) log.debug(`background.setRpcTarget`)
background.setRpcTarget(newRpc) background.setRpcTarget(newRpc)
return { return {
type: actions.SET_RPC_TARGET, type: actions.SET_RPC_TARGET,
@ -657,7 +668,7 @@ function setRpcTarget (newRpc) {
} }
function setProviderType (type) { function setProviderType (type) {
if (global.METAMASK_DEBUG) console.log(`background.setProviderType`) log.debug(`background.setProviderType`)
background.setProviderType(type) background.setProviderType(type)
return { return {
type: actions.SET_PROVIDER_TYPE, type: actions.SET_PROVIDER_TYPE,
@ -666,7 +677,7 @@ function setProviderType (type) {
} }
function useEtherscanProvider () { function useEtherscanProvider () {
if (global.METAMASK_DEBUG) console.log(`background.useEtherscanProvider`) log.debug(`background.useEtherscanProvider`)
background.useEtherscanProvider() background.useEtherscanProvider()
return { return {
type: actions.USE_ETHERSCAN_PROVIDER, type: actions.USE_ETHERSCAN_PROVIDER,
@ -723,7 +734,7 @@ function exportAccount (address) {
return function (dispatch) { return function (dispatch) {
dispatch(self.showLoadingIndication()) dispatch(self.showLoadingIndication())
if (global.METAMASK_DEBUG) console.log(`background.exportAccount`) log.debug(`background.exportAccount`)
background.exportAccount(address, function (err, result) { background.exportAccount(address, function (err, result) {
dispatch(self.hideLoadingIndication()) dispatch(self.hideLoadingIndication())
@ -747,7 +758,7 @@ function showPrivateKey (key) {
function saveAccountLabel (account, label) { function saveAccountLabel (account, label) {
return (dispatch) => { return (dispatch) => {
dispatch(actions.showLoadingIndication()) dispatch(actions.showLoadingIndication())
if (global.METAMASK_DEBUG) console.log(`background.saveAccountLabel`) log.debug(`background.saveAccountLabel`)
background.saveAccountLabel(account, label, (err) => { background.saveAccountLabel(account, label, (err) => {
dispatch(actions.hideLoadingIndication()) dispatch(actions.hideLoadingIndication())
if (err) { if (err) {
@ -769,7 +780,7 @@ function showSendPage () {
function buyEth (address, amount) { function buyEth (address, amount) {
return (dispatch) => { return (dispatch) => {
if (global.METAMASK_DEBUG) console.log(`background.buyEth`) log.debug(`background.buyEth`)
background.buyEth(address, amount) background.buyEth(address, amount)
dispatch({ dispatch({
type: actions.BUY_ETH, type: actions.BUY_ETH,
@ -849,7 +860,7 @@ function coinShiftRquest (data, marketData) {
if (response.error) return dispatch(actions.displayWarning(response.error)) if (response.error) return dispatch(actions.displayWarning(response.error))
var message = ` var message = `
Deposit your ${response.depositType} to the address bellow:` Deposit your ${response.depositType} to the address bellow:`
if (global.METAMASK_DEBUG) console.log(`background.createShapeShiftTx`) log.debug(`background.createShapeShiftTx`)
background.createShapeShiftTx(response.deposit, response.depositType) background.createShapeShiftTx(response.deposit, response.depositType)
dispatch(actions.showQrView(response.deposit, [message].concat(marketData))) dispatch(actions.showQrView(response.deposit, [message].concat(marketData)))
}) })
@ -929,7 +940,7 @@ function callBackgroundThenUpdate (method, ...args) {
} }
function forceUpdateMetamaskState(dispatch){ function forceUpdateMetamaskState(dispatch){
if (global.METAMASK_DEBUG) console.log(`background.getState`) log.debug(`background.getState`)
background.getState((err, newState) => { background.getState((err, newState) => {
if (err) { if (err) {
return dispatch(actions.displayWarning(err.message)) return dispatch(actions.displayWarning(err.message))

View File

@ -64,6 +64,7 @@ function mapStateToProps (state) {
App.prototype.render = function () { App.prototype.render = function () {
var props = this.props var props = this.props
const { isLoading, loadingMessage, transForward } = props const { isLoading, loadingMessage, transForward } = props
log.debug('Main ui render function')
return ( return (
@ -347,6 +348,7 @@ App.prototype.renderBackButton = function (style, justArrow = false) {
} }
App.prototype.renderPrimary = function () { App.prototype.renderPrimary = function () {
log.debug('rendering primary')
var props = this.props var props = this.props
// notices // notices

View File

@ -0,0 +1,50 @@
const Component = require('react').Component
const h = require('react-hyperscript')
const inherits = require('util').inherits
const AccountPanel = require('./account-panel')
module.exports = PendingMsgDetails
inherits(PendingMsgDetails, Component)
function PendingMsgDetails () {
Component.call(this)
}
PendingMsgDetails.prototype.render = function () {
var state = this.props
var msgData = state.txData
var msgParams = msgData.msgParams || {}
var address = msgParams.from || state.selectedAddress
var identity = state.identities[address] || { address: address }
var account = state.accounts[address] || { address: address }
return (
h('div', {
key: msgData.id,
style: {
margin: '10px 20px',
},
}, [
// account that will sign
h(AccountPanel, {
showFullAddress: true,
identity: identity,
account: account,
imageifyIdenticons: state.imageifyIdenticons,
}),
// message data
h('.tx-data.flex-column.flex-justify-center.flex-grow.select-none', [
h('.flex-row.flex-space-between', [
h('label.font-small', 'MESSAGE'),
h('span.font-small', msgParams.data),
]),
]),
])
)
}

View File

@ -1,7 +1,7 @@
const Component = require('react').Component const Component = require('react').Component
const h = require('react-hyperscript') const h = require('react-hyperscript')
const inherits = require('util').inherits const inherits = require('util').inherits
const PendingTxDetails = require('./pending-msg-details') const PendingTxDetails = require('./pending-personal-msg-details')
module.exports = PendingMsg module.exports = PendingMsg
@ -37,7 +37,7 @@ PendingMsg.prototype.render = function () {
onClick: state.cancelMessage, onClick: state.cancelMessage,
}, 'Cancel'), }, 'Cancel'),
h('button', { h('button', {
onClick: state.signMessage, onClick: state.signPersonalMessage,
}, 'Sign'), }, 'Sign'),
]), ]),
]) ])

View File

@ -109,6 +109,7 @@ ConfirmTxScreen.prototype.render = function () {
sendTransaction: this.sendTransaction.bind(this, txData), sendTransaction: this.sendTransaction.bind(this, txData),
cancelTransaction: this.cancelTransaction.bind(this, txData), cancelTransaction: this.cancelTransaction.bind(this, txData),
signMessage: this.signMessage.bind(this, txData), signMessage: this.signMessage.bind(this, txData),
signPersonalMessage: this.signPersonalMessage.bind(this, txData),
cancelMessage: this.cancelMessage.bind(this, txData), cancelMessage: this.cancelMessage.bind(this, txData),
}), }),
@ -167,13 +168,24 @@ 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')
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))
} }
ConfirmTxScreen.prototype.signPersonalMessage = function (msgData, event) {
log.info('conf-tx.js: signing personal message')
var params = msgData.msgParams
params.metamaskId = msgData.id
event.stopPropagation()
this.props.dispatch(actions.signPersonalMsg(params))
}
ConfirmTxScreen.prototype.cancelMessage = function (msgData, event) { ConfirmTxScreen.prototype.cancelMessage = function (msgData, event) {
log.info('canceling message')
event.stopPropagation() event.stopPropagation()
this.props.dispatch(actions.cancelMsg(msgData)) this.props.dispatch(actions.cancelMsg(msgData))
} }
@ -185,7 +197,7 @@ ConfirmTxScreen.prototype.goHome = function (event) {
function warningIfExists (warning) { function warningIfExists (warning) {
if (warning && if (warning &&
// Do not display user rejections on this screen: // Do not display user rejections on this screen:
warning.indexOf('User denied transaction signature') === -1) { warning.indexOf('User denied transaction signature') === -1) {
return h('.error', { return h('.error', {
style: { style: {

View File

@ -6,6 +6,7 @@ const notification = require('../../../app/scripts/lib/notifications')
module.exports = reduceApp module.exports = reduceApp
function reduceApp (state, action) { function reduceApp (state, action) {
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) const pendingTxs = hasPendingTxs(state)
@ -289,32 +290,36 @@ function reduceApp (state, action) {
case actions.SHOW_CONF_TX_PAGE: case actions.SHOW_CONF_TX_PAGE:
return extend(appState, { return extend(appState, {
currentView: { currentView: {
name: 'confTx', name: pendingTxs ? 'confTx' : 'account-detail',
context: 0, context: 0,
}, },
transForward: action.transForward, transForward: action.transForward,
warning: null, warning: null,
isLoading: false,
}) })
case actions.SHOW_CONF_MSG_PAGE: case actions.SHOW_CONF_MSG_PAGE:
return extend(appState, { return extend(appState, {
currentView: { currentView: {
name: 'confTx', name: pendingTxs ? 'confTx' : 'account-detail',
context: 0, context: 0,
}, },
transForward: true, transForward: true,
warning: null, warning: null,
isLoading: false,
}) })
case actions.COMPLETED_TX: case actions.COMPLETED_TX:
var unapprovedTxs = state.metamask.unapprovedTxs log.debug('reducing COMPLETED_TX')
var unapprovedMsgs = state.metamask.unapprovedMsgs var { unapprovedTxs, unapprovedMsgs,
var network = state.metamask.network unapprovedPersonalMsgs, network } = state.metamask
var unconfTxList = txHelper(unapprovedTxs, unapprovedMsgs, network) var unconfTxList = txHelper(unapprovedTxs, unapprovedMsgs, unapprovedPersonalMsgs, network)
.filter(tx => tx !== tx.id) .filter(tx => tx !== tx.id)
log.debug(`actions - COMPLETED_TX with ${unconfTxList.length} txs`)
if (unconfTxList && unconfTxList.length > 0) { if (unconfTxList && unconfTxList.length > 0) {
log.debug('reducer detected txs - rendering confTx view')
return extend(appState, { return extend(appState, {
transForward: false, transForward: false,
currentView: { currentView: {
@ -324,6 +329,7 @@ function reduceApp (state, action) {
warning: null, warning: null,
}) })
} else { } else {
log.debug('attempting to close popup')
notification.closePopup() notification.closePopup()
return extend(appState, { return extend(appState, {
@ -572,10 +578,12 @@ function reduceApp (state, action) {
} }
function hasPendingTxs (state) { function hasPendingTxs (state) {
var unapprovedTxs = state.metamask.unapprovedTxs var { unapprovedTxs, unapprovedMsgs,
var unapprovedMsgs = state.metamask.unapprovedMsgs unapprovedPersonalMsgs, network } = state.metamask
var network = state.metamask.network
var unconfTxList = txHelper(unapprovedTxs, unapprovedMsgs, network) 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 unconfTxList.length > 0
} }

View File

@ -6,9 +6,10 @@ const configureStore = require('./app/store')
const txHelper = require('./lib/tx-helper') const txHelper = require('./lib/tx-helper')
module.exports = launchApp module.exports = launchApp
let debugMode = window.METAMASK_DEBUG
const log = require('loglevel') const log = require('loglevel')
window.log = log window.log = log
log.setLevel('warn') log.setLevel(debugMode ? 'debug' : 'warn')
function launchApp (opts) { function launchApp (opts) {
var accountManager = opts.accountManager var accountManager = opts.accountManager

View File

@ -10,6 +10,7 @@ module.exports = function (unapprovedTxs, unapprovedMsgs, personalMsgs, network)
log.debug(`tx helper found ${msgValues.length} unsigned messages`) log.debug(`tx helper found ${msgValues.length} unsigned messages`)
let allValues = txValues.concat(msgValues) let allValues = txValues.concat(msgValues)
const personalValues = valuesFor(personalMsgs) const personalValues = valuesFor(personalMsgs)
log.debug(`tx helper found ${personalValues.length} unsigned personal messages`)
allValues = allValues.concat(personalValues) allValues = allValues.concat(personalValues)
return allValues.sort(tx => tx.time) return allValues.sort(tx => tx.time)