aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Huang <thomas.b.huang@gmail.com>2019-03-21 09:26:48 +0800
committerThomas Huang <thomas.b.huang@gmail.com>2019-03-21 09:26:48 +0800
commitc43374a553c28459be4cac116a72a4f34dddba72 (patch)
treee7584d60bf8617b742cdd09485f029e4d92f336d
parentfc534b8041bbf69f3f7f8384554934d68a081835 (diff)
downloadtangerine-wallet-browser-c43374a553c28459be4cac116a72a4f34dddba72.tar
tangerine-wallet-browser-c43374a553c28459be4cac116a72a4f34dddba72.tar.gz
tangerine-wallet-browser-c43374a553c28459be4cac116a72a4f34dddba72.tar.bz2
tangerine-wallet-browser-c43374a553c28459be4cac116a72a4f34dddba72.tar.lz
tangerine-wallet-browser-c43374a553c28459be4cac116a72a4f34dddba72.tar.xz
tangerine-wallet-browser-c43374a553c28459be4cac116a72a4f34dddba72.tar.zst
tangerine-wallet-browser-c43374a553c28459be4cac116a72a4f34dddba72.zip
Clear notices when setCompletedOnboarding is called
-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/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 8d7de8b02..d27521088 100644
--- a/test/unit/ui/app/actions.spec.js
+++ b/test/unit/ui/app/actions.spec.js
@@ -1308,6 +1308,30 @@ describe('Actions', () => {
})
})
+ describe.only('#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/actions.js b/ui/app/actions.js
index d8363eba6..65070fc8c 100644
--- a/ui/app/actions.js
+++ b/ui/app/actions.js
@@ -2487,16 +2487,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()
+ })
})
})
}