aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Finlay <dan@danfinlay.com>2017-11-29 03:14:57 +0800
committerDan Finlay <dan@danfinlay.com>2017-11-29 03:14:57 +0800
commite89f82399f1c732c40dc644c496795833691cff0 (patch)
treee2d2490157ace55771dc59e8637143e544f80c30
parent4d6bae774a22487f9861225e6fc00a73829a51ee (diff)
downloadtangerine-wallet-browser-e89f82399f1c732c40dc644c496795833691cff0.tar
tangerine-wallet-browser-e89f82399f1c732c40dc644c496795833691cff0.tar.gz
tangerine-wallet-browser-e89f82399f1c732c40dc644c496795833691cff0.tar.bz2
tangerine-wallet-browser-e89f82399f1c732c40dc644c496795833691cff0.tar.lz
tangerine-wallet-browser-e89f82399f1c732c40dc644c496795833691cff0.tar.xz
tangerine-wallet-browser-e89f82399f1c732c40dc644c496795833691cff0.tar.zst
tangerine-wallet-browser-e89f82399f1c732c40dc644c496795833691cff0.zip
Add optional version field to notices
Allows notices to only show to users who are on a certain version.
-rw-r--r--app/scripts/metamask-controller.js11
-rw-r--r--app/scripts/notice-controller.js10
-rw-r--r--package.json1
3 files changed, 21 insertions, 1 deletions
diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js
index a4c77e468..c1b63449a 100644
--- a/app/scripts/metamask-controller.js
+++ b/app/scripts/metamask-controller.js
@@ -44,6 +44,7 @@ module.exports = class MetamaskController extends EventEmitter {
this.opts = opts
const initState = opts.initState || {}
+ this.recordFirstTimeInfo(initState)
// platform-specific api
this.platform = opts.platform
@@ -149,6 +150,7 @@ module.exports = class MetamaskController extends EventEmitter {
// notices
this.noticeController = new NoticeController({
initState: initState.NoticeController,
+ version,
})
this.noticeController.updateNoticesList()
// to be uncommented when retrieving notices from a remote server.
@@ -797,4 +799,13 @@ module.exports = class MetamaskController extends EventEmitter {
return rpcTarget
}
+ recordFirstTimeInfo (initState) {
+ if (!('firstTimeInfo' in initState)) {
+ initState.firstTimeInfo = {
+ version,
+ date: Date.now(),
+ }
+ }
+ }
+
}
diff --git a/app/scripts/notice-controller.js b/app/scripts/notice-controller.js
index 57aad40c5..bc545127e 100644
--- a/app/scripts/notice-controller.js
+++ b/app/scripts/notice-controller.js
@@ -1,4 +1,5 @@
const EventEmitter = require('events').EventEmitter
+const semver = require('semver')
const extend = require('xtend')
const ObservableStore = require('obs-store')
const hardCodedNotices = require('../../notices/notices.json')
@@ -8,6 +9,7 @@ module.exports = class NoticeController extends EventEmitter {
constructor (opts) {
super()
this.noticePoller = null
+ this.version = opts.version
const initState = extend({
noticesList: [],
}, opts.initState)
@@ -51,7 +53,13 @@ module.exports = class NoticeController extends EventEmitter {
}
updateNoticesList () {
- return this._retrieveNoticeData().then((newNotices) => {
+ return this._retrieveNoticeData().then((hardNotices) => {
+ const newNotices = hardNotices.filter((newNotice) => {
+ if ('version' in newNotice) {
+ return semver.satisfies(this.version, newNotice.version)
+ }
+ return true
+ })
var oldNotices = this.getNoticesList()
var combinedNotices = this._mergeNotices(oldNotices, newNotices)
return Promise.resolve(this.setNoticesList(combinedNotices))
diff --git a/package.json b/package.json
index 941707de1..1d04271e7 100644
--- a/package.json
+++ b/package.json
@@ -144,6 +144,7 @@
"request-promise": "^4.2.1",
"sandwich-expando": "^1.1.3",
"semaphore": "^1.0.5",
+ "semver": "^5.4.1",
"sw-stream": "^2.0.0",
"textarea-caret": "^3.0.1",
"through2": "^2.0.3",