From 53e410167b25b8914fa927efc822515d6b22e0ee Mon Sep 17 00:00:00 2001 From: kumavis Date: Wed, 23 Aug 2017 16:13:33 -0700 Subject: inpage provider - sync rpc - default to null values --- app/scripts/lib/inpage-provider.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/scripts/lib/inpage-provider.js b/app/scripts/lib/inpage-provider.js index fd032a673..8b36b4433 100644 --- a/app/scripts/lib/inpage-provider.js +++ b/app/scripts/lib/inpage-provider.js @@ -27,7 +27,7 @@ function MetamaskInpageProvider (connectionStream) { ) // ignore phishing warning message (handled elsewhere) - multiStream.ignoreStream('phishing') + multiStream.ignoreStream('phishing') // connect to async provider const asyncProvider = self.asyncProvider = new StreamProvider() @@ -80,7 +80,7 @@ MetamaskInpageProvider.prototype.send = function (payload) { case 'eth_coinbase': // read from localStorage selectedAddress = self.publicConfigStore.getState().selectedAddress - result = selectedAddress + result = selectedAddress || null break case 'eth_uninstallFilter': @@ -90,7 +90,7 @@ MetamaskInpageProvider.prototype.send = function (payload) { case 'net_version': const networkVersion = self.publicConfigStore.getState().networkVersion - result = networkVersion + result = networkVersion || null break // throw not-supported Error -- cgit v1.2.3 From 44dc2ba7128704f26bf2a530aa24c2a62b862b75 Mon Sep 17 00:00:00 2001 From: kumavis Date: Wed, 23 Aug 2017 16:26:55 -0700 Subject: inpage provider - only warn web3 usage once per session --- app/scripts/lib/auto-reload.js | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/app/scripts/lib/auto-reload.js b/app/scripts/lib/auto-reload.js index 6abce73ea..f3566cff5 100644 --- a/app/scripts/lib/auto-reload.js +++ b/app/scripts/lib/auto-reload.js @@ -2,17 +2,22 @@ module.exports = setupDappAutoReload function setupDappAutoReload (web3, observable) { // export web3 as a global, checking for usage + let hasBeenWarned = false global.web3 = new Proxy(web3, { - get: (_web3, name) => { - // get the time of use - if (name !== '_used') { + 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/ethereum/mist/releases/tag/v0.9.0') + hasBeenWarned = true + } + // get the time of use + if (key !== '_used') { _web3._used = Date.now() } - return _web3[name] + return _web3[key] }, - set: (_web3, name, value) => { - _web3[name] = value + set: (_web3, key, value) => { + _web3[key] = value }, }) var networkVersion -- cgit v1.2.3 From 4019f318fe48e85ac7325ac1cb942c230644547c Mon Sep 17 00:00:00 2001 From: kumavis Date: Wed, 23 Aug 2017 16:44:57 -0700 Subject: inpage provider - autoreload - improve readability --- app/scripts/lib/auto-reload.js | 47 ++++++++++++++++++++++++++++-------------- 1 file changed, 32 insertions(+), 15 deletions(-) diff --git a/app/scripts/lib/auto-reload.js b/app/scripts/lib/auto-reload.js index f3566cff5..62aaf405c 100644 --- a/app/scripts/lib/auto-reload.js +++ b/app/scripts/lib/auto-reload.js @@ -3,6 +3,10 @@ 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 @@ -11,29 +15,42 @@ function setupDappAutoReload (web3, observable) { hasBeenWarned = true } // get the time of use - if (key !== '_used') { - _web3._used = Date.now() - } + lastTimeUsed = Date.now() + // return value normally return _web3[key] }, set: (_web3, key, value) => { + // set value normally _web3[key] = value }, }) - var networkVersion observable.subscribe(function (state) { - // get the initial network - const curentNetVersion = state.networkVersion - if (!networkVersion) networkVersion = curentNetVersion - - if (curentNetVersion !== networkVersion && web3._used) { - const timeSinceUse = Date.now() - web3._used - // if web3 was recently used then delay the reloading of the page - timeSinceUse > 500 ? triggerReset() : setTimeout(triggerReset, 500) - // prevent reentry into if statement if state updates again before - // reload - networkVersion = curentNetVersion + // 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) } }) } -- cgit v1.2.3 From e294aa7e0dd4c773c7724f0fb152cfafece431fe Mon Sep 17 00:00:00 2001 From: kumavis Date: Mon, 28 Aug 2017 10:41:01 -0700 Subject: inpage - lint fix --- app/scripts/lib/inpage-provider.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/scripts/lib/inpage-provider.js b/app/scripts/lib/inpage-provider.js index 8b36b4433..7c74a62d3 100644 --- a/app/scripts/lib/inpage-provider.js +++ b/app/scripts/lib/inpage-provider.js @@ -90,7 +90,7 @@ MetamaskInpageProvider.prototype.send = function (payload) { case 'net_version': const networkVersion = self.publicConfigStore.getState().networkVersion - result = networkVersion || null + result = networkVersion || null break // throw not-supported Error -- cgit v1.2.3 From 6bff55ba2ae36a1d005b052940d91e6e43262359 Mon Sep 17 00:00:00 2001 From: kumavis Date: Mon, 28 Aug 2017 11:29:13 -0700 Subject: inpage - add changelog note --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d2b6572da..28e7ec92d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ ## Current Master +- Make eth_sign deprecation warning less noisy +- Fix bug with network version serialization over synchronous RPC + ## 3.9.10 2017-8-23 - Improve nonce calculation, to prevent bug where people are unable to send transactions reliably. -- cgit v1.2.3