aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorkumavis <kumavis@users.noreply.github.com>2017-08-03 10:57:16 +0800
committerGitHub <noreply@github.com>2017-08-03 10:57:16 +0800
commit8a9d0073b1d6b959e9374180e2f52d12ea8319ca (patch)
treed1718624781338be20181aa40d461d99304e274d /app
parent2c37d438885865fb9b93769a6dee9fb32f8d82aa (diff)
parent5ac4c2de6fa3a83709eeefc71d5afc0857a28445 (diff)
downloadtangerine-wallet-browser-8a9d0073b1d6b959e9374180e2f52d12ea8319ca.tar
tangerine-wallet-browser-8a9d0073b1d6b959e9374180e2f52d12ea8319ca.tar.gz
tangerine-wallet-browser-8a9d0073b1d6b959e9374180e2f52d12ea8319ca.tar.bz2
tangerine-wallet-browser-8a9d0073b1d6b959e9374180e2f52d12ea8319ca.tar.lz
tangerine-wallet-browser-8a9d0073b1d6b959e9374180e2f52d12ea8319ca.tar.xz
tangerine-wallet-browser-8a9d0073b1d6b959e9374180e2f52d12ea8319ca.tar.zst
tangerine-wallet-browser-8a9d0073b1d6b959e9374180e2f52d12ea8319ca.zip
Merge pull request #1848 from MetaMask/transactionControllerRefractor
Transaction controller refractor part 1: promises for everyone and more tests!
Diffstat (limited to 'app')
-rw-r--r--app/scripts/background.js2
-rw-r--r--app/scripts/controllers/transactions.js345
-rw-r--r--app/scripts/lib/tx-utils.js61
-rw-r--r--app/scripts/metamask-controller.js30
4 files changed, 191 insertions, 247 deletions
diff --git a/app/scripts/background.js b/app/scripts/background.js
index a235afff3..f077ca7a8 100644
--- a/app/scripts/background.js
+++ b/app/scripts/background.js
@@ -121,7 +121,7 @@ function setupController (initState) {
// plugin badge text
function updateBadge () {
var label = ''
- var unapprovedTxCount = controller.txController.unapprovedTxCount
+ var unapprovedTxCount = controller.txController.getUnapprovedTxCount()
var unapprovedMsgCount = controller.messageManager.unapprovedMsgCount
var unapprovedPersonalMsgs = controller.personalMessageManager.unapprovedPersonalMsgCount
var count = unapprovedTxCount + unapprovedMsgCount + unapprovedPersonalMsgs
diff --git a/app/scripts/controllers/transactions.js b/app/scripts/controllers/transactions.js
index f71659042..720323e41 100644
--- a/app/scripts/controllers/transactions.js
+++ b/app/scripts/controllers/transactions.js
@@ -1,10 +1,9 @@
const EventEmitter = require('events')
-const async = require('async')
const extend = require('xtend')
const clone = require('clone')
const ObservableStore = require('obs-store')
const ethUtil = require('ethereumjs-util')
-const pify = require('pify')
+const EthQuery = require('ethjs-query')
const TxProviderUtil = require('../lib/tx-utils')
const getStack = require('../lib/util').getStack
const createId = require('../lib/random-id')
@@ -32,7 +31,7 @@ module.exports = class TransactionController extends EventEmitter {
})
},
})
- this.query = opts.ethQuery
+ this.query = new EthQuery(this.provider)
this.txProviderUtils = new TxProviderUtil(this.query)
this.blockTracker.on('rawBlock', this.checkForTxInBlock.bind(this))
// this is a little messy but until ethstore has been either
@@ -61,13 +60,6 @@ module.exports = class TransactionController extends EventEmitter {
return this.preferencesStore.getState().selectedAddress
}
- // Returns the tx list
- getTxList () {
- const network = this.getNetwork()
- const fullTxList = this.getFullTxList()
- return fullTxList.filter(txMeta => txMeta.metamaskNetworkId === network)
- }
-
// Returns the number of txs for the current network.
getTxCount () {
return this.getTxList().length
@@ -78,6 +70,58 @@ module.exports = class TransactionController extends EventEmitter {
return this.store.getState().transactions
}
+ getUnapprovedTxCount () {
+ return Object.keys(this.getUnapprovedTxList()).length
+ }
+
+ getPendingTxCount () {
+ return this.getTxsByMetaData('status', 'signed').length
+ }
+
+ // Returns the tx list
+ getTxList () {
+ const network = this.getNetwork()
+ const fullTxList = this.getFullTxList()
+ return this.getTxsByMetaData('metamaskNetworkId', network, fullTxList)
+ }
+
+ // gets tx by Id and returns it
+ getTx (txId) {
+ const txList = this.getTxList()
+ const txMeta = txList.find(txData => txData.id === txId)
+ return txMeta
+ }
+ getUnapprovedTxList () {
+ const txList = this.getTxList()
+ return txList.filter((txMeta) => txMeta.status === 'unapproved')
+ .reduce((result, tx) => {
+ result[tx.id] = tx
+ return result
+ }, {})
+ }
+
+ updateTx (txMeta) {
+ // create txMeta snapshot for history
+ const txMetaForHistory = clone(txMeta)
+ // dont include previous history in this snapshot
+ delete txMetaForHistory.history
+ // add stack to help understand why tx was updated
+ txMetaForHistory.stack = getStack()
+ // add snapshot to tx history
+ if (!txMeta.history) txMeta.history = []
+ txMeta.history.push(txMetaForHistory)
+
+ const txId = txMeta.id
+ const txList = this.getFullTxList()
+ const index = txList.findIndex(txData => txData.id === txId)
+ if (!txMeta.history) txMeta.history = []
+ txMeta.history.push(txMetaForHistory)
+
+ txList[index] = txMeta
+ this._saveTxList(txList)
+ this.emit('update')
+ }
+
// Adds a tx to the txlist
addTx (txMeta) {
const txCount = this.getTxCount()
@@ -91,7 +135,7 @@ module.exports = class TransactionController extends EventEmitter {
// or rejected tx's.
// not tx's that are pending or unapproved
if (txCount > txHistoryLimit - 1) {
- var index = fullTxList.findIndex((metaTx) => ((metaTx.status === 'confirmed' || metaTx.status === 'rejected') && network === txMeta.metamaskNetworkId))
+ const index = fullTxList.findIndex((metaTx) => ((metaTx.status === 'confirmed' || metaTx.status === 'rejected') && network === txMeta.metamaskNetworkId))
fullTxList.splice(index, 1)
}
fullTxList.push(txMeta)
@@ -109,92 +153,59 @@ module.exports = class TransactionController extends EventEmitter {
this.emit(`${txMeta.id}:unapproved`, txMeta)
}
- // gets tx by Id and returns it
- getTx (txId, cb) {
- var txList = this.getTxList()
- var txMeta = txList.find(txData => txData.id === txId)
- return cb ? cb(txMeta) : txMeta
- }
-
- //
- updateTx (txMeta) {
- // create txMeta snapshot for history
- const txMetaForHistory = clone(txMeta)
- // dont include previous history in this snapshot
- delete txMetaForHistory.history
- // add stack to help understand why tx was updated
- txMetaForHistory.stack = getStack()
- // add snapshot to tx history
- if (!txMeta.history) txMeta.history = []
- txMeta.history.push(txMetaForHistory)
-
- // update the tx
- var txId = txMeta.id
- var txList = this.getFullTxList()
- var index = txList.findIndex(txData => txData.id === txId)
- txList[index] = txMeta
- this._saveTxList(txList)
- this.emit('update')
- }
-
- get unapprovedTxCount () {
- return Object.keys(this.getUnapprovedTxList()).length
- }
-
- get pendingTxCount () {
- return this.getTxsByMetaData('status', 'signed').length
+ async newUnapprovedTransaction (txParams) {
+ log.debug(`MetaMaskController newUnapprovedTransaction ${JSON.stringify(txParams)}`)
+ const txMeta = await this.addUnapprovedTransaction(txParams)
+ this.emit('newUnaprovedTx', txMeta)
+ // listen for tx completion (success, fail)
+ return new Promise((resolve, reject) => {
+ this.once(`${txMeta.id}:finished`, (completedTx) => {
+ switch (completedTx.status) {
+ case 'submitted':
+ return resolve(completedTx.hash)
+ case 'rejected':
+ return reject(new Error('MetaMask Tx Signature: User denied transaction signature.'))
+ default:
+ return reject(new Error(`MetaMask Tx Signature: Unknown problem: ${JSON.stringify(completedTx.txParams)}`))
+ }
+ })
+ })
}
- addUnapprovedTransaction (txParams, done) {
- let txMeta = {}
- async.waterfall([
- // validate
- (cb) => this.txProviderUtils.validateTxParams(txParams, cb),
- // construct txMeta
- (cb) => {
- txMeta = {
- id: createId(),
- time: (new Date()).getTime(),
- status: 'unapproved',
- metamaskNetworkId: this.getNetwork(),
- txParams: txParams,
- history: [],
- }
- cb()
- },
- // add default tx params
- (cb) => this.addTxDefaults(txMeta, cb),
- // save txMeta
- (cb) => {
- this.addTx(txMeta)
- cb(null, txMeta)
- },
- ], done)
+ async addUnapprovedTransaction (txParams) {
+ // validate
+ await this.txProviderUtils.validateTxParams(txParams)
+ // construct txMeta
+ const txMeta = {
+ id: createId(),
+ time: (new Date()).getTime(),
+ status: 'unapproved',
+ metamaskNetworkId: this.getNetwork(),
+ txParams: txParams,
+ history: [],
+ }
+ // add default tx params
+ await this.addTxDefaults(txMeta)
+ // save txMeta
+ this.addTx(txMeta)
+ return txMeta
}
- addTxDefaults (txMeta, cb) {
+ async addTxDefaults (txMeta) {
const txParams = txMeta.txParams
// ensure value
txParams.value = txParams.value || '0x0'
if (!txParams.gasPrice) {
- this.query.gasPrice((err, gasPrice) => {
-
- if (err) return cb(err)
- // set gasPrice
- txParams.gasPrice = gasPrice
- })
+ const gasPrice = await this.query.gasPrice()
+ txParams.gasPrice = gasPrice
}
// set gasLimit
- this.txProviderUtils.analyzeGasUsage(txMeta, cb)
+ return await this.txProviderUtils.analyzeGasUsage(txMeta)
}
- getUnapprovedTxList () {
- var txList = this.getTxList()
- return txList.filter((txMeta) => txMeta.status === 'unapproved')
- .reduce((result, tx) => {
- result[tx.id] = tx
- return result
- }, {})
+ async updateAndApproveTransaction (txMeta) {
+ this.updateTx(txMeta)
+ await this.approveTransaction(txMeta.id)
}
async approveTransaction (txId) {
@@ -230,26 +241,6 @@ module.exports = class TransactionController extends EventEmitter {
}
}
- cancelTransaction (txId, cb = warn) {
- this.setTxStatusRejected(txId)
- cb()
- }
-
- async updateAndApproveTransaction (txMeta) {
- this.updateTx(txMeta)
- await this.approveTransaction(txMeta.id)
- }
-
- getChainId () {
- const networkState = this.networkStore.getState()
- const getChainId = parseInt(networkState)
- if (Number.isNaN(getChainId)) {
- return 0
- } else {
- return getChainId
- }
- }
-
async signTransaction (txId) {
const txMeta = this.getTx(txId)
const txParams = txMeta.txParams
@@ -257,10 +248,9 @@ module.exports = class TransactionController extends EventEmitter {
// add network/chain id
txParams.chainId = this.getChainId()
const ethTx = this.txProviderUtils.buildEthTxFromParams(txParams)
- const rawTx = await this.signEthTx(ethTx, fromAddress).then(() => {
- this.setTxStatusSigned(txMeta.id)
- return ethUtil.bufferToHex(ethTx.serialize())
- })
+ await this.signEthTx(ethTx, fromAddress)
+ this.setTxStatusSigned(txMeta.id)
+ const rawTx = ethUtil.bufferToHex(ethTx.serialize())
return rawTx
}
@@ -268,10 +258,24 @@ module.exports = class TransactionController extends EventEmitter {
const txMeta = this.getTx(txId)
txMeta.rawTx = rawTx
this.updateTx(txMeta)
- await this.txProviderUtils.publishTransaction(rawTx).then((txHash) => {
- this.setTxHash(txId, txHash)
- this.setTxStatusSubmitted(txId)
- })
+ const txHash = await this.txProviderUtils.publishTransaction(rawTx)
+ this.setTxHash(txId, txHash)
+ this.setTxStatusSubmitted(txId)
+ }
+
+ async cancelTransaction (txId) {
+ this.setTxStatusRejected(txId)
+ }
+
+
+ getChainId () {
+ const networkState = this.networkStore.getState()
+ const getChainId = parseInt(networkState)
+ if (Number.isNaN(getChainId)) {
+ return 0
+ } else {
+ return getChainId
+ }
}
// receives a txHash records the tx as signed
@@ -284,7 +288,7 @@ module.exports = class TransactionController extends EventEmitter {
/*
Takes an object of fields to search for eg:
- var thingsToLookFor = {
+ let thingsToLookFor = {
to: '0x0..',
from: '0x0..',
status: 'signed',
@@ -307,7 +311,7 @@ module.exports = class TransactionController extends EventEmitter {
and that have been 'confirmed'
*/
getFilteredTxList (opts) {
- var filteredTxList
+ let filteredTxList
Object.keys(opts).forEach((key) => {
filteredTxList = this.getTxsByMetaData(key, opts[key], filteredTxList)
})
@@ -368,7 +372,7 @@ module.exports = class TransactionController extends EventEmitter {
// merges txParams obj onto txData.txParams
// use extend to ensure that all fields are filled
updateTxParams (txId, txParams) {
- var txMeta = this.getTx(txId)
+ const txMeta = this.getTx(txId)
txMeta.txParams = extend(txMeta.txParams, txParams)
this.updateTx(txMeta)
}
@@ -376,20 +380,19 @@ module.exports = class TransactionController extends EventEmitter {
// checks if a signed tx is in a block and
// if included sets the tx status as 'confirmed'
checkForTxInBlock (block) {
- var signedTxList = this.getFilteredTxList({status: 'submitted'})
+ const signedTxList = this.getFilteredTxList({status: 'submitted'})
if (!signedTxList.length) return
signedTxList.forEach((txMeta) => {
- var txHash = txMeta.hash
- var txId = txMeta.id
+ const txHash = txMeta.hash
+ const txId = txMeta.id
if (!txHash) {
- return this.setTxStatusFailed(txId, {
- stack: 'checkForTxInBlock: custom tx-controller error message',
- errCode: 'No hash was provided',
- message: 'We had an error while submitting this transaction, please try again.',
- })
+ const noTxHashErr = new Error('We had an error while submitting this transaction, please try again.')
+ noTxHashErr.name = 'NoTxHashError'
+ this.setTxStatusFailed(txId, noTxHashErr)
}
+
block.transactions.forEach((tx) => {
if (tx.hash === txHash) this.setTxStatusConfirmed(txId)
})
@@ -407,7 +410,45 @@ module.exports = class TransactionController extends EventEmitter {
if (diff > 1) this._checkPendingTxs()
}
- // PRIVATE METHODS
+ resubmitPendingTxs () {
+ const pending = this.getTxsByMetaData('status', 'submitted')
+ // only try resubmitting if their are transactions to resubmit
+ if (!pending.length) return
+ pending.forEach((txMeta) => this._resubmitTx(txMeta).catch((err) => {
+ /*
+ Dont marked as failed if the error is a "known" transaction warning
+ "there is already a transaction with the same sender-nonce
+ but higher/same gas price"
+ */
+ const errorMessage = err.message.toLowerCase()
+ const isKnownTx = (
+ // geth
+ errorMessage.includes('replacement transaction underpriced')
+ || errorMessage.includes('known transaction')
+ // parity
+ || errorMessage.includes('gas price too low to replace')
+ || errorMessage.includes('transaction with the same hash was already imported')
+ // other
+ || errorMessage.includes('gateway timeout')
+ || errorMessage.includes('nonce too low')
+ )
+ // ignore resubmit warnings, return early
+ if (isKnownTx) return
+ // encountered real error - transition to error state
+ this.setTxStatusFailed(txMeta.id, {
+ stack: err.stack || err.message,
+ errCode: err.errCode || err,
+ message: err.message,
+ })
+ }))
+ }
+
+
+/* _____________________________________
+| |
+| PRIVATE METHODS |
+|______________________________________*/
+
// Should find the tx in the tx list and
// update it.
@@ -420,7 +461,7 @@ module.exports = class TransactionController extends EventEmitter {
// - `'confirmed'` the tx has been included in a block.
// - `'failed'` the tx failed for some reason, included on tx data.
_setTxStatus (txId, status) {
- var txMeta = this.getTx(txId)
+ const txMeta = this.getTx(txId)
txMeta.status = status
this.emit(`${txMeta.id}:${status}`, txId)
if (status === 'submitted' || status === 'rejected') {
@@ -445,39 +486,6 @@ module.exports = class TransactionController extends EventEmitter {
this.memStore.updateState({ unapprovedTxs, selectedAddressTxList })
}
- resubmitPendingTxs () {
- const pending = this.getTxsByMetaData('status', 'submitted')
- // only try resubmitting if their are transactions to resubmit
- if (!pending.length) return
- pending.forEach((txMeta) => this._resubmitTx(txMeta).catch((err) => {
- /*
- Dont marked as failed if the error is a "known" transaction warning
- "there is already a transaction with the same sender-nonce
- but higher/same gas price"
- */
- const errorMessage = err.message.toLowerCase()
- const isKnownTx = (
- // geth
- errorMessage.includes('replacement transaction underpriced')
- || errorMessage.includes('known transaction')
- // parity
- || errorMessage.includes('gas price too low to replace')
- || errorMessage.includes('transaction with the same hash was already imported')
- // other
- || errorMessage.includes('gateway timeout')
- || errorMessage.includes('nonce too low')
- )
- // ignore resubmit warnings, return early
- if (isKnownTx) return
- // encountered real error - transition to error state
- this.setTxStatusFailed(txMeta.id, {
- stack: err.stack || err.message,
- errCode: err.errCode || err,
- message: err.message,
- })
- }))
- }
-
async _resubmitTx (txMeta) {
const address = txMeta.txParams.from
const balance = this.ethStore.getState().accounts[address].balance
@@ -524,17 +532,14 @@ module.exports = class TransactionController extends EventEmitter {
// extra check in case there was an uncaught error during the
// signature and submission process
if (!txHash) {
- this.setTxStatusFailed(txId, {
- stack: '_checkPendingTxs: custom tx-controller error message',
- errCode: 'No hash was provided',
- message: 'We had an error while submitting this transaction, please try again.',
- })
- return
+ const noTxHashErr = new Error('We had an error while submitting this transaction, please try again.')
+ noTxHashErr.name = 'NoTxHashError'
+ this.setTxStatusFailed(txId, noTxHashErr)
}
// get latest transaction status
let txParams
try {
- txParams = await pify((cb) => this.query.getTransactionByHash(txHash, cb))()
+ txParams = await this.query.getTransactionByHash(txHash)
if (!txParams) return
if (txParams.blockNumber) {
this.setTxStatusConfirmed(txId)
@@ -547,12 +552,8 @@ module.exports = class TransactionController extends EventEmitter {
message: 'There was a problem loading this transaction.',
}
this.updateTx(txMeta)
- log.error(err)
+ throw err
}
}
}
-
-}
-
-
-const warn = () => log.warn('warn was used no cb provided')
+} \ No newline at end of file
diff --git a/app/scripts/lib/tx-utils.js b/app/scripts/lib/tx-utils.js
index 8f6943937..3687a9652 100644
--- a/app/scripts/lib/tx-utils.js
+++ b/app/scripts/lib/tx-utils.js
@@ -1,4 +1,3 @@
-const async = require('async')
const ethUtil = require('ethereumjs-util')
const Transaction = require('ethereumjs-tx')
const normalize = require('eth-sig-util').normalize
@@ -10,24 +9,19 @@ its passed ethquery
and used to do things like calculate gas of a tx.
*/
-module.exports = class txProviderUtils {
-
+module.exports = class txProvideUtils {
constructor (ethQuery) {
this.query = ethQuery
}
- analyzeGasUsage (txMeta, cb) {
- var self = this
- this.query.getBlockByNumber('latest', true, (err, block) => {
- if (err) return cb(err)
- async.waterfall([
- self.estimateTxGas.bind(self, txMeta, block.gasLimit),
- self.setTxGas.bind(self, txMeta, block.gasLimit),
- ], cb)
- })
+ async analyzeGasUsage (txMeta) {
+ const block = await this.query.getBlockByNumber('latest', true)
+ const estimatedGasHex = await this.estimateTxGas(txMeta, block.gasLimit)
+ this.setTxGas(txMeta, block.gasLimit, estimatedGasHex)
+ return txMeta
}
- estimateTxGas (txMeta, blockGasLimitHex, cb) {
+ async estimateTxGas (txMeta, blockGasLimitHex) {
const txParams = txMeta.txParams
// check if gasLimit is already specified
txMeta.gasLimitSpecified = Boolean(txParams.gas)
@@ -38,10 +32,10 @@ module.exports = class txProviderUtils {
txParams.gas = bnToHex(saferGasLimitBN)
}
// run tx, see if it will OOG
- this.query.estimateGas(txParams, cb)
+ return this.query.estimateGas(txParams)
}
- setTxGas (txMeta, blockGasLimitHex, estimatedGasHex, cb) {
+ setTxGas (txMeta, blockGasLimitHex, estimatedGasHex) {
txMeta.estimatedGas = estimatedGasHex
const txParams = txMeta.txParams
@@ -49,14 +43,12 @@ module.exports = class txProviderUtils {
// use original specified amount
if (txMeta.gasLimitSpecified) {
txMeta.estimatedGas = txParams.gas
- cb()
return
}
// if gasLimit not originally specified,
// try adding an additional gas buffer to our estimation for safety
const recommendedGasHex = this.addGasBuffer(txMeta.estimatedGas, blockGasLimitHex)
txParams.gas = recommendedGasHex
- cb()
return
}
@@ -74,22 +66,6 @@ module.exports = class txProviderUtils {
return bnToHex(upperGasLimitBn)
}
- fillInTxParams (txParams, cb) {
- const fromAddress = txParams.from
- const reqs = {}
-
- if (isUndef(txParams.gas)) reqs.gas = (cb) => this.query.estimateGas(txParams, cb)
- if (isUndef(txParams.gasPrice)) reqs.gasPrice = (cb) => this.query.gasPrice(cb)
- if (isUndef(txParams.nonce)) reqs.nonce = (cb) => this.query.getTransactionCount(fromAddress, 'pending', cb)
-
- async.parallel(reqs, function (err, result) {
- if (err) return cb(err)
- // write results to txParams obj
- Object.assign(txParams, result)
- cb()
- })
- }
-
// builds ethTx from txParams object
buildEthTxFromParams (txParams) {
// normalize values
@@ -106,20 +82,13 @@ module.exports = class txProviderUtils {
return ethTx
}
- publishTransaction (rawTx) {
- return new Promise((resolve, reject) => {
- this.query.sendRawTransaction(rawTx, (err, ress) => {
- if (err) reject(err)
- else resolve(ress)
- })
- })
+ async publishTransaction (rawTx) {
+ return await this.query.sendRawTransaction(rawTx)
}
- validateTxParams (txParams, cb) {
+ async validateTxParams (txParams) {
if (('value' in txParams) && txParams.value.indexOf('-') === 0) {
- cb(new Error(`Invalid transaction value of ${txParams.value} not a positive number.`))
- } else {
- cb()
+ throw new Error(`Invalid transaction value of ${txParams.value} not a positive number.`)
}
}
@@ -137,10 +106,6 @@ module.exports = class txProviderUtils {
// util
-function isUndef (value) {
- return value === undefined
-}
-
function bnToHex (inputBn) {
return ethUtil.addHexPrefix(inputBn.toString(16))
}
diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js
index 6d6cb85ab..a007d6fc5 100644
--- a/app/scripts/metamask-controller.js
+++ b/app/scripts/metamask-controller.js
@@ -113,6 +113,7 @@ module.exports = class MetamaskController extends EventEmitter {
ethQuery: this.ethQuery,
ethStore: this.ethStore,
})
+ this.txController.on('newUnaprovedTx', opts.showUnapprovedTx.bind(opts))
// notices
this.noticeController = new NoticeController({
@@ -203,7 +204,7 @@ module.exports = class MetamaskController extends EventEmitter {
cb(null, result)
},
// tx signing
- processTransaction: (txParams, cb) => this.newUnapprovedTransaction(txParams, cb),
+ processTransaction: nodeify(async (txParams) => await this.txController.newUnapprovedTransaction(txParams), this),
// old style msg signing
processMessage: this.newUnsignedMessage.bind(this),
@@ -316,7 +317,7 @@ module.exports = class MetamaskController extends EventEmitter {
exportAccount: nodeify(keyringController.exportAccount, keyringController),
// txController
- cancelTransaction: txController.cancelTransaction.bind(txController),
+ cancelTransaction: nodeify(txController.cancelTransaction, txController),
updateAndApproveTransaction: nodeify(txController.updateAndApproveTransaction, txController),
// messageManager
@@ -461,27 +462,6 @@ module.exports = class MetamaskController extends EventEmitter {
// Identity Management
//
- newUnapprovedTransaction (txParams, cb) {
- log.debug(`MetaMaskController newUnapprovedTransaction ${JSON.stringify(txParams)}`)
- const self = this
- self.txController.addUnapprovedTransaction(txParams, (err, txMeta) => {
- if (err) return cb(err)
- self.sendUpdate()
- self.opts.showUnapprovedTx(txMeta)
- // listen for tx completion (success, fail)
- self.txController.once(`${txMeta.id}:finished`, (completedTx) => {
- switch (completedTx.status) {
- case 'submitted':
- return cb(null, completedTx.hash)
- case 'rejected':
- return cb(new Error('MetaMask Tx Signature: User denied transaction signature.'))
- default:
- return cb(new Error(`MetaMask Tx Signature: Unknown problem: ${JSON.stringify(completedTx.txParams)}`))
- }
- })
- })
- }
-
newUnsignedMessage (msgParams, cb) {
const msgId = this.messageManager.addUnapprovedMessage(msgParams)
this.sendUpdate()
@@ -667,6 +647,4 @@ module.exports = class MetamaskController extends EventEmitter {
return Promise.resolve(rpcTarget)
})
}
-
-
-}
+} \ No newline at end of file