aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts
diff options
context:
space:
mode:
authorkumavis <kumavis@users.noreply.github.com>2019-03-29 14:23:02 +0800
committerGitHub <noreply@github.com>2019-03-29 14:23:02 +0800
commitc3a605f27a846b72227237cefa6e4590c8a3b2c1 (patch)
tree6dfc14e35e25ae47b04a331d8d8ccb0bc4341c64 /app/scripts
parent133ed80aeeeea4e2b0e9f1acb532f5d66f2575ca (diff)
parented381f5b2a3a85d351248769b3d150742acb703b (diff)
downloadtangerine-wallet-browser-c3a605f27a846b72227237cefa6e4590c8a3b2c1.tar
tangerine-wallet-browser-c3a605f27a846b72227237cefa6e4590c8a3b2c1.tar.gz
tangerine-wallet-browser-c3a605f27a846b72227237cefa6e4590c8a3b2c1.tar.bz2
tangerine-wallet-browser-c3a605f27a846b72227237cefa6e4590c8a3b2c1.tar.lz
tangerine-wallet-browser-c3a605f27a846b72227237cefa6e4590c8a3b2c1.tar.xz
tangerine-wallet-browser-c3a605f27a846b72227237cefa6e4590c8a3b2c1.tar.zst
tangerine-wallet-browser-c3a605f27a846b72227237cefa6e4590c8a3b2c1.zip
Merge pull request #6328 from MetaMask/clearNotices
Clear notices
Diffstat (limited to 'app/scripts')
-rw-r--r--app/scripts/lib/nodeify.js15
-rw-r--r--app/scripts/metamask-controller.js1
-rw-r--r--app/scripts/notice-controller.js12
3 files changed, 25 insertions, 3 deletions
diff --git a/app/scripts/lib/nodeify.js b/app/scripts/lib/nodeify.js
index 25be6537b..a813ae679 100644
--- a/app/scripts/lib/nodeify.js
+++ b/app/scripts/lib/nodeify.js
@@ -1,5 +1,5 @@
const promiseToCallback = require('promise-to-callback')
-const noop = function () {}
+const callbackNoop = function (err) { if (err) throw err }
/**
* A generator that returns a function which, when passed a promise, can treat that promise as a node style callback.
@@ -11,6 +11,7 @@ const noop = function () {}
*/
module.exports = function nodeify (fn, context) {
return function () {
+ // parse arguments
const args = [].slice.call(arguments)
const lastArg = args[args.length - 1]
const lastArgIsCallback = typeof lastArg === 'function'
@@ -19,8 +20,16 @@ module.exports = function nodeify (fn, context) {
callback = lastArg
args.pop()
} else {
- callback = noop
+ callback = callbackNoop
}
- promiseToCallback(fn.apply(context, args))(callback)
+ // call the provided function and ensure result is a promise
+ let result
+ try {
+ result = Promise.resolve(fn.apply(context, args))
+ } catch (err) {
+ result = Promise.reject(err)
+ }
+ // wire up promise resolution to callback
+ promiseToCallback(result)(callback)
}
}
diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js
index 540aee936..058d527c0 100644
--- a/app/scripts/metamask-controller.js
+++ b/app/scripts/metamask-controller.js
@@ -473,6 +473,7 @@ module.exports = class MetamaskController extends EventEmitter {
// notices
checkNotices: noticeController.updateNoticesList.bind(noticeController),
markNoticeRead: noticeController.markNoticeRead.bind(noticeController),
+ markAllNoticesRead: nodeify(noticeController.markAllNoticesRead, noticeController),
approveProviderRequest: providerApprovalController.approveProviderRequest.bind(providerApprovalController),
clearApprovedOrigins: providerApprovalController.clearApprovedOrigins.bind(providerApprovalController),
diff --git a/app/scripts/notice-controller.js b/app/scripts/notice-controller.js
index 6fe8b8cf0..63b422c5b 100644
--- a/app/scripts/notice-controller.js
+++ b/app/scripts/notice-controller.js
@@ -58,6 +58,18 @@ module.exports = class NoticeController extends EventEmitter {
}
}
+ markAllNoticesRead () {
+ const noticeList = this.getNoticesList()
+ noticeList.forEach(notice => {
+ notice.read = true
+ notice.body = ''
+ })
+ this.setNoticesList(noticeList)
+ const latestNotice = this.getNextUnreadNotice()
+ return latestNotice
+ }
+
+
async updateNoticesList () {
const newNotices = await this._retrieveNoticeData()
const oldNotices = this.getNoticesList()