Skip to content

Commit

Permalink
Prevent web3 shim identifier from being overwritten (MetaMask#115)
Browse files Browse the repository at this point in the history
  • Loading branch information
rekmarks authored Dec 2, 2020
1 parent 6edacf9 commit be4174b
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/shimWeb3.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,17 @@
module.exports = function shimWeb3 (provider) {
if (!window.web3) {
const SHIM_IDENTIFIER = '__isMetaMaskShim__'
const web3Shim = new Proxy(
{
currentProvider: provider,
[SHIM_IDENTIFIER]: true,
},

let web3Shim = { currentProvider: provider }
Object.defineProperty(web3Shim, SHIM_IDENTIFIER, {
value: true,
enumerable: true,
configurable: false,
writable: false,
})

web3Shim = new Proxy(
web3Shim,
{
get: (target, property, ...args) => {
if (property === 'currentProvider') {
Expand Down

0 comments on commit be4174b

Please sign in to comment.