mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
commit
5fc24930a7
@ -8,6 +8,7 @@ const TxGasUtil = require('./tx-gas-utils')
|
||||
const PendingTransactionTracker = require('./pending-tx-tracker')
|
||||
const NonceTracker = require('./nonce-tracker')
|
||||
const txUtils = require('./lib/util')
|
||||
const cleanErrorStack = require('../../lib/cleanErrorStack')
|
||||
const log = require('loglevel')
|
||||
|
||||
/**
|
||||
@ -118,6 +119,7 @@ class TransactionController extends EventEmitter {
|
||||
@param txParams {object} - txParams for the transaction
|
||||
@param opts {object} - with the key origin to put the origin on the txMeta
|
||||
*/
|
||||
|
||||
async newUnapprovedTransaction (txParams, opts = {}) {
|
||||
log.debug(`MetaMaskController newUnapprovedTransaction ${JSON.stringify(txParams)}`)
|
||||
const initialTxMeta = await this.addUnapprovedTransaction(txParams)
|
||||
@ -130,11 +132,11 @@ class TransactionController extends EventEmitter {
|
||||
case 'submitted':
|
||||
return resolve(finishedTxMeta.hash)
|
||||
case 'rejected':
|
||||
return reject(new Error('MetaMask Tx Signature: User denied transaction signature.'))
|
||||
return reject(cleanErrorStack(new Error('MetaMask Tx Signature: User denied transaction signature.')))
|
||||
case 'failed':
|
||||
return reject(new Error(finishedTxMeta.err.message))
|
||||
return reject(cleanErrorStack(new Error(finishedTxMeta.err.message)))
|
||||
default:
|
||||
return reject(new Error(`MetaMask Tx Signature: Unknown problem: ${JSON.stringify(finishedTxMeta.txParams)}`))
|
||||
return reject(cleanErrorStack(new Error(`MetaMask Tx Signature: Unknown problem: ${JSON.stringify(finishedTxMeta.txParams)}`)))
|
||||
}
|
||||
})
|
||||
})
|
||||
|
24
app/scripts/lib/cleanErrorStack.js
Normal file
24
app/scripts/lib/cleanErrorStack.js
Normal file
@ -0,0 +1,24 @@
|
||||
/**
|
||||
* Returns error without stack trace for better UI display
|
||||
* @param {Error} err - error
|
||||
* @returns {Error} Error with clean stack trace.
|
||||
*/
|
||||
function cleanErrorStack(err){
|
||||
var name = err.name
|
||||
name = (name === undefined) ? 'Error' : String(name)
|
||||
|
||||
var msg = err.message
|
||||
msg = (msg === undefined) ? '' : String(msg)
|
||||
|
||||
if (name === '') {
|
||||
err.stack = err.message
|
||||
} else if (msg === '') {
|
||||
err.stack = err.name
|
||||
} else {
|
||||
err.stack = err.name + ': ' + err.message
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
module.exports = cleanErrorStack
|
@ -45,6 +45,7 @@ const BN = require('ethereumjs-util').BN
|
||||
const GWEI_BN = new BN('1000000000')
|
||||
const percentile = require('percentile')
|
||||
const seedPhraseVerifier = require('./lib/seed-phrase-verifier')
|
||||
const cleanErrorStack = require('./lib/cleanErrorStack')
|
||||
const log = require('loglevel')
|
||||
|
||||
module.exports = class MetamaskController extends EventEmitter {
|
||||
@ -637,9 +638,9 @@ module.exports = class MetamaskController extends EventEmitter {
|
||||
case 'signed':
|
||||
return cb(null, data.rawSig)
|
||||
case 'rejected':
|
||||
return cb(new Error('MetaMask Message Signature: User denied message signature.'))
|
||||
return cb(cleanErrorStack(new Error('MetaMask Message Signature: User denied message signature.')))
|
||||
default:
|
||||
return cb(new Error(`MetaMask Message Signature: Unknown problem: ${JSON.stringify(msgParams)}`))
|
||||
return cb(cleanErrorStack(new Error(`MetaMask Message Signature: Unknown problem: ${JSON.stringify(msgParams)}`)))
|
||||
}
|
||||
})
|
||||
}
|
||||
@ -697,7 +698,7 @@ module.exports = class MetamaskController extends EventEmitter {
|
||||
*/
|
||||
newUnsignedPersonalMessage (msgParams, cb) {
|
||||
if (!msgParams.from) {
|
||||
return cb(new Error('MetaMask Message Signature: from field is required.'))
|
||||
return cb(cleanErrorStack(new Error('MetaMask Message Signature: from field is required.')))
|
||||
}
|
||||
|
||||
const msgId = this.personalMessageManager.addUnapprovedMessage(msgParams)
|
||||
@ -708,9 +709,9 @@ module.exports = class MetamaskController extends EventEmitter {
|
||||
case 'signed':
|
||||
return cb(null, data.rawSig)
|
||||
case 'rejected':
|
||||
return cb(new Error('MetaMask Message Signature: User denied message signature.'))
|
||||
return cb(cleanErrorStack(new Error('MetaMask Message Signature: User denied message signature.')))
|
||||
default:
|
||||
return cb(new Error(`MetaMask Message Signature: Unknown problem: ${JSON.stringify(msgParams)}`))
|
||||
return cb(cleanErrorStack(new Error(`MetaMask Message Signature: Unknown problem: ${JSON.stringify(msgParams)}`)))
|
||||
}
|
||||
})
|
||||
}
|
||||
@ -776,9 +777,9 @@ module.exports = class MetamaskController extends EventEmitter {
|
||||
case 'signed':
|
||||
return cb(null, data.rawSig)
|
||||
case 'rejected':
|
||||
return cb(new Error('MetaMask Message Signature: User denied message signature.'))
|
||||
return cb(cleanErrorStack(new Error('MetaMask Message Signature: User denied message signature.')))
|
||||
default:
|
||||
return cb(new Error(`MetaMask Message Signature: Unknown problem: ${JSON.stringify(msgParams)}`))
|
||||
return cb(cleanErrorStack(new Error(`MetaMask Message Signature: Unknown problem: ${JSON.stringify(msgParams)}`)))
|
||||
}
|
||||
})
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user