Skip to content

Commit

Permalink
Add web3 deprecation warning (#7334)
Browse files Browse the repository at this point in the history
* Add web3 deprecation warning

* Update web3 deprecation article URL
  • Loading branch information
whymarrh authored Nov 1, 2019
1 parent 3060632 commit 6bd87e1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 21 deletions.
21 changes: 0 additions & 21 deletions app/scripts/inpage.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,27 +174,6 @@ 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) => {
// 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) {
web3.eth.defaultAccount = state.selectedAddress
Expand Down
6 changes: 6 additions & 0 deletions app/scripts/lib/auto-reload.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,17 @@ function setupDappAutoReload (web3, observable) {
let reloadInProgress = false
let lastTimeUsed
let lastSeenNetwork
let hasBeenWarned = false

global.web3 = new Proxy(web3, {
get: (_web3, key) => {
// get the time of use
lastTimeUsed = Date.now()
// 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://medium.com/metamask/4a899ad6e59e')
hasBeenWarned = true
}
// return value normally
return _web3[key]
},
Expand Down

0 comments on commit 6bd87e1

Please sign in to comment.