aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/scripts/metamask-controller.js1
-rw-r--r--app/scripts/notice-controller.js17
-rw-r--r--test/unit/app/controllers/notice-controller-test.js26
-rw-r--r--test/unit/ui/app/actions.spec.js24
-rw-r--r--ui/app/store/actions.js21
5 files changed, 85 insertions, 4 deletions
diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js
index 540aee936..ce59caf83 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: noticeController.markAllNoticesRead.bind(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..d1a15ff08 100644
--- a/app/scripts/notice-controller.js
+++ b/app/scripts/notice-controller.js
@@ -58,6 +58,23 @@ 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 updateNoticesList () {
const newNotices = await this._retrieveNoticeData()
const oldNotices = this.getNoticesList()
diff --git a/test/unit/app/controllers/notice-controller-test.js b/test/unit/app/controllers/notice-controller-test.js
index 834c88f7b..95e3ea9bd 100644
--- a/test/unit/app/controllers/notice-controller-test.js
+++ b/test/unit/app/controllers/notice-controller-test.js
@@ -39,6 +39,32 @@ describe('notice-controller', function () {
})
})
+ describe('#markAllNoticesRead', () => {
+ it('marks all notices read', (done) => {
+ const testList = [{
+ id: 0,
+ read: false,
+ title: 'Notice 1',
+ }, {
+ id: 1,
+ read: false,
+ title: 'Notice 2',
+ }, {
+ id: 2,
+ read: false,
+ title: 'Notice 3',
+ }]
+
+ noticeController.setNoticesList(testList)
+
+ noticeController.markAllNoticesRead()
+
+ const unreadNotices = noticeController.getUnreadNotices()
+ assert.equal(unreadNotices.length, 0)
+ done()
+ })
+ })
+
describe('#getNextUnreadNotice', function () {
it('should retrieve the latest unread notice', function (done) {
var testList = [
diff --git a/test/unit/ui/app/actions.spec.js b/test/unit/ui/app/actions.spec.js
index 46e94bb32..d395c9adb 100644
--- a/test/unit/ui/app/actions.spec.js
+++ b/test/unit/ui/app/actions.spec.js
@@ -1308,6 +1308,30 @@ describe('Actions', () => {
})
})
+ describe('#setCompletedOnboarding', () => {
+ let markAllNoticesReadSpy, completeOnboardingSpy
+
+ beforeEach(() => {
+ markAllNoticesReadSpy = sinon.stub(background, 'markAllNoticesRead')
+ completeOnboardingSpy = sinon.stub(background, 'completeOnboarding')
+ })
+
+ after(() => {
+ markAllNoticesReadSpy.restore()
+ completeOnboardingSpy.restore()
+ })
+
+ it('', (done) => {
+ const store = mockStore()
+ store.dispatch(actions.setCompletedOnboarding())
+ .then(() => {
+ assert.equal(markAllNoticesReadSpy.callCount, 1)
+ assert.equal(completeOnboardingSpy.callCount, 1)
+ })
+ done()
+ })
+ })
+
describe('#updateNetworkNonce', () => {
let getTransactionCountSpy
diff --git a/ui/app/store/actions.js b/ui/app/store/actions.js
index b2aa28c93..785cadc3c 100644
--- a/ui/app/store/actions.js
+++ b/ui/app/store/actions.js
@@ -2491,16 +2491,29 @@ function setCompletedOnboarding () {
return dispatch => {
dispatch(actions.showLoadingIndication())
return new Promise((resolve, reject) => {
- background.completeOnboarding(err => {
- dispatch(actions.hideLoadingIndication())
+ background.markAllNoticesRead(err => {
if (err) {
dispatch(actions.displayWarning(err.message))
return reject(err)
}
- dispatch(actions.completeOnboarding())
- resolve()
+ dispatch(actions.clearNotices())
+ resolve(false)
+ })
+ })
+ .then(() => {
+ return new Promise((resolve, reject) => {
+ background.completeOnboarding(err => {
+ if (err) {
+ dispatch(actions.displayWarning(err.message))
+ return reject(err)
+ }
+
+ dispatch(actions.completeOnboarding())
+ dispatch(actions.hideLoadingIndication())
+ resolve()
+ })
})
})
}