aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorThomas Huang <tmashuang@users.noreply.github.com>2019-04-02 09:03:54 +0800
committerWhymarrh Whitby <whymarrh.whitby@gmail.com>2019-04-02 09:03:54 +0800
commita46ec83c9b258a3aed65e1ef08769300c01ca13b (patch)
treea48f7ddb8635ffbb024ff755d1865686c8a0ab27 /app
parent4055dc3475cb743e540766a8a8c704bb2b807502 (diff)
downloadtangerine-wallet-browser-a46ec83c9b258a3aed65e1ef08769300c01ca13b.tar
tangerine-wallet-browser-a46ec83c9b258a3aed65e1ef08769300c01ca13b.tar.gz
tangerine-wallet-browser-a46ec83c9b258a3aed65e1ef08769300c01ca13b.tar.bz2
tangerine-wallet-browser-a46ec83c9b258a3aed65e1ef08769300c01ca13b.tar.lz
tangerine-wallet-browser-a46ec83c9b258a3aed65e1ef08769300c01ca13b.tar.xz
tangerine-wallet-browser-a46ec83c9b258a3aed65e1ef08769300c01ca13b.tar.zst
tangerine-wallet-browser-a46ec83c9b258a3aed65e1ef08769300c01ca13b.zip
Remove NoticeController (#6382)
Diffstat (limited to 'app')
-rw-r--r--app/scripts/background.js1
-rw-r--r--app/scripts/metamask-controller.js16
-rw-r--r--app/scripts/migrations/033.js32
-rw-r--r--app/scripts/migrations/index.js2
-rw-r--r--app/scripts/notice-controller.js112
5 files changed, 34 insertions, 129 deletions
diff --git a/app/scripts/background.js b/app/scripts/background.js
index 7fea3c8c6..cca0d4709 100644
--- a/app/scripts/background.js
+++ b/app/scripts/background.js
@@ -106,7 +106,6 @@ setupMetamaskMeshMetrics()
* @property {string} rpcTarget - DEPRECATED - The URL of the current RPC provider.
* @property {Object} identities - An object matching lower-case hex addresses to Identity objects with "address" and "name" (nickname) keys.
* @property {Object} unapprovedTxs - An object mapping transaction hashes to unapproved transactions.
- * @property {boolean} noActiveNotices - False if there are notices the user should confirm before using the application.
* @property {Array} frequentRpcList - A list of frequently used RPCs, including custom user-provided ones.
* @property {Array} addressBook - A list of previously sent to addresses.
* @property {address} selectedTokenAddress - Used to indicate if a token is globally selected. Should be deprecated in favor of UI-centric token selection.
diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js
index 058d527c0..4108ed4c0 100644
--- a/app/scripts/metamask-controller.js
+++ b/app/scripts/metamask-controller.js
@@ -24,7 +24,6 @@ const KeyringController = require('eth-keyring-controller')
const NetworkController = require('./controllers/network')
const PreferencesController = require('./controllers/preferences')
const CurrencyController = require('./controllers/currency')
-const NoticeController = require('./notice-controller')
const ShapeShiftController = require('./controllers/shapeshift')
const InfuraController = require('./controllers/infura')
const BlacklistController = require('./controllers/blacklist')
@@ -211,13 +210,6 @@ module.exports = class MetamaskController extends EventEmitter {
})
this.balancesController.updateAllBalances()
- // notices
- this.noticeController = new NoticeController({
- initState: initState.NoticeController,
- version,
- firstVersion: initState.firstTimeInfo.version,
- })
-
this.shapeshiftController = new ShapeShiftController({
initState: initState.ShapeShiftController,
})
@@ -243,7 +235,6 @@ module.exports = class MetamaskController extends EventEmitter {
PreferencesController: this.preferencesController.store,
AddressBookController: this.addressBookController,
CurrencyController: this.currencyController.store,
- NoticeController: this.noticeController.store,
ShapeShiftController: this.shapeshiftController.store,
NetworkController: this.networkController.store,
InfuraController: this.infuraController.store,
@@ -265,7 +256,6 @@ module.exports = class MetamaskController extends EventEmitter {
RecentBlocksController: this.recentBlocksController.store,
AddressBookController: this.addressBookController,
CurrencyController: this.currencyController.store,
- NoticeController: this.noticeController.memStore,
ShapeshiftController: this.shapeshiftController.store,
InfuraController: this.infuraController.store,
ProviderApprovalController: this.providerApprovalController.store,
@@ -371,7 +361,6 @@ module.exports = class MetamaskController extends EventEmitter {
const keyringController = this.keyringController
const preferencesController = this.preferencesController
const txController = this.txController
- const noticeController = this.noticeController
const networkController = this.networkController
const providerApprovalController = this.providerApprovalController
@@ -470,11 +459,6 @@ module.exports = class MetamaskController extends EventEmitter {
signTypedMessage: nodeify(this.signTypedMessage, this),
cancelTypedMessage: this.cancelTypedMessage.bind(this),
- // notices
- checkNotices: noticeController.updateNoticesList.bind(noticeController),
- markNoticeRead: noticeController.markNoticeRead.bind(noticeController),
- markAllNoticesRead: nodeify(noticeController.markAllNoticesRead, noticeController),
-
approveProviderRequest: providerApprovalController.approveProviderRequest.bind(providerApprovalController),
clearApprovedOrigins: providerApprovalController.clearApprovedOrigins.bind(providerApprovalController),
rejectProviderRequest: providerApprovalController.rejectProviderRequest.bind(providerApprovalController),
diff --git a/app/scripts/migrations/033.js b/app/scripts/migrations/033.js
new file mode 100644
index 000000000..3abb2593e
--- /dev/null
+++ b/app/scripts/migrations/033.js
@@ -0,0 +1,32 @@
+// next version number
+const version = 33
+
+/*
+
+Cleans up notices and assocated notice controller code
+
+*/
+
+const clone = require('clone')
+
+module.exports = {
+ version,
+
+ migrate: async function (originalVersionedData) {
+ const versionedData = clone(originalVersionedData)
+ versionedData.meta.version = version
+ const state = versionedData.data
+ const newState = transformState(state)
+ versionedData.data = newState
+ return versionedData
+ },
+}
+
+function transformState (state) {
+ const newState = state
+ // transform state here
+ if (state.NoticeController) {
+ delete newState.NoticeController
+ }
+ return newState
+}
diff --git a/app/scripts/migrations/index.js b/app/scripts/migrations/index.js
index eb1b51685..be3328bad 100644
--- a/app/scripts/migrations/index.js
+++ b/app/scripts/migrations/index.js
@@ -42,4 +42,6 @@ module.exports = [
require('./029'),
require('./030'),
require('./031'),
+ require('./032'),
+ require('./033'),
]
diff --git a/app/scripts/notice-controller.js b/app/scripts/notice-controller.js
deleted file mode 100644
index 63b422c5b..000000000
--- a/app/scripts/notice-controller.js
+++ /dev/null
@@ -1,112 +0,0 @@
-const {EventEmitter} = require('events')
-const semver = require('semver')
-const extend = require('xtend')
-const ObservableStore = require('obs-store')
-const hardCodedNotices = require('../../notices/notices.js')
-const uniqBy = require('lodash.uniqby')
-
-module.exports = class NoticeController extends EventEmitter {
-
- constructor (opts = {}) {
- super()
- this.noticePoller = null
- this.firstVersion = opts.firstVersion
- this.version = opts.version
- const initState = extend({
- noticesList: [],
- }, opts.initState)
- this.store = new ObservableStore(initState)
- // setup memStore
- this.memStore = new ObservableStore({})
- this.store.subscribe(() => this._updateMemstore())
- this._updateMemstore()
- // pull in latest notices
- this.updateNoticesList()
- }
-
- getNoticesList () {
- return this.store.getState().noticesList
- }
-
- getUnreadNotices () {
- const notices = this.getNoticesList()
- return notices.filter((notice) => notice.read === false)
- }
-
- getNextUnreadNotice () {
- const unreadNotices = this.getUnreadNotices()
- return unreadNotices[0]
- }
-
- async setNoticesList (noticesList) {
- this.store.updateState({ noticesList })
- return true
- }
-
- markNoticeRead (noticeToMark, cb) {
- cb = cb || function (err) { if (err) throw err }
- try {
- const notices = this.getNoticesList()
- const index = notices.findIndex((currentNotice) => currentNotice.id === noticeToMark.id)
- notices[index].read = true
- notices[index].body = ''
- this.setNoticesList(notices)
- const latestNotice = this.getNextUnreadNotice()
- cb(null, latestNotice)
- } catch (err) {
- cb(err)
- }
- }
-
- markAllNoticesRead () {
- const noticeList = this.getNoticesList()
- noticeList.forEach(notice => {
- notice.read = true
- notice.body = ''
- })
- this.setNoticesList(noticeList)
- const latestNotice = this.getNextUnreadNotice()
- return latestNotice
- }
-
-
- async updateNoticesList () {
- const newNotices = await this._retrieveNoticeData()
- const oldNotices = this.getNoticesList()
- const combinedNotices = this._mergeNotices(oldNotices, newNotices)
- const filteredNotices = this._filterNotices(combinedNotices)
- const result = this.setNoticesList(filteredNotices)
- this._updateMemstore()
- return result
- }
-
- _mergeNotices (oldNotices, newNotices) {
- return uniqBy(oldNotices.concat(newNotices), 'id')
- }
-
- _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
- })
- }
-
- async _retrieveNoticeData () {
- // Placeholder for remote notice API.
- return hardCodedNotices
- }
-
- _updateMemstore () {
- const nextUnreadNotice = this.getNextUnreadNotice()
- const noActiveNotices = !nextUnreadNotice
- this.memStore.updateState({ nextUnreadNotice, noActiveNotices })
- }
-
-}