aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/scripts/background.js11
-rw-r--r--app/scripts/transaction-manager.js30
2 files changed, 31 insertions, 10 deletions
diff --git a/app/scripts/background.js b/app/scripts/background.js
index 854b679da..f476e89e4 100644
--- a/app/scripts/background.js
+++ b/app/scripts/background.js
@@ -115,18 +115,11 @@ function updateBadge () {
// txManger :: tx approvals and rejection cb's
txManager.on('signed', function (txId) {
- var approvalCb = this._unconfTxCbs[txId]
-
- approvalCb(null, true)
- // clean up
- delete this._unconfTxCbs[txId]
+ this.execOnTxDoneCb(txId, true)
})
txManager.on('rejected', function (txId) {
- var approvalCb = this._unconfTxCbs[txId]
- approvalCb(null, false)
- // clean up
- delete this._unconfTxCbs[txId]
+ this.execOnTxDoneCb(txId, false)
})
// data :: setters/getters
diff --git a/app/scripts/transaction-manager.js b/app/scripts/transaction-manager.js
index 07e588679..d0226a600 100644
--- a/app/scripts/transaction-manager.js
+++ b/app/scripts/transaction-manager.js
@@ -38,12 +38,14 @@ module.exports = class TransactionManager extends EventEmitter {
this.emit('update')
}
+ // gets tx by Id and returns it
getTx (txId, cb) {
var txList = this.getTxList()
var tx = txList.find((tx) => tx.id === txId)
return cb ? cb(tx) : tx
}
+ //
updateTx (txData) {
var txId = txData.id
var txList = this.getTxList()
@@ -75,6 +77,21 @@ module.exports = class TransactionManager extends EventEmitter {
}, {})
}
+ /*
+ Takes an object of fields to search for eg:
+ var thingsToLookFor = {
+ to: '0x0..',
+ from: '0x0..',
+ status: 'signed',
+ }
+ and returns a list of tx with all
+ options matching
+
+ this is for things like filtering a the tx list
+ for only tx's from 1 account
+ or for filltering for all txs from one account
+ and that have been 'confirmed'
+ */
getFilterdTxList (opts) {
var filteredTxList
Object.keys(opts).forEach((key) => {
@@ -93,10 +110,19 @@ module.exports = class TransactionManager extends EventEmitter {
})
}
+// keeps around the txCbs for later
addOnTxDoneCb (txId, cb) {
this._unconfTxCbs[txId] = cb || noop
}
+ execOnTxDoneCb (txId, conf) {
+ var approvalCb = this._unconfTxCbs[txId]
+
+ approvalCb(null, conf)
+ // clean up
+ delete this._unconfTxCbs[txId]
+ }
+
// should return the tx
// Should find the tx in the tx list and
@@ -136,7 +162,6 @@ module.exports = class TransactionManager extends EventEmitter {
setTxStatusConfirmed (txId) {
this.setTxStatus(txId, 'confirmed')
- // this.removeListener(`check${txId}`, this.checkForTxInBlock)
}
// merges txParams obj onto txData.txParams
@@ -147,12 +172,15 @@ module.exports = class TransactionManager extends EventEmitter {
this.updateTx(txData)
}
+ // sets provider for provider utils and event listener
setProvider (provider) {
this.provider = provider
this.txProviderUtils = new TxProviderUtil(provider)
this.provider.on('block', this.checkForTxInBlock.bind(this))
}
+ // checks if a signed tx is in a block and
+ // if included sets the tx status as 'confirmed'
checkForTxInBlock () {
var signedTxList = this.getFilterdTxList({status: 'signed'})
if (!signedTxList.length) return