aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkumavis <aaron@kumavis.me>2019-03-29 12:03:31 +0800
committerkumavis <aaron@kumavis.me>2019-03-29 12:03:31 +0800
commita64855ef4940f1a409b4a168a60d0f5f06836086 (patch)
tree1953d4de8cc4352e8122c971ee9a3f8337f4aab4
parent781a39c039500fcfe8fce3c3d75081ff781c4cf1 (diff)
downloadtangerine-wallet-browser-a64855ef4940f1a409b4a168a60d0f5f06836086.tar.gz
tangerine-wallet-browser-a64855ef4940f1a409b4a168a60d0f5f06836086.tar.zst
tangerine-wallet-browser-a64855ef4940f1a409b4a168a60d0f5f06836086.zip
notices - markAllNoticesRead - use async/await
-rw-r--r--app/scripts/metamask-controller.js2
-rw-r--r--app/scripts/notice-controller.js23
-rw-r--r--test/unit/app/controllers/notice-controller-test.js5
-rw-r--r--test/unit/ui/app/actions.spec.js11
4 files changed, 16 insertions, 25 deletions
diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js
index ce59caf83..058d527c0 100644
--- a/app/scripts/metamask-controller.js
+++ b/app/scripts/metamask-controller.js
@@ -473,7 +473,7 @@ module.exports = class MetamaskController extends EventEmitter {
// notices
checkNotices: noticeController.updateNoticesList.bind(noticeController),
markNoticeRead: noticeController.markNoticeRead.bind(noticeController),
- markAllNoticesRead: noticeController.markAllNoticesRead.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 d1a15ff08..050fca9c8 100644
--- a/app/scripts/notice-controller.js
+++ b/app/scripts/notice-controller.js
@@ -58,20 +58,15 @@ module.exports = class NoticeController extends EventEmitter {
}
}
- markAllNoticesRead (cb) {
- cb = cb || function (err) { if (err) throw err }
- try {
- const noticeList = this.getNoticesList()
- noticeList.forEach(notice => {
- notice.read = true
- notice.body = ''
- })
- this.setNoticesList(noticeList)
- const latestNotice = this.getNextUnreadNotice()
- cb(null, latestNotice)
- } catch (err) {
- cb(err)
- }
+ async markAllNoticesRead () {
+ const noticeList = this.getNoticesList()
+ noticeList.forEach(notice => {
+ notice.read = true
+ notice.body = ''
+ })
+ this.setNoticesList(noticeList)
+ const latestNotice = this.getNextUnreadNotice()
+ return latestNotice
}
diff --git a/test/unit/app/controllers/notice-controller-test.js b/test/unit/app/controllers/notice-controller-test.js
index 95e3ea9bd..d550d86cd 100644
--- a/test/unit/app/controllers/notice-controller-test.js
+++ b/test/unit/app/controllers/notice-controller-test.js
@@ -40,7 +40,7 @@ describe('notice-controller', function () {
})
describe('#markAllNoticesRead', () => {
- it('marks all notices read', (done) => {
+ it('marks all notices read', async () => {
const testList = [{
id: 0,
read: false,
@@ -57,11 +57,10 @@ describe('notice-controller', function () {
noticeController.setNoticesList(testList)
- noticeController.markAllNoticesRead()
+ await noticeController.markAllNoticesRead()
const unreadNotices = noticeController.getUnreadNotices()
assert.equal(unreadNotices.length, 0)
- done()
})
})
diff --git a/test/unit/ui/app/actions.spec.js b/test/unit/ui/app/actions.spec.js
index d395c9adb..a3b979d75 100644
--- a/test/unit/ui/app/actions.spec.js
+++ b/test/unit/ui/app/actions.spec.js
@@ -1321,14 +1321,11 @@ describe('Actions', () => {
completeOnboardingSpy.restore()
})
- it('', (done) => {
+ it('completing onboarding marks all notices as read', async () => {
const store = mockStore()
- store.dispatch(actions.setCompletedOnboarding())
- .then(() => {
- assert.equal(markAllNoticesReadSpy.callCount, 1)
- assert.equal(completeOnboardingSpy.callCount, 1)
- })
- done()
+ await store.dispatch(actions.setCompletedOnboarding())
+ assert.equal(markAllNoticesReadSpy.callCount, 1)
+ assert.equal(completeOnboardingSpy.callCount, 1)
})
})