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') 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 v1.2.3 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') 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 v1.2.3 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') 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 v1.2.3 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') 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 v1.2.3 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') 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 v1.2.3 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') 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 v1.2.3 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') 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 v1.2.3 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') 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 v1.2.3 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') 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 v1.2.3 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') 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 v1.2.3 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') 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 v1.2.3 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') 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 v1.2.3 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') 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 v1.2.3 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') 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 v1.2.3 From ef31eeccb244592aa17dd677e854e106c9bb5848 Mon Sep 17 00:00:00 2001 From: Thomas Date: Thu, 14 Jun 2018 10:48:38 -0700 Subject: v4.8.0 --- app/manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app') diff --git a/app/manifest.json b/app/manifest.json index e3a7fd963..50b7e3c53 100644 --- a/app/manifest.json +++ b/app/manifest.json @@ -1,7 +1,7 @@ { "name": "__MSG_appName__", "short_name": "__MSG_appName__", - "version": "4.7.4", + "version": "4.8.0", "manifest_version": 2, "author": "https://metamask.io", "description": "__MSG_appDescription__", -- cgit v1.2.3 From bb855707efbcb754f5e4ee4e124f69308bca037d Mon Sep 17 00:00:00 2001 From: Dan Date: Thu, 14 Jun 2018 11:25:55 -0230 Subject: ENS input in send form shows distinct errors for invalid addresses and non-existent addresses. --- app/_locales/en/messages.json | 3 +++ 1 file changed, 3 insertions(+) (limited to 'app') diff --git a/app/_locales/en/messages.json b/app/_locales/en/messages.json index 457c3c3b1..b65d8ac87 100644 --- a/app/_locales/en/messages.json +++ b/app/_locales/en/messages.json @@ -262,6 +262,9 @@ "encryptNewDen": { "message": "Encrypt your new DEN" }, + "ensNameNotFound": { + "message": "ENS name not found" + }, "enterPassword": { "message": "Enter password" }, -- cgit v1.2.3 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') 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 v1.2.3 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') 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 v1.2.3 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') 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 v1.2.3 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') 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 v1.2.3 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') 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 v1.2.3 From 4c1b526137379969d16386f50ca3214d90c67c3f Mon Sep 17 00:00:00 2001 From: vittominacori Date: Sat, 16 Jun 2018 18:51:01 +0200 Subject: set an id to the metamask notification popup --- app/scripts/lib/notification-manager.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'app') diff --git a/app/scripts/lib/notification-manager.js b/app/scripts/lib/notification-manager.js index 5dfb42078..4a5d21e2f 100644 --- a/app/scripts/lib/notification-manager.js +++ b/app/scripts/lib/notification-manager.js @@ -28,6 +28,7 @@ class NotificationManager { } else { // create new notification popup extension.windows.create({ + id: 'metamask-popup', url: 'notification.html', type: 'popup', width, @@ -93,7 +94,7 @@ class NotificationManager { _getPopupIn (windows) { return windows ? windows.find((win) => { // Returns notification popup - return (win && win.type === 'popup') + return (win && win.type === 'popup' && win.id === 'metamask-popup') }) : null } -- cgit v1.2.3 From ff3c2626213afa48151c43947087aae95298d5f6 Mon Sep 17 00:00:00 2001 From: vittominacori Date: Sun, 17 Jun 2018 19:16:30 +0200 Subject: set the popup id returned by create promise --- app/scripts/lib/notification-manager.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'app') diff --git a/app/scripts/lib/notification-manager.js b/app/scripts/lib/notification-manager.js index 4a5d21e2f..6b88a7a99 100644 --- a/app/scripts/lib/notification-manager.js +++ b/app/scripts/lib/notification-manager.js @@ -28,11 +28,12 @@ class NotificationManager { } else { // create new notification popup extension.windows.create({ - id: 'metamask-popup', url: 'notification.html', type: 'popup', width, height, + }).then((currentPopup) => { + this._popupId = currentPopup.id }) } }) @@ -85,7 +86,7 @@ class NotificationManager { } /** - * Given an array of windows, returns the first that has a 'popup' type, or null if no such window exists. + * Given an array of windows, returns the 'popup' that has been opened by MetaMask, or null if no such window exists. * * @private * @param {array} windows An array of objects containing data about the open MetaMask extension windows. @@ -94,7 +95,7 @@ class NotificationManager { _getPopupIn (windows) { return windows ? windows.find((win) => { // Returns notification popup - return (win && win.type === 'popup' && win.id === 'metamask-popup') + return (win && win.type === 'popup' && win.id === this._popupId) }) : null } -- cgit v1.2.3 From 8aab4dd1fa5db1de54af7a029f0a758154572b49 Mon Sep 17 00:00:00 2001 From: Csaba S Date: Mon, 18 Jun 2018 19:29:09 +0200 Subject: View address of an added token (#4591) * adding menu actions for tokens * apply common style --- app/_locales/en/messages.json | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'app') diff --git a/app/_locales/en/messages.json b/app/_locales/en/messages.json index 457c3c3b1..2579da87d 100644 --- a/app/_locales/en/messages.json +++ b/app/_locales/en/messages.json @@ -146,6 +146,9 @@ "copy": { "message": "Copy" }, + "copyContractAddress": { + "message": "Copy Contract Address" + }, "copyToClipboard": { "message": "Copy to clipboard" }, @@ -955,6 +958,9 @@ "viewAccount": { "message": "View Account" }, + "viewOnEtherscan": { + "message": "View on Etherscan" + }, "visitWebSite": { "message": "Visit our web site" }, -- cgit v1.2.3 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') 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 v1.2.3