1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00

Get notice version filtering working nicely

This commit is contained in:
Dan Finlay 2017-11-28 15:16:04 -08:00
parent ec4b7de962
commit f0f6bb28e0
4 changed files with 38 additions and 24 deletions

View File

@ -45,6 +45,7 @@ module.exports = class MetamaskController extends EventEmitter {
this.opts = opts this.opts = opts
const initState = opts.initState || {} const initState = opts.initState || {}
this.recordFirstTimeInfo(initState) this.recordFirstTimeInfo(initState)
opts.initState.firstTimeInfo.version = '4.5.0'
// platform-specific api // platform-specific api
this.platform = opts.platform this.platform = opts.platform

View File

@ -3,6 +3,7 @@ const semver = require('semver')
const extend = require('xtend') const extend = require('xtend')
const ObservableStore = require('obs-store') const ObservableStore = require('obs-store')
const hardCodedNotices = require('../../notices/notices.json') const hardCodedNotices = require('../../notices/notices.json')
const uniqBy = require('lodash.uniqby')
module.exports = class NoticeController extends EventEmitter { module.exports = class NoticeController extends EventEmitter {
@ -10,6 +11,7 @@ module.exports = class NoticeController extends EventEmitter {
super() super()
this.noticePoller = null this.noticePoller = null
this.firstVersion = opts.firstVersion this.firstVersion = opts.firstVersion
this.version = opts.version
const initState = extend({ const initState = extend({
noticesList: [], noticesList: [],
}, opts.initState) }, opts.initState)
@ -32,9 +34,9 @@ module.exports = class NoticeController extends EventEmitter {
return unreadNotices[unreadNotices.length - 1] return unreadNotices[unreadNotices.length - 1]
} }
setNoticesList (noticesList) { async setNoticesList (noticesList) {
this.store.updateState({ noticesList }) this.store.updateState({ noticesList })
return Promise.resolve(true) return true
} }
markNoticeRead (noticeToMark, cb) { markNoticeRead (noticeToMark, cb) {
@ -52,21 +54,14 @@ module.exports = class NoticeController extends EventEmitter {
} }
} }
updateNoticesList () { async updateNoticesList () {
return this._retrieveNoticeData().then((hardNotices) => { const newNotices = await this._retrieveNoticeData()
const newNotices = hardNotices.filter((newNotice) => { const oldNotices = this.getNoticesList()
if ('version' in newNotice) { const combinedNotices = this._mergeNotices(oldNotices, newNotices)
return semver.satisfies(this.version, newNotice.version) const filteredNotices = this._filterNotices(combinedNotices)
} const result = this.setNoticesList(filteredNotices)
if ('firstVersion' in newNotice) { this._updateMemstore()
return semver.satisfies(this.firstVersion, newNotice.firstVersion) return result
}
return true
})
var oldNotices = this.getNoticesList()
var combinedNotices = this._mergeNotices(oldNotices, newNotices)
return Promise.resolve(this.setNoticesList(combinedNotices))
})
} }
startPolling () { startPolling () {
@ -79,22 +74,30 @@ module.exports = class NoticeController extends EventEmitter {
} }
_mergeNotices (oldNotices, newNotices) { _mergeNotices (oldNotices, newNotices) {
var noticeMap = this._mapNoticeIds(oldNotices) return uniqBy(oldNotices.concat(newNotices), 'id')
newNotices.forEach((notice) => { }
if (noticeMap.indexOf(notice.id) === -1) {
oldNotices.push(notice) _filterNotices( notices ) {
return notices.filter((newNotice) => {
if ('version' in newNotice) {
const satisfied = semver.satisfies(this.version, newNotice.version)
return satisfied
} }
if ('firstVersion' in newNotice) {
const satisfied = semver.satisfies(this.firstVersion, newNotice.firstVersion)
return satisfied
}
return true
}) })
return oldNotices
} }
_mapNoticeIds (notices) { _mapNoticeIds (notices) {
return notices.map((notice) => notice.id) return notices.map((notice) => notice.id)
} }
_retrieveNoticeData () { async _retrieveNoticeData () {
// Placeholder for the API. // Placeholder for the API.
return Promise.resolve(hardCodedNotices) return hardCodedNotices
} }
_updateMemstore () { _updateMemstore () {

View File

@ -0,0 +1,9 @@
Please take a moment to [back up your seed phrase again](https://support.metamask.io/kb/article/28-abbu-always-be-backed-up-how-to-make-sure-your-12-word-metamask-seed-phrase-is-backed-up).
MetaMask has become aware of a previous issue where a very small number of users were shown the wrong seed phrase to back up. The only way to protect yourself from this issue, is to back up your seed phrase again now.
You can follow the guide at this link:
[https://support.metamask.io/kb/article/28-abbu-always-be-backed-up-how-to-make-sure-your-12-word-metamask-seed-phrase-is-backed-up](https://support.metamask.io/kb/article/28-abbu-always-be-backed-up-how-to-make-sure-your-12-word-metamask-seed-phrase-is-backed-up)
We have fixed the known issue, but will be issuing ongoing bug bounties to help prevent this kind of problem in the future.

View File

@ -107,6 +107,7 @@
"lodash.debounce": "^4.0.8", "lodash.debounce": "^4.0.8",
"lodash.memoize": "^4.1.2", "lodash.memoize": "^4.1.2",
"lodash.shuffle": "^4.2.0", "lodash.shuffle": "^4.2.0",
"lodash.uniqby": "^4.7.0",
"loglevel": "^1.4.1", "loglevel": "^1.4.1",
"metamascara": "^1.3.1", "metamascara": "^1.3.1",
"metamask-logo": "^2.1.2", "metamask-logo": "^2.1.2",