aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/scripts/lib/nodeify.js3
-rw-r--r--test/unit/actions/tx_test.js10
-rw-r--r--test/unit/nodeify-test.js11
-rw-r--r--ui/app/actions.js9
4 files changed, 25 insertions, 8 deletions
diff --git a/app/scripts/lib/nodeify.js b/app/scripts/lib/nodeify.js
index 299bfe624..832d6c6d3 100644
--- a/app/scripts/lib/nodeify.js
+++ b/app/scripts/lib/nodeify.js
@@ -1,9 +1,10 @@
const promiseToCallback = require('promise-to-callback')
-module.exports = function(fn, context) {
+module.exports = function nodeify (fn, context) {
return function(){
const args = [].slice.call(arguments)
const callback = args.pop()
+ if (typeof callback !== 'function') throw new Error('callback is not a function')
promiseToCallback(fn.apply(context, args))(callback)
}
}
diff --git a/test/unit/actions/tx_test.js b/test/unit/actions/tx_test.js
index 0ea1bfdc7..67c72e9a5 100644
--- a/test/unit/actions/tx_test.js
+++ b/test/unit/actions/tx_test.js
@@ -45,13 +45,15 @@ describe('tx confirmation screen', function () {
before(function (done) {
actions._setBackgroundConnection({
approveTransaction (txId, cb) { cb('An error!') },
- cancelTransaction (txId) { /* noop */ },
+ cancelTransaction (txId, cb) { cb() },
clearSeedWordCache (cb) { cb() },
})
- const action = actions.cancelTx({value: firstTxId})
- result = reducers(initialState, action)
- done()
+ actions.cancelTx({value: firstTxId})((action) => {
+ result = reducers(initialState, action)
+ done()
+ })
+
})
it('should transition to the account detail view', function () {
diff --git a/test/unit/nodeify-test.js b/test/unit/nodeify-test.js
index 06241334d..537dae605 100644
--- a/test/unit/nodeify-test.js
+++ b/test/unit/nodeify-test.js
@@ -17,4 +17,15 @@ describe('nodeify', function () {
done()
})
})
+
+ it('should throw if the last argument is not a function', function (done) {
+ const nodified = nodeify(obj.promiseFunc, obj)
+ try {
+ nodified('baz')
+ done(new Error('should have thrown if the last argument is not a function'))
+ } catch (err) {
+ assert.equal(err.message, 'callback is not a function')
+ done()
+ }
+ })
})
diff --git a/ui/app/actions.js b/ui/app/actions.js
index d99291e46..8ff8bbbdd 100644
--- a/ui/app/actions.js
+++ b/ui/app/actions.js
@@ -462,9 +462,12 @@ function cancelPersonalMsg (msgData) {
}
function cancelTx (txData) {
- log.debug(`background.cancelTransaction`)
- background.cancelTransaction(txData.id)
- return actions.completedTx(txData.id)
+ return (dispatch) => {
+ log.debug(`background.cancelTransaction`)
+ background.cancelTransaction(txData.id, () => {
+ dispatch(actions.completedTx(txData.id))
+ })
+ }
}
//