1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-30 08:09:15 +01:00
This commit is contained in:
Kevin Serrano 2016-12-20 16:45:22 -08:00
parent 572980402d
commit aea263a80d
No known key found for this signature in database
GPG Key ID: 7CC862A58D2889B4
2 changed files with 12 additions and 12 deletions

View File

@ -9,7 +9,7 @@ module.exports = class NoticeController extends EventEmitter {
this.noticePoller = null this.noticePoller = null
} }
getState() { getState () {
var lastUnreadNotice = this.getLatestUnreadNotice() var lastUnreadNotice = this.getLatestUnreadNotice()
return { return {
@ -18,7 +18,7 @@ module.exports = class NoticeController extends EventEmitter {
} }
} }
getNoticesList() { getNoticesList () {
var data = this.configManager.getData() var data = this.configManager.getData()
if ('noticesList' in data) { if ('noticesList' in data) {
return data.noticesList return data.noticesList
@ -27,28 +27,28 @@ module.exports = class NoticeController extends EventEmitter {
} }
} }
setNoticesList(list) { setNoticesList (list) {
var data = this.configManager.getData() var data = this.configManager.getData()
data.noticesList = list data.noticesList = list
this.configManager.setData(data) this.configManager.setData(data)
return Promise.resolve(true) return Promise.resolve(true)
} }
markNoticeRead(notice, cb) { markNoticeRead (notice, cb) {
cb = cb || function(err){ if (err) throw err } cb = cb || function (err) { if (err) throw err }
try { try {
var notices = this.getNoticesList() var notices = this.getNoticesList()
var id = notice.id var id = notice.id
notices[id].read = true notices[id].read = true
this.setNoticesList(notices) this.setNoticesList(notices)
let latestNotice = this.getLatestUnreadNotice() const latestNotice = this.getLatestUnreadNotice()
cb(null, latestNotice) cb(null, latestNotice)
} catch (err) { } catch (err) {
cb(err) cb(err)
} }
} }
updateNoticesList() { updateNoticesList () {
return this._retrieveNoticeData().then((newNotices) => { return this._retrieveNoticeData().then((newNotices) => {
var oldNotices = this.getNoticesList() var oldNotices = this.getNoticesList()
var combinedNotices = this._mergeNotices(oldNotices, newNotices) var combinedNotices = this._mergeNotices(oldNotices, newNotices)
@ -56,7 +56,7 @@ module.exports = class NoticeController extends EventEmitter {
}) })
} }
getLatestUnreadNotice() { getLatestUnreadNotice () {
var notices = this.getNoticesList() var notices = this.getNoticesList()
var filteredNotices = notices.filter((notice) => { var filteredNotices = notices.filter((notice) => {
return notice.read === false return notice.read === false
@ -73,7 +73,7 @@ module.exports = class NoticeController extends EventEmitter {
}, 300000) }, 300000)
} }
_mergeNotices(oldNotices, newNotices) { _mergeNotices (oldNotices, newNotices) {
var noticeMap = this._mapNoticeIds(oldNotices) var noticeMap = this._mapNoticeIds(oldNotices)
newNotices.forEach((notice) => { newNotices.forEach((notice) => {
if (noticeMap.indexOf(notice.id) === -1) { if (noticeMap.indexOf(notice.id) === -1) {
@ -83,11 +83,11 @@ module.exports = class NoticeController extends EventEmitter {
return oldNotices return oldNotices
} }
_mapNoticeIds(notices) { _mapNoticeIds (notices) {
return notices.map((notice) => notice.id) return notices.map((notice) => notice.id)
} }
_retrieveNoticeData() { _retrieveNoticeData () {
// Placeholder for the API. // Placeholder for the API.
return Promise.resolve(hardCodedNotices) return Promise.resolve(hardCodedNotices)
} }

View File

@ -10,7 +10,7 @@ module.exports = connect(mapStateToProps)(ConfigScreen)
function mapStateToProps (state) { function mapStateToProps (state) {
return { return {
metamask: state.metamask, metamask: state.metamask,
warning: state.appState.warning warning: state.appState.warning,
} }
} }