From d61c979de68934f9d2315261fdaa35fa601d7969 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Tue, 5 Jun 2018 13:44:03 -0700 Subject: Add validation for importing empty private key Previously importing an empty string would result in a new empty Keyring object to be constructed, with no notification to the user. Now we render a clear error explaining the mistake. --- app/scripts/account-import-strategies/index.js | 3 +++ 1 file changed, 3 insertions(+) (limited to 'app/scripts') diff --git a/app/scripts/account-import-strategies/index.js b/app/scripts/account-import-strategies/index.js index 96e2b5912..9f2703571 100644 --- a/app/scripts/account-import-strategies/index.js +++ b/app/scripts/account-import-strategies/index.js @@ -16,6 +16,9 @@ const accountImporter = { strategies: { 'Private Key': (privateKey) => { + if (!privateKey) { + throw new Error('Cannot import an empty key.') + } const stripped = ethUtil.stripHexPrefix(privateKey) return stripped }, -- cgit From 275c31855da73299f4e0838d9ecbcc4278b8431c Mon Sep 17 00:00:00 2001 From: Jenny Pollack Date: Wed, 6 Jun 2018 18:10:05 -0700 Subject: first language - add check for brave browser on getAcceptLanguages --- app/scripts/lib/get-first-preferred-lang-code.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'app/scripts') diff --git a/app/scripts/lib/get-first-preferred-lang-code.js b/app/scripts/lib/get-first-preferred-lang-code.js index 1e6a83ba6..5e524f9eb 100644 --- a/app/scripts/lib/get-first-preferred-lang-code.js +++ b/app/scripts/lib/get-first-preferred-lang-code.js @@ -1,8 +1,14 @@ const extension = require('extensionizer') const promisify = require('pify') const allLocales = require('../../_locales/index.json') +const log = require('loglevel') +// as far as i can tell, this is truthy in the case of Brave browser +// where extension.i18n.getAcceptLanguages throws due to not being implemented +// Unchecked runtime.lastError while running i18n.getAcceptLanguages: Access to extension API denied. +// https://stackoverflow.com/questions/28431505/unchecked-runtime-lasterror-when-using-chrome-api const isSupported = extension.i18n && extension.i18n.getAcceptLanguages + const getPreferredLocales = isSupported ? promisify( extension.i18n.getAcceptLanguages, { errorFirst: false } @@ -18,7 +24,11 @@ const existingLocaleCodes = allLocales.map(locale => locale.code.toLowerCase().r * */ async function getFirstPreferredLangCode () { - const userPreferredLocaleCodes = await getPreferredLocales() + let userPreferredLocaleCodes = await getPreferredLocales() + if(!userPreferredLocaleCodes){ + userPreferredLocaleCodes = [] + } + log.debug(`user preferredLocaleCodes: ${userPreferredLocaleCodes}`) const firstPreferredLangCode = userPreferredLocaleCodes .map(code => code.toLowerCase()) .find(code => existingLocaleCodes.includes(code)) -- cgit From 7edde61c1231b1df6023ac458559b8a008bf300d Mon Sep 17 00:00:00 2001 From: Jenny Pollack Date: Wed, 6 Jun 2018 18:24:45 -0700 Subject: preferred first languauge - check for Brave --- app/scripts/lib/get-first-preferred-lang-code.js | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) (limited to 'app/scripts') diff --git a/app/scripts/lib/get-first-preferred-lang-code.js b/app/scripts/lib/get-first-preferred-lang-code.js index 5e524f9eb..89239a013 100644 --- a/app/scripts/lib/get-first-preferred-lang-code.js +++ b/app/scripts/lib/get-first-preferred-lang-code.js @@ -3,13 +3,7 @@ const promisify = require('pify') const allLocales = require('../../_locales/index.json') const log = require('loglevel') -// as far as i can tell, this is truthy in the case of Brave browser -// where extension.i18n.getAcceptLanguages throws due to not being implemented -// Unchecked runtime.lastError while running i18n.getAcceptLanguages: Access to extension API denied. -// https://stackoverflow.com/questions/28431505/unchecked-runtime-lasterror-when-using-chrome-api -const isSupported = extension.i18n && extension.i18n.getAcceptLanguages - -const getPreferredLocales = isSupported ? promisify( +const getPreferredLocales = extension.i18n ? promisify( extension.i18n.getAcceptLanguages, { errorFirst: false } ) : async () => [] @@ -25,10 +19,13 @@ const existingLocaleCodes = allLocales.map(locale => locale.code.toLowerCase().r */ async function getFirstPreferredLangCode () { let userPreferredLocaleCodes = await getPreferredLocales() + + // safeguard for Brave Browser until they implement chrome.i18n.getAcceptLanguages + // https://github.com/MetaMask/metamask-extension/issues/4270 if(!userPreferredLocaleCodes){ userPreferredLocaleCodes = [] } - log.debug(`user preferredLocaleCodes: ${userPreferredLocaleCodes}`) + const firstPreferredLangCode = userPreferredLocaleCodes .map(code => code.toLowerCase()) .find(code => existingLocaleCodes.includes(code)) -- cgit From 01a1eff8a82167217b4d805e8c09f49ad0109aae Mon Sep 17 00:00:00 2001 From: Jenny Pollack Date: Wed, 6 Jun 2018 18:35:41 -0700 Subject: remove loglevel --- app/scripts/lib/get-first-preferred-lang-code.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'app/scripts') diff --git a/app/scripts/lib/get-first-preferred-lang-code.js b/app/scripts/lib/get-first-preferred-lang-code.js index 89239a013..4d4d9df9a 100644 --- a/app/scripts/lib/get-first-preferred-lang-code.js +++ b/app/scripts/lib/get-first-preferred-lang-code.js @@ -1,7 +1,6 @@ const extension = require('extensionizer') const promisify = require('pify') const allLocales = require('../../_locales/index.json') -const log = require('loglevel') const getPreferredLocales = extension.i18n ? promisify( extension.i18n.getAcceptLanguages, @@ -25,7 +24,7 @@ async function getFirstPreferredLangCode () { if(!userPreferredLocaleCodes){ userPreferredLocaleCodes = [] } - + const firstPreferredLangCode = userPreferredLocaleCodes .map(code => code.toLowerCase()) .find(code => existingLocaleCodes.includes(code)) -- cgit From fd8bcc9cb1b9f9c1cc5ef48eda4952182b23e499 Mon Sep 17 00:00:00 2001 From: Jenny Pollack Date: Wed, 6 Jun 2018 22:08:32 -0700 Subject: lint --- app/scripts/lib/get-first-preferred-lang-code.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/scripts') diff --git a/app/scripts/lib/get-first-preferred-lang-code.js b/app/scripts/lib/get-first-preferred-lang-code.js index 4d4d9df9a..2384e655e 100644 --- a/app/scripts/lib/get-first-preferred-lang-code.js +++ b/app/scripts/lib/get-first-preferred-lang-code.js @@ -21,7 +21,7 @@ async function getFirstPreferredLangCode () { // safeguard for Brave Browser until they implement chrome.i18n.getAcceptLanguages // https://github.com/MetaMask/metamask-extension/issues/4270 - if(!userPreferredLocaleCodes){ + if (!userPreferredLocaleCodes){ userPreferredLocaleCodes = [] } -- cgit From b24efcb1cd9092dfe131af47639ac75ed9209a4c Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Mon, 11 Jun 2018 14:58:05 -0700 Subject: Make account import tests much more specific However, they no longer seem to work. I'm unclear why this test is failing. The private key being provided should be valid. --- app/scripts/account-import-strategies/index.js | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'app/scripts') diff --git a/app/scripts/account-import-strategies/index.js b/app/scripts/account-import-strategies/index.js index 9f2703571..5972cb345 100644 --- a/app/scripts/account-import-strategies/index.js +++ b/app/scripts/account-import-strategies/index.js @@ -19,7 +19,14 @@ const accountImporter = { if (!privateKey) { throw new Error('Cannot import an empty key.') } + const stripped = ethUtil.stripHexPrefix(privateKey) + const buffer = ethUtil.toBuffer(stripped) + + if (!ethUtil.isValidPrivate(buffer)) { + throw new Error('Cannot import invalid private key.') + } + return stripped }, 'JSON File': (input, password) => { -- cgit From f461bd881259183b1f76af27e7662d1c37da672f Mon Sep 17 00:00:00 2001 From: Erik Marks Date: Tue, 12 Jun 2018 09:28:50 -0700 Subject: wip --- app/scripts/inpage.js | 23 ++++++++++++++++++++--- app/scripts/lib/auto-reload.js | 40 ++-------------------------------------- 2 files changed, 22 insertions(+), 41 deletions(-) (limited to 'app/scripts') diff --git a/app/scripts/inpage.js b/app/scripts/inpage.js index 6d16eebd4..cbbcbb00e 100644 --- a/app/scripts/inpage.js +++ b/app/scripts/inpage.js @@ -3,7 +3,7 @@ cleanContextForImports() require('web3/dist/web3.min.js') const log = require('loglevel') const LocalMessageDuplexStream = require('post-message-stream') -const setupDappAutoReload = require('./lib/auto-reload.js') +const exportWeb3Global = require('./lib/auto-reload.js') const MetamaskInpageProvider = require('./lib/inpage-provider.js') restoreContextAfterImports() @@ -38,8 +38,25 @@ web3.setProvider = function () { log.debug('MetaMask - overrode web3.setProvider') } log.debug('MetaMask - injected web3') -// export global web3, with usage-detection -setupDappAutoReload(web3, inpageProvider.publicConfigStore) + +// export global web3, with usage-detection and deprecation warning +exportWeb3Global(web3) +// let hasBeenWarned = false +// global.web3 = new Proxy(web3, { +// get: (_web3, key) => { +// // show warning once on web3 access +// if (!hasBeenWarned && key !== 'currentProvider') { +// console.warn('MetaMask: web3 will be deprecated in the near future in favor of the ethereumProvider \nhttps://github.com/MetaMask/faq/blob/master/detecting_metamask.md#web3-deprecation') +// hasBeenWarned = true +// } +// // return value normally +// return _web3[key] +// }, +// set: (_web3, key, value) => { +// // set value normally +// _web3[key] = value +// }, +// }) // set web3 defaultAccount inpageProvider.publicConfigStore.subscribe(function (state) { diff --git a/app/scripts/lib/auto-reload.js b/app/scripts/lib/auto-reload.js index cce31c3d2..63dc3e921 100644 --- a/app/scripts/lib/auto-reload.js +++ b/app/scripts/lib/auto-reload.js @@ -1,11 +1,9 @@ -module.exports = setupDappAutoReload +module.exports = exportWeb3Global -function setupDappAutoReload (web3, observable) { +function exportWeb3Global (web3) { // export web3 as a global, checking for usage let hasBeenWarned = false - let reloadInProgress = false let lastTimeUsed - let lastSeenNetwork global.web3 = new Proxy(web3, { get: (_web3, key) => { @@ -24,38 +22,4 @@ function setupDappAutoReload (web3, observable) { _web3[key] = value }, }) - - observable.subscribe(function (state) { - // if reload in progress, no need to check reload logic - if (reloadInProgress) return - - const currentNetwork = state.networkVersion - - // set the initial network - if (!lastSeenNetwork) { - lastSeenNetwork = currentNetwork - return - } - - // skip reload logic if web3 not used - if (!lastTimeUsed) return - - // if network did not change, exit - if (currentNetwork === lastSeenNetwork) return - - // initiate page reload - reloadInProgress = true - const timeSinceUse = Date.now() - lastTimeUsed - // if web3 was recently used then delay the reloading of the page - if (timeSinceUse > 500) { - triggerReset() - } else { - setTimeout(triggerReset, 500) - } - }) -} - -// reload the page -function triggerReset () { - global.location.reload() } -- cgit From b98296138146fcd304a21637ea83a13670cff6ed Mon Sep 17 00:00:00 2001 From: Erik Marks Date: Tue, 12 Jun 2018 11:04:37 -0700 Subject: removed auto-reload.js, moved global web3 export to inpage.js --- app/scripts/inpage.js | 34 ++++++++++++++++------------------ app/scripts/lib/auto-reload.js | 25 ------------------------- 2 files changed, 16 insertions(+), 43 deletions(-) delete mode 100644 app/scripts/lib/auto-reload.js (limited to 'app/scripts') diff --git a/app/scripts/inpage.js b/app/scripts/inpage.js index cbbcbb00e..070f5d247 100644 --- a/app/scripts/inpage.js +++ b/app/scripts/inpage.js @@ -3,7 +3,6 @@ cleanContextForImports() require('web3/dist/web3.min.js') const log = require('loglevel') const LocalMessageDuplexStream = require('post-message-stream') -const exportWeb3Global = require('./lib/auto-reload.js') const MetamaskInpageProvider = require('./lib/inpage-provider.js') restoreContextAfterImports() @@ -40,23 +39,22 @@ web3.setProvider = function () { log.debug('MetaMask - injected web3') // export global web3, with usage-detection and deprecation warning -exportWeb3Global(web3) -// let hasBeenWarned = false -// global.web3 = new Proxy(web3, { -// get: (_web3, key) => { -// // show warning once on web3 access -// if (!hasBeenWarned && key !== 'currentProvider') { -// console.warn('MetaMask: web3 will be deprecated in the near future in favor of the ethereumProvider \nhttps://github.com/MetaMask/faq/blob/master/detecting_metamask.md#web3-deprecation') -// hasBeenWarned = true -// } -// // return value normally -// return _web3[key] -// }, -// set: (_web3, key, value) => { -// // set value normally -// _web3[key] = value -// }, -// }) +let hasBeenWarned = false +global.web3 = new Proxy(web3, { + get: (_web3, key) => { + // show warning once on web3 access + if (!hasBeenWarned && key !== 'currentProvider') { + console.warn('MetaMask: web3 will be deprecated in the near future in favor of the ethereumProvider \nhttps://github.com/MetaMask/faq/blob/master/detecting_metamask.md#web3-deprecation') + hasBeenWarned = true + } + // return value normally + return _web3[key] + }, + set: (_web3, key, value) => { + // set value normally + _web3[key] = value + }, +}) // set web3 defaultAccount inpageProvider.publicConfigStore.subscribe(function (state) { diff --git a/app/scripts/lib/auto-reload.js b/app/scripts/lib/auto-reload.js deleted file mode 100644 index 63dc3e921..000000000 --- a/app/scripts/lib/auto-reload.js +++ /dev/null @@ -1,25 +0,0 @@ -module.exports = exportWeb3Global - -function exportWeb3Global (web3) { - // export web3 as a global, checking for usage - let hasBeenWarned = false - let lastTimeUsed - - global.web3 = new Proxy(web3, { - get: (_web3, key) => { - // show warning once on web3 access - if (!hasBeenWarned && key !== 'currentProvider') { - console.warn('MetaMask: web3 will be deprecated in the near future in favor of the ethereumProvider \nhttps://github.com/MetaMask/faq/blob/master/detecting_metamask.md#web3-deprecation') - hasBeenWarned = true - } - // get the time of use - lastTimeUsed = Date.now() - // return value normally - return _web3[key] - }, - set: (_web3, key, value) => { - // set value normally - _web3[key] = value - }, - }) -} -- cgit From 8f93e341750b99b8ff0e66f2a6831799c7d9ab58 Mon Sep 17 00:00:00 2001 From: kumavis Date: Tue, 12 Jun 2018 10:55:54 -0700 Subject: nonce-tracker - wrap nonce calculations in try-catch and release lock on error --- .../controllers/transactions/nonce-tracker.js | 50 ++++++++++++---------- 1 file changed, 28 insertions(+), 22 deletions(-) (limited to 'app/scripts') diff --git a/app/scripts/controllers/transactions/nonce-tracker.js b/app/scripts/controllers/transactions/nonce-tracker.js index f8cdc5523..ca340bae4 100644 --- a/app/scripts/controllers/transactions/nonce-tracker.js +++ b/app/scripts/controllers/transactions/nonce-tracker.js @@ -49,29 +49,35 @@ class NonceTracker { await this._globalMutexFree() // await lock free, then take lock const releaseLock = await this._takeMutex(address) - // evaluate multiple nextNonce strategies - const nonceDetails = {} - const networkNonceResult = await this._getNetworkNextNonce(address) - const highestLocallyConfirmed = this._getHighestLocallyConfirmed(address) - const nextNetworkNonce = networkNonceResult.nonce - const highestSuggested = Math.max(nextNetworkNonce, highestLocallyConfirmed) - - const pendingTxs = this.getPendingTransactions(address) - const localNonceResult = this._getHighestContinuousFrom(pendingTxs, highestSuggested) || 0 - - nonceDetails.params = { - highestLocallyConfirmed, - highestSuggested, - nextNetworkNonce, + try { + // evaluate multiple nextNonce strategies + const nonceDetails = {} + const networkNonceResult = await this._getNetworkNextNonce(address) + const highestLocallyConfirmed = this._getHighestLocallyConfirmed(address) + const nextNetworkNonce = networkNonceResult.nonce + const highestSuggested = Math.max(nextNetworkNonce, highestLocallyConfirmed) + + const pendingTxs = this.getPendingTransactions(address) + const localNonceResult = this._getHighestContinuousFrom(pendingTxs, highestSuggested) || 0 + + nonceDetails.params = { + highestLocallyConfirmed, + highestSuggested, + nextNetworkNonce, + } + nonceDetails.local = localNonceResult + nonceDetails.network = networkNonceResult + + const nextNonce = Math.max(networkNonceResult.nonce, localNonceResult.nonce) + assert(Number.isInteger(nextNonce), `nonce-tracker - nextNonce is not an integer - got: (${typeof nextNonce}) "${nextNonce}"`) + + // return nonce and release cb + return { nextNonce, nonceDetails, releaseLock } + } catch (err) { + // release lock if we encounter an error + releaseLock() + throw err } - nonceDetails.local = localNonceResult - nonceDetails.network = networkNonceResult - - const nextNonce = Math.max(networkNonceResult.nonce, localNonceResult.nonce) - assert(Number.isInteger(nextNonce), `nonce-tracker - nextNonce is not an integer - got: (${typeof nextNonce}) "${nextNonce}"`) - - // return nonce and release cb - return { nextNonce, nonceDetails, releaseLock } } async _getCurrentBlock () { -- cgit From 177cc3f280f26c5fb4cfc1b934e95b9d16def1a6 Mon Sep 17 00:00:00 2001 From: kumavis Date: Tue, 12 Jun 2018 11:51:35 -0700 Subject: metamask - ensure all nonce locks are released --- app/scripts/controllers/transactions/index.js | 7 ++++++- .../controllers/transactions/nonce-tracker.js | 4 ++-- .../controllers/transactions/pending-tx-tracker.js | 4 ++-- app/scripts/metamask-controller.js | 20 ++++++++------------ 4 files changed, 18 insertions(+), 17 deletions(-) (limited to 'app/scripts') diff --git a/app/scripts/controllers/transactions/index.js b/app/scripts/controllers/transactions/index.js index b53947e27..339052543 100644 --- a/app/scripts/controllers/transactions/index.js +++ b/app/scripts/controllers/transactions/index.js @@ -264,7 +264,12 @@ class TransactionController extends EventEmitter { // must set transaction to submitted/failed before releasing lock nonceLock.releaseLock() } catch (err) { - this.txStateManager.setTxStatusFailed(txId, err) + // this is try-catch wrapped so that we can guarantee that the nonceLock is released + try { + this.txStateManager.setTxStatusFailed(txId, err) + } catch (err) { + console.error(err) + } // must set transaction to submitted/failed before releasing lock if (nonceLock) nonceLock.releaseLock() // continue with error chain diff --git a/app/scripts/controllers/transactions/nonce-tracker.js b/app/scripts/controllers/transactions/nonce-tracker.js index ca340bae4..35ca08d6c 100644 --- a/app/scripts/controllers/transactions/nonce-tracker.js +++ b/app/scripts/controllers/transactions/nonce-tracker.js @@ -91,8 +91,8 @@ class NonceTracker { async _globalMutexFree () { const globalMutex = this._lookupMutex('global') - const release = await globalMutex.acquire() - release() + const releaseLock = await globalMutex.acquire() + releaseLock() } async _takeMutex (lockId) { diff --git a/app/scripts/controllers/transactions/pending-tx-tracker.js b/app/scripts/controllers/transactions/pending-tx-tracker.js index 6e2fcb40b..4e41cdaf8 100644 --- a/app/scripts/controllers/transactions/pending-tx-tracker.js +++ b/app/scripts/controllers/transactions/pending-tx-tracker.js @@ -196,14 +196,14 @@ class PendingTransactionTracker extends EventEmitter { async _checkPendingTxs () { const signedTxList = this.getPendingTransactions() // in order to keep the nonceTracker accurate we block it while updating pending transactions - const nonceGlobalLock = await this.nonceTracker.getGlobalLock() + const { releaseLock } = await this.nonceTracker.getGlobalLock() try { await Promise.all(signedTxList.map((txMeta) => this._checkPendingTx(txMeta))) } catch (err) { log.error('PendingTransactionWatcher - Error updating pending transactions') log.error(err) } - nonceGlobalLock.releaseLock() + releaseLock() } /** diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js index a362e3826..e444180cc 100644 --- a/app/scripts/metamask-controller.js +++ b/app/scripts/metamask-controller.js @@ -436,28 +436,24 @@ module.exports = class MetamaskController extends EventEmitter { * @returns {Object} vault */ async createNewVaultAndKeychain (password) { - const release = await this.createVaultMutex.acquire() - let vault - + const releaseLock = await this.createVaultMutex.acquire() try { + let vault const accounts = await this.keyringController.getAccounts() - if (accounts.length > 0) { vault = await this.keyringController.fullUpdate() - } else { vault = await this.keyringController.createNewVaultAndKeychain(password) const accounts = await this.keyringController.getAccounts() this.preferencesController.setAddresses(accounts) this.selectFirstIdentity() } - release() + releaseLock() + return vault } catch (err) { - release() + releaseLock() throw err } - - return vault } /** @@ -466,7 +462,7 @@ module.exports = class MetamaskController extends EventEmitter { * @param {} seed */ async createNewVaultAndRestore (password, seed) { - const release = await this.createVaultMutex.acquire() + const releaseLock = await this.createVaultMutex.acquire() try { // clear known identities this.preferencesController.setAddresses([]) @@ -476,10 +472,10 @@ module.exports = class MetamaskController extends EventEmitter { const accounts = await this.keyringController.getAccounts() this.preferencesController.setAddresses(accounts) this.selectFirstIdentity() - release() + releaseLock() return vault } catch (err) { - release() + releaseLock() throw err } } -- cgit From 604289c96cde7e5f4634fe5e76a50dfa9174fcbd Mon Sep 17 00:00:00 2001 From: kumavis Date: Tue, 12 Jun 2018 12:08:06 -0700 Subject: controllers - transaction - prefer log over console --- app/scripts/controllers/transactions/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'app/scripts') diff --git a/app/scripts/controllers/transactions/index.js b/app/scripts/controllers/transactions/index.js index 339052543..8e2288aed 100644 --- a/app/scripts/controllers/transactions/index.js +++ b/app/scripts/controllers/transactions/index.js @@ -165,7 +165,7 @@ class TransactionController extends EventEmitter { // add default tx params txMeta = await this.addTxGasDefaults(txMeta) } catch (error) { - console.log(error) + log.warn(error) this.txStateManager.setTxStatusFailed(txMeta.id, error) throw error } @@ -268,7 +268,7 @@ class TransactionController extends EventEmitter { try { this.txStateManager.setTxStatusFailed(txId, err) } catch (err) { - console.error(err) + log.error(err) } // must set transaction to submitted/failed before releasing lock if (nonceLock) nonceLock.releaseLock() -- cgit From 7b414f3ed08b8eb35ce7a8e076e4ffd75fea3d30 Mon Sep 17 00:00:00 2001 From: kumavis Date: Wed, 13 Jun 2018 16:45:18 -0700 Subject: background - persistence pipeline - fix persistence bug --- app/scripts/background.js | 14 ++++++++------ app/scripts/lib/createStreamSink.js | 24 ++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 6 deletions(-) create mode 100644 app/scripts/lib/createStreamSink.js (limited to 'app/scripts') diff --git a/app/scripts/background.js b/app/scripts/background.js index 56e190f97..2451cddb6 100644 --- a/app/scripts/background.js +++ b/app/scripts/background.js @@ -16,6 +16,7 @@ const ExtensionPlatform = require('./platforms/extension') const Migrator = require('./lib/migrator/') const migrations = require('./migrations/') const PortStream = require('./lib/port-stream.js') +const createStreamSink = require('./lib/createStreamSink') const NotificationManager = require('./lib/notification-manager.js') const MetamaskController = require('./metamask-controller') const firstTimeState = require('./first-time-state') @@ -273,7 +274,7 @@ function setupController (initState, initLangCode) { asStream(controller.store), debounce(1000), storeTransform(versionifyData), - storeTransform(persistData), + createStreamSink(persistData), (error) => { log.error('MetaMask - Persistence pipeline failed', error) } @@ -289,7 +290,7 @@ function setupController (initState, initLangCode) { return versionedData } - function persistData (state) { + async function persistData (state) { if (!state) { throw new Error('MetaMask - updated state is missing', state) } @@ -297,12 +298,13 @@ function setupController (initState, initLangCode) { throw new Error('MetaMask - updated state does not have data', state) } if (localStore.isSupported) { - localStore.set(state) - .catch((err) => { + try { + await localStore.set(state) + } catch (err) { + // log error so we dont break the pipeline log.error('error setting state in local store:', err) - }) + } } - return state } // diff --git a/app/scripts/lib/createStreamSink.js b/app/scripts/lib/createStreamSink.js new file mode 100644 index 000000000..cf9416fea --- /dev/null +++ b/app/scripts/lib/createStreamSink.js @@ -0,0 +1,24 @@ +const WritableStream = require('readable-stream').Writable +const promiseToCallback = require('promise-to-callback') + +module.exports = createStreamSink + + +function createStreamSink(asyncWriteFn, _opts) { + return new AsyncWritableStream(asyncWriteFn, _opts) +} + +class AsyncWritableStream extends WritableStream { + + constructor (asyncWriteFn, _opts) { + const opts = Object.assign({ objectMode: true }, _opts) + super(opts) + this._asyncWriteFn = asyncWriteFn + } + + // write from incomming stream to state + _write (chunk, encoding, callback) { + promiseToCallback(this._asyncWriteFn(chunk, encoding))(callback) + } + +} -- cgit From 43e805805ea49b36034837f081f17e4ec5d86020 Mon Sep 17 00:00:00 2001 From: kumavis Date: Wed, 13 Jun 2018 17:40:28 -0700 Subject: diagnostics - temporarily disable --- app/scripts/metamask-controller.js | 8 -------- 1 file changed, 8 deletions(-) (limited to 'app/scripts') diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js index e444180cc..6e3425cc2 100644 --- a/app/scripts/metamask-controller.js +++ b/app/scripts/metamask-controller.js @@ -46,7 +46,6 @@ const GWEI_BN = new BN('1000000000') const percentile = require('percentile') const seedPhraseVerifier = require('./lib/seed-phrase-verifier') const cleanErrorStack = require('./lib/cleanErrorStack') -const DiagnosticsReporter = require('./lib/diagnostics-reporter') const log = require('loglevel') module.exports = class MetamaskController extends EventEmitter { @@ -65,12 +64,6 @@ module.exports = class MetamaskController extends EventEmitter { const initState = opts.initState || {} this.recordFirstTimeInfo(initState) - // metamask diagnostics reporter - this.diagnostics = opts.diagnostics || new DiagnosticsReporter({ - firstTimeInfo: initState.firstTimeInfo, - version, - }) - // platform-specific api this.platform = opts.platform @@ -92,7 +85,6 @@ module.exports = class MetamaskController extends EventEmitter { this.preferencesController = new PreferencesController({ initState: initState.PreferencesController, initLangCode: opts.initLangCode, - diagnostics: this.diagnostics, }) // currency controller -- cgit From 691ac5d288963f376e34c1711e23bbd58432396f Mon Sep 17 00:00:00 2001 From: kumavis Date: Wed, 13 Jun 2018 21:06:33 -0700 Subject: account-import-strategies - ensure privateKey is prefixed before converting to buffer --- app/scripts/account-import-strategies/index.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'app/scripts') diff --git a/app/scripts/account-import-strategies/index.js b/app/scripts/account-import-strategies/index.js index 5972cb345..16ae224ea 100644 --- a/app/scripts/account-import-strategies/index.js +++ b/app/scripts/account-import-strategies/index.js @@ -20,13 +20,14 @@ const accountImporter = { throw new Error('Cannot import an empty key.') } - const stripped = ethUtil.stripHexPrefix(privateKey) - const buffer = ethUtil.toBuffer(stripped) + const prefixed = ethUtil.addHexPrefix(privateKey) + const buffer = ethUtil.toBuffer(prefixed) if (!ethUtil.isValidPrivate(buffer)) { throw new Error('Cannot import invalid private key.') } + const stripped = ethUtil.stripHexPrefix(prefixed) return stripped }, 'JSON File': (input, password) => { -- cgit From ac8b56a00defff4cb44a6a34251a19d8ab6159b6 Mon Sep 17 00:00:00 2001 From: kumavis Date: Wed, 13 Jun 2018 22:56:46 -0700 Subject: notices - notices collection is now manually edited --- app/scripts/notice-controller.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/scripts') diff --git a/app/scripts/notice-controller.js b/app/scripts/notice-controller.js index 14a63eae7..377ef5055 100644 --- a/app/scripts/notice-controller.js +++ b/app/scripts/notice-controller.js @@ -2,7 +2,7 @@ const EventEmitter = require('events').EventEmitter const semver = require('semver') const extend = require('xtend') const ObservableStore = require('obs-store') -const hardCodedNotices = require('../../notices/notices.json') +const hardCodedNotices = require('../../notices/notices.js') const uniqBy = require('lodash.uniqby') module.exports = class NoticeController extends EventEmitter { -- cgit From 44a8e48a04ea69e1f8e530ae1bacf55890f8df98 Mon Sep 17 00:00:00 2001 From: kumavis Date: Wed, 13 Jun 2018 23:30:31 -0700 Subject: notices - replace getLatestNotice with getNextNotice --- app/scripts/metamask-controller.js | 3 --- app/scripts/notice-controller.js | 29 ++++++++--------------------- 2 files changed, 8 insertions(+), 24 deletions(-) (limited to 'app/scripts') diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js index e444180cc..cc02958b5 100644 --- a/app/scripts/metamask-controller.js +++ b/app/scripts/metamask-controller.js @@ -189,9 +189,6 @@ module.exports = class MetamaskController extends EventEmitter { version, firstVersion: initState.firstTimeInfo.version, }) - this.noticeController.updateNoticesList() - // to be uncommented when retrieving notices from a remote server. - // this.noticeController.startPolling() this.shapeshiftController = new ShapeShiftController({ initState: initState.ShapeShiftController, diff --git a/app/scripts/notice-controller.js b/app/scripts/notice-controller.js index 377ef5055..635922104 100644 --- a/app/scripts/notice-controller.js +++ b/app/scripts/notice-controller.js @@ -13,7 +13,7 @@ module.exports = class NoticeController extends EventEmitter { this.firstVersion = opts.firstVersion this.version = opts.version const initState = extend({ - noticesList: [], + noticesList: hardCodedNotices, }, opts.initState) this.store = new ObservableStore(initState) this.memStore = new ObservableStore({}) @@ -29,9 +29,9 @@ module.exports = class NoticeController extends EventEmitter { return notices.filter((notice) => notice.read === false) } - getLatestUnreadNotice () { + getNextUnreadNotice () { const unreadNotices = this.getUnreadNotices() - return unreadNotices[unreadNotices.length - 1] + return unreadNotices[0] } async setNoticesList (noticesList) { @@ -47,7 +47,7 @@ module.exports = class NoticeController extends EventEmitter { notices[index].read = true notices[index].body = '' this.setNoticesList(notices) - const latestNotice = this.getLatestUnreadNotice() + const latestNotice = this.getNextUnreadNotice() cb(null, latestNotice) } catch (err) { cb(err) @@ -64,15 +64,6 @@ module.exports = class NoticeController extends EventEmitter { return result } - startPolling () { - if (this.noticePoller) { - clearInterval(this.noticePoller) - } - this.noticePoller = setInterval(() => { - this.noticeController.updateNoticesList() - }, 300000) - } - _mergeNotices (oldNotices, newNotices) { return uniqBy(oldNotices.concat(newNotices), 'id') } @@ -91,19 +82,15 @@ module.exports = class NoticeController extends EventEmitter { }) } - _mapNoticeIds (notices) { - return notices.map((notice) => notice.id) - } - async _retrieveNoticeData () { // Placeholder for the API. - return hardCodedNotices + return [] } _updateMemstore () { - const lastUnreadNotice = this.getLatestUnreadNotice() - const noActiveNotices = !lastUnreadNotice - this.memStore.updateState({ lastUnreadNotice, noActiveNotices }) + const nextUnreadNotice = this.getNextUnreadNotice() + const noActiveNotices = !nextUnreadNotice + this.memStore.updateState({ nextUnreadNotice, noActiveNotices }) } } -- cgit From 4b8a4fd5fe5816dc5d748436b5b1cd9fe7d5bdea Mon Sep 17 00:00:00 2001 From: kumavis Date: Wed, 13 Jun 2018 23:52:51 -0700 Subject: test - e2e - check for phishing warning --- app/scripts/notice-controller.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/scripts') diff --git a/app/scripts/notice-controller.js b/app/scripts/notice-controller.js index 635922104..5cbc14c78 100644 --- a/app/scripts/notice-controller.js +++ b/app/scripts/notice-controller.js @@ -13,7 +13,7 @@ module.exports = class NoticeController extends EventEmitter { this.firstVersion = opts.firstVersion this.version = opts.version const initState = extend({ - noticesList: hardCodedNotices, + noticesList: this._filterNotices(hardCodedNotices), }, opts.initState) this.store = new ObservableStore(initState) this.memStore = new ObservableStore({}) -- cgit From 722c5ae82153d2bcf3c34037e13d3d5f430920f2 Mon Sep 17 00:00:00 2001 From: kumavis Date: Thu, 14 Jun 2018 00:23:01 -0700 Subject: notice-controller - update memStore on boot --- app/scripts/notice-controller.js | 1 + 1 file changed, 1 insertion(+) (limited to 'app/scripts') diff --git a/app/scripts/notice-controller.js b/app/scripts/notice-controller.js index 5cbc14c78..e202043cf 100644 --- a/app/scripts/notice-controller.js +++ b/app/scripts/notice-controller.js @@ -18,6 +18,7 @@ module.exports = class NoticeController extends EventEmitter { this.store = new ObservableStore(initState) this.memStore = new ObservableStore({}) this.store.subscribe(() => this._updateMemstore()) + this._updateMemstore() } getNoticesList () { -- cgit From 11bfdf444dca3917479cff82f807cc0d4c217191 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Thu, 14 Jun 2018 10:09:45 -0700 Subject: Handle brave throws --- app/scripts/lib/get-first-preferred-lang-code.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'app/scripts') diff --git a/app/scripts/lib/get-first-preferred-lang-code.js b/app/scripts/lib/get-first-preferred-lang-code.js index 2384e655e..41a886d74 100644 --- a/app/scripts/lib/get-first-preferred-lang-code.js +++ b/app/scripts/lib/get-first-preferred-lang-code.js @@ -17,12 +17,19 @@ const existingLocaleCodes = allLocales.map(locale => locale.code.toLowerCase().r * */ async function getFirstPreferredLangCode () { - let userPreferredLocaleCodes = await getPreferredLocales() - + let userPreferredLocaleCodes + + try { + userPreferredLocaleCodes = await getPreferredLocales() + } catch (e) { + // Brave currently throws when calling getAcceptLanguages, so this handles that. + userPreferredLocaleCodes = [] + } + // safeguard for Brave Browser until they implement chrome.i18n.getAcceptLanguages // https://github.com/MetaMask/metamask-extension/issues/4270 if (!userPreferredLocaleCodes){ - userPreferredLocaleCodes = [] + userPreferredLocaleCodes = [] } const firstPreferredLangCode = userPreferredLocaleCodes @@ -32,3 +39,4 @@ async function getFirstPreferredLangCode () { } module.exports = getFirstPreferredLangCode + -- cgit From 3a6cc3c8fd1cf16b744af61104472887d6d37fb3 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Thu, 14 Jun 2018 15:15:23 -0700 Subject: Re-enable dapp reload on network change We want to give devs some time to digest [this blog post](https://medium.com/metamask/breaking-change-no-longer-reloading-pages-on-network-change-4a3e1fd2f5e7) before we making a breaking change to our platform. Makes it easy to re-implement the change. --- app/scripts/inpage.js | 6 +++++ app/scripts/lib/auto-reload.js | 61 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+) create mode 100644 app/scripts/lib/auto-reload.js (limited to 'app/scripts') diff --git a/app/scripts/inpage.js b/app/scripts/inpage.js index 070f5d247..7dd7fda02 100644 --- a/app/scripts/inpage.js +++ b/app/scripts/inpage.js @@ -3,6 +3,7 @@ cleanContextForImports() require('web3/dist/web3.min.js') const log = require('loglevel') const LocalMessageDuplexStream = require('post-message-stream') +const setupDappAutoReload = require('./lib/auto-reload.js') const MetamaskInpageProvider = require('./lib/inpage-provider.js') restoreContextAfterImports() @@ -38,7 +39,11 @@ web3.setProvider = function () { } log.debug('MetaMask - injected web3') +setupDappAutoReload(web3, inpageProvider.publicConfigStore) + // export global web3, with usage-detection and deprecation warning + +/* TODO: Uncomment this area once auto-reload.js has been deprecated: let hasBeenWarned = false global.web3 = new Proxy(web3, { get: (_web3, key) => { @@ -55,6 +60,7 @@ global.web3 = new Proxy(web3, { _web3[key] = value }, }) +*/ // set web3 defaultAccount inpageProvider.publicConfigStore.subscribe(function (state) { diff --git a/app/scripts/lib/auto-reload.js b/app/scripts/lib/auto-reload.js new file mode 100644 index 000000000..cce31c3d2 --- /dev/null +++ b/app/scripts/lib/auto-reload.js @@ -0,0 +1,61 @@ +module.exports = setupDappAutoReload + +function setupDappAutoReload (web3, observable) { + // export web3 as a global, checking for usage + let hasBeenWarned = false + let reloadInProgress = false + let lastTimeUsed + let lastSeenNetwork + + global.web3 = new Proxy(web3, { + get: (_web3, key) => { + // show warning once on web3 access + if (!hasBeenWarned && key !== 'currentProvider') { + console.warn('MetaMask: web3 will be deprecated in the near future in favor of the ethereumProvider \nhttps://github.com/MetaMask/faq/blob/master/detecting_metamask.md#web3-deprecation') + hasBeenWarned = true + } + // get the time of use + lastTimeUsed = Date.now() + // return value normally + return _web3[key] + }, + set: (_web3, key, value) => { + // set value normally + _web3[key] = value + }, + }) + + observable.subscribe(function (state) { + // if reload in progress, no need to check reload logic + if (reloadInProgress) return + + const currentNetwork = state.networkVersion + + // set the initial network + if (!lastSeenNetwork) { + lastSeenNetwork = currentNetwork + return + } + + // skip reload logic if web3 not used + if (!lastTimeUsed) return + + // if network did not change, exit + if (currentNetwork === lastSeenNetwork) return + + // initiate page reload + reloadInProgress = true + const timeSinceUse = Date.now() - lastTimeUsed + // if web3 was recently used then delay the reloading of the page + if (timeSinceUse > 500) { + triggerReset() + } else { + setTimeout(triggerReset, 500) + } + }) +} + +// reload the page +function triggerReset () { + global.location.reload() +} -- cgit From a42299aab7d775f8a55d7c5e7fc02192371a3f25 Mon Sep 17 00:00:00 2001 From: Dan Finlay <542863+danfinlay@users.noreply.github.com> Date: Fri, 15 Jun 2018 08:55:39 -0700 Subject: Add apparent phishing address to block list In [this reddit post](https://www.reddit.com/r/Metamask/comments/8r3nsu/help_me_please_somebody_stole_my_ethers/) a user suggests they got some ether stolen after visiting IDEX. Their ether was sent to [this address](https://etherscan.io/address/0x9bcb0a9d99d815bb87ee3191b1399b1bcc46dc77), which is full of comments of people telling similar stories of being phished on IDEX. I think we can safely block this, and probably safe some people some money. --- app/scripts/controllers/transactions/lib/recipient-blacklist-config.json | 1 + 1 file changed, 1 insertion(+) (limited to 'app/scripts') diff --git a/app/scripts/controllers/transactions/lib/recipient-blacklist-config.json b/app/scripts/controllers/transactions/lib/recipient-blacklist-config.json index b348eb72e..995ca102a 100644 --- a/app/scripts/controllers/transactions/lib/recipient-blacklist-config.json +++ b/app/scripts/controllers/transactions/lib/recipient-blacklist-config.json @@ -1,5 +1,6 @@ { "blacklist": [ + "0x9bcb0A9d99d815Bb87ee3191b1399b1Bcc46dc77", "0x627306090abab3a6e1400e9345bc60c78a8bef57", "0xf17f52151ebef6c7334fad080c5704d77216b732", "0xc5fdf4076b8f3a5357c5e395ab970b5b54098fef", -- cgit From 753743e7462285e3bffbf1ce53817731da176514 Mon Sep 17 00:00:00 2001 From: kumavis Date: Fri, 15 Jun 2018 10:32:09 -0700 Subject: Update recipient-blacklist-config.json --- .../controllers/transactions/lib/recipient-blacklist-config.json | 2 ++ 1 file changed, 2 insertions(+) (limited to 'app/scripts') diff --git a/app/scripts/controllers/transactions/lib/recipient-blacklist-config.json b/app/scripts/controllers/transactions/lib/recipient-blacklist-config.json index 995ca102a..f0b427fe3 100644 --- a/app/scripts/controllers/transactions/lib/recipient-blacklist-config.json +++ b/app/scripts/controllers/transactions/lib/recipient-blacklist-config.json @@ -1,6 +1,8 @@ { "blacklist": [ + // IDEX phisher "0x9bcb0A9d99d815Bb87ee3191b1399b1Bcc46dc77", + // Ganache default seed phrases "0x627306090abab3a6e1400e9345bc60c78a8bef57", "0xf17f52151ebef6c7334fad080c5704d77216b732", "0xc5fdf4076b8f3a5357c5e395ab970b5b54098fef", -- cgit From 83c02f90cf1f85925fc8b7dd242a4cc96c2d509c Mon Sep 17 00:00:00 2001 From: kumavis Date: Fri, 15 Jun 2018 10:47:42 -0700 Subject: blacklist - recipient blacklist as js for inline comments --- .../transactions/lib/recipient-blacklist-checker.js | 2 +- .../transactions/lib/recipient-blacklist-config.json | 17 ----------------- .../controllers/transactions/lib/recipient-blacklist.js | 17 +++++++++++++++++ 3 files changed, 18 insertions(+), 18 deletions(-) delete mode 100644 app/scripts/controllers/transactions/lib/recipient-blacklist-config.json create mode 100644 app/scripts/controllers/transactions/lib/recipient-blacklist.js (limited to 'app/scripts') diff --git a/app/scripts/controllers/transactions/lib/recipient-blacklist-checker.js b/app/scripts/controllers/transactions/lib/recipient-blacklist-checker.js index 84c6df1f0..e4df2367e 100644 --- a/app/scripts/controllers/transactions/lib/recipient-blacklist-checker.js +++ b/app/scripts/controllers/transactions/lib/recipient-blacklist-checker.js @@ -1,4 +1,4 @@ -const Config = require('./recipient-blacklist-config.json') +const Config = require('./recipient-blacklist.js') /** @module*/ module.exports = { diff --git a/app/scripts/controllers/transactions/lib/recipient-blacklist-config.json b/app/scripts/controllers/transactions/lib/recipient-blacklist-config.json deleted file mode 100644 index f0b427fe3..000000000 --- a/app/scripts/controllers/transactions/lib/recipient-blacklist-config.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "blacklist": [ - // IDEX phisher - "0x9bcb0A9d99d815Bb87ee3191b1399b1Bcc46dc77", - // Ganache default seed phrases - "0x627306090abab3a6e1400e9345bc60c78a8bef57", - "0xf17f52151ebef6c7334fad080c5704d77216b732", - "0xc5fdf4076b8f3a5357c5e395ab970b5b54098fef", - "0x821aea9a577a9b44299b9c15c88cf3087f3b5544", - "0x0d1d4e623d10f9fba5db95830f7d3839406c6af2", - "0x2932b7a2355d6fecc4b5c0b6bd44cc31df247a2e", - "0x2191ef87e392377ec08e7c08eb105ef5448eced5", - "0x0f4f2ac550a1b4e2280d04c21cea7ebd822934b5", - "0x6330a553fc93768f612722bb8c2ec78ac90b3bbc", - "0x5aeda56215b167893e80b4fe645ba6d5bab767de" - ] -} diff --git a/app/scripts/controllers/transactions/lib/recipient-blacklist.js b/app/scripts/controllers/transactions/lib/recipient-blacklist.js new file mode 100644 index 000000000..810112977 --- /dev/null +++ b/app/scripts/controllers/transactions/lib/recipient-blacklist.js @@ -0,0 +1,17 @@ +module.exports = { + "blacklist": [ + // IDEX phisher + "0x9bcb0A9d99d815Bb87ee3191b1399b1Bcc46dc77", + // Ganache default seed phrases + "0x627306090abab3a6e1400e9345bc60c78a8bef57", + "0xf17f52151ebef6c7334fad080c5704d77216b732", + "0xc5fdf4076b8f3a5357c5e395ab970b5b54098fef", + "0x821aea9a577a9b44299b9c15c88cf3087f3b5544", + "0x0d1d4e623d10f9fba5db95830f7d3839406c6af2", + "0x2932b7a2355d6fecc4b5c0b6bd44cc31df247a2e", + "0x2191ef87e392377ec08e7c08eb105ef5448eced5", + "0x0f4f2ac550a1b4e2280d04c21cea7ebd822934b5", + "0x6330a553fc93768f612722bb8c2ec78ac90b3bbc", + "0x5aeda56215b167893e80b4fe645ba6d5bab767de" + ] +} -- cgit From 33cb0a8cb2a7fe594eb5f0761e1c7b329a6021d5 Mon Sep 17 00:00:00 2001 From: kumavis Date: Fri, 15 Jun 2018 11:07:56 -0700 Subject: lint - fix recipient-blacklist.js --- .../transactions/lib/recipient-blacklist.js | 26 +++++++++++----------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'app/scripts') diff --git a/app/scripts/controllers/transactions/lib/recipient-blacklist.js b/app/scripts/controllers/transactions/lib/recipient-blacklist.js index 810112977..08e1a2ccd 100644 --- a/app/scripts/controllers/transactions/lib/recipient-blacklist.js +++ b/app/scripts/controllers/transactions/lib/recipient-blacklist.js @@ -1,17 +1,17 @@ module.exports = { - "blacklist": [ + 'blacklist': [ // IDEX phisher - "0x9bcb0A9d99d815Bb87ee3191b1399b1Bcc46dc77", + '0x9bcb0A9d99d815Bb87ee3191b1399b1Bcc46dc77', // Ganache default seed phrases - "0x627306090abab3a6e1400e9345bc60c78a8bef57", - "0xf17f52151ebef6c7334fad080c5704d77216b732", - "0xc5fdf4076b8f3a5357c5e395ab970b5b54098fef", - "0x821aea9a577a9b44299b9c15c88cf3087f3b5544", - "0x0d1d4e623d10f9fba5db95830f7d3839406c6af2", - "0x2932b7a2355d6fecc4b5c0b6bd44cc31df247a2e", - "0x2191ef87e392377ec08e7c08eb105ef5448eced5", - "0x0f4f2ac550a1b4e2280d04c21cea7ebd822934b5", - "0x6330a553fc93768f612722bb8c2ec78ac90b3bbc", - "0x5aeda56215b167893e80b4fe645ba6d5bab767de" - ] + '0x627306090abab3a6e1400e9345bc60c78a8bef57', + '0xf17f52151ebef6c7334fad080c5704d77216b732', + '0xc5fdf4076b8f3a5357c5e395ab970b5b54098fef', + '0x821aea9a577a9b44299b9c15c88cf3087f3b5544', + '0x0d1d4e623d10f9fba5db95830f7d3839406c6af2', + '0x2932b7a2355d6fecc4b5c0b6bd44cc31df247a2e', + '0x2191ef87e392377ec08e7c08eb105ef5448eced5', + '0x0f4f2ac550a1b4e2280d04c21cea7ebd822934b5', + '0x6330a553fc93768f612722bb8c2ec78ac90b3bbc', + '0x5aeda56215b167893e80b4fe645ba6d5bab767de', + ], } -- cgit From 356cc500956e40b48d78c9dcaf907d498eb707f7 Mon Sep 17 00:00:00 2001 From: kumavis Date: Mon, 18 Jun 2018 12:10:35 -0700 Subject: notice controller - properly show new notices for non-new users --- app/scripts/notice-controller.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'app/scripts') diff --git a/app/scripts/notice-controller.js b/app/scripts/notice-controller.js index e202043cf..2def4371e 100644 --- a/app/scripts/notice-controller.js +++ b/app/scripts/notice-controller.js @@ -13,12 +13,15 @@ module.exports = class NoticeController extends EventEmitter { this.firstVersion = opts.firstVersion this.version = opts.version const initState = extend({ - noticesList: this._filterNotices(hardCodedNotices), + 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 () { @@ -84,8 +87,8 @@ module.exports = class NoticeController extends EventEmitter { } async _retrieveNoticeData () { - // Placeholder for the API. - return [] + // Placeholder for remote notice API. + return hardCodedNotices } _updateMemstore () { -- cgit