mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 01:39:44 +01:00
Clear notices when setCompletedOnboarding is called
This commit is contained in:
parent
fc534b8041
commit
c43374a553
@ -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),
|
||||
|
@ -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()
|
||||
|
@ -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 = [
|
||||
|
@ -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
|
||||
|
||||
|
@ -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()
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user