mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
notices - markAllNoticesRead - use async/await
This commit is contained in:
parent
781a39c039
commit
a64855ef49
@ -473,7 +473,7 @@ module.exports = class MetamaskController extends EventEmitter {
|
|||||||
// notices
|
// notices
|
||||||
checkNotices: noticeController.updateNoticesList.bind(noticeController),
|
checkNotices: noticeController.updateNoticesList.bind(noticeController),
|
||||||
markNoticeRead: noticeController.markNoticeRead.bind(noticeController),
|
markNoticeRead: noticeController.markNoticeRead.bind(noticeController),
|
||||||
markAllNoticesRead: noticeController.markAllNoticesRead.bind(noticeController),
|
markAllNoticesRead: nodeify(noticeController.markAllNoticesRead, noticeController),
|
||||||
|
|
||||||
approveProviderRequest: providerApprovalController.approveProviderRequest.bind(providerApprovalController),
|
approveProviderRequest: providerApprovalController.approveProviderRequest.bind(providerApprovalController),
|
||||||
clearApprovedOrigins: providerApprovalController.clearApprovedOrigins.bind(providerApprovalController),
|
clearApprovedOrigins: providerApprovalController.clearApprovedOrigins.bind(providerApprovalController),
|
||||||
|
@ -58,20 +58,15 @@ module.exports = class NoticeController extends EventEmitter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
markAllNoticesRead (cb) {
|
async markAllNoticesRead () {
|
||||||
cb = cb || function (err) { if (err) throw err }
|
const noticeList = this.getNoticesList()
|
||||||
try {
|
noticeList.forEach(notice => {
|
||||||
const noticeList = this.getNoticesList()
|
notice.read = true
|
||||||
noticeList.forEach(notice => {
|
notice.body = ''
|
||||||
notice.read = true
|
})
|
||||||
notice.body = ''
|
this.setNoticesList(noticeList)
|
||||||
})
|
const latestNotice = this.getNextUnreadNotice()
|
||||||
this.setNoticesList(noticeList)
|
return latestNotice
|
||||||
const latestNotice = this.getNextUnreadNotice()
|
|
||||||
cb(null, latestNotice)
|
|
||||||
} catch (err) {
|
|
||||||
cb(err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -40,7 +40,7 @@ describe('notice-controller', function () {
|
|||||||
})
|
})
|
||||||
|
|
||||||
describe('#markAllNoticesRead', () => {
|
describe('#markAllNoticesRead', () => {
|
||||||
it('marks all notices read', (done) => {
|
it('marks all notices read', async () => {
|
||||||
const testList = [{
|
const testList = [{
|
||||||
id: 0,
|
id: 0,
|
||||||
read: false,
|
read: false,
|
||||||
@ -57,11 +57,10 @@ describe('notice-controller', function () {
|
|||||||
|
|
||||||
noticeController.setNoticesList(testList)
|
noticeController.setNoticesList(testList)
|
||||||
|
|
||||||
noticeController.markAllNoticesRead()
|
await noticeController.markAllNoticesRead()
|
||||||
|
|
||||||
const unreadNotices = noticeController.getUnreadNotices()
|
const unreadNotices = noticeController.getUnreadNotices()
|
||||||
assert.equal(unreadNotices.length, 0)
|
assert.equal(unreadNotices.length, 0)
|
||||||
done()
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -1321,14 +1321,11 @@ describe('Actions', () => {
|
|||||||
completeOnboardingSpy.restore()
|
completeOnboardingSpy.restore()
|
||||||
})
|
})
|
||||||
|
|
||||||
it('', (done) => {
|
it('completing onboarding marks all notices as read', async () => {
|
||||||
const store = mockStore()
|
const store = mockStore()
|
||||||
store.dispatch(actions.setCompletedOnboarding())
|
await store.dispatch(actions.setCompletedOnboarding())
|
||||||
.then(() => {
|
assert.equal(markAllNoticesReadSpy.callCount, 1)
|
||||||
assert.equal(markAllNoticesReadSpy.callCount, 1)
|
assert.equal(completeOnboardingSpy.callCount, 1)
|
||||||
assert.equal(completeOnboardingSpy.callCount, 1)
|
|
||||||
})
|
|
||||||
done()
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user