Skip to content

Commit

Permalink
Fix warning on second currentProvider access (#138)
Browse files Browse the repository at this point in the history
We expose the `currentProvider` property on our shim as a deprecated
way to access to provider, to make the task of migrating dapps away
from our injected web3 instance easier. The intent was to warn if that
property is used, but log an error to the console and inform MetaMask
if any other property is used.

There was a mistake in the logic that caused us to treat subsequent
accesses to `currentProvider` to be treated like some unsupported
property was being accessed. This results in the console error being
shown erroneously, it bloats our web3 usage metrics, and it causes the
warning about web3 usage to appear unnecessarily in the MetaMask UI.

The logic has been updated to never treat `currentProvider` as an
unsupported property. Accessing that property will only result in a
deprecation warning.
  • Loading branch information
Gudahtt authored Feb 4, 2021
1 parent 12c3d84 commit 1bab224
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/shimWeb3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export default function shimWeb3(
log.warn(
'You are accessing the MetaMask window.web3.currentProvider shim. This property is deprecated; use window.ethereum instead. For details, see: https://docs.metamask.io/guide/provider-migration.html#replacing-window-web3',
);
} else if (property !== SHIM_IDENTIFIER && !loggedMissingProperty) {
} else if (property !== 'currentProvider' && property !== SHIM_IDENTIFIER && !loggedMissingProperty) {
loggedMissingProperty = true;
log.error(
`MetaMask no longer injects web3. For details, see: https://docs.metamask.io/guide/provider-migration.html#replacing-window-web3`,
Expand Down

0 comments on commit 1bab224

Please sign in to comment.