Skip to content

Commit

Permalink
Remove web3 injection (#9156)
Browse files Browse the repository at this point in the history
* Remove web3 injection
* Implement logWeb3ShimUsage
  • Loading branch information
rekmarks authored Dec 7, 2020
1 parent 26272d3 commit 6795298
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 437 deletions.
18 changes: 0 additions & 18 deletions app/scripts/inpage.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@ import log from 'loglevel'
import LocalMessageDuplexStream from 'post-message-stream'
import { initProvider } from '@metamask/inpage-provider'

// TODO:deprecate:2020
import setupWeb3 from './lib/setupWeb3'
/* eslint-enable import/first */

restoreContextAfterImports()

log.setDefaultLevel(process.env.METAMASK_DEBUG ? 'debug' : 'warn')
Expand All @@ -56,17 +52,3 @@ const metamaskStream = new LocalMessageDuplexStream({
initProvider({
connectionStream: metamaskStream,
})

// TODO:deprecate:2020
// Setup web3

if (typeof window.web3 === 'undefined') {
// proxy web3, assign to window, and set up site auto reload
setupWeb3(log)
} else {
log.warn(`MetaMask detected another web3.
MetaMask will not work reliably with another web3 extension.
This usually happens if you have two MetaMasks installed,
or MetaMask and another web3 extension. Please remove one
and try again.`)
}
2 changes: 1 addition & 1 deletion app/scripts/lib/enums.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const MESSAGE_TYPE = {
ETH_GET_ENCRYPTION_PUBLIC_KEY: 'eth_getEncryptionPublicKey',
ETH_SIGN: 'eth_sign',
ETH_SIGN_TYPED_DATA: 'eth_signTypedData',
LOG_WEB3_USAGE: 'metamask_logInjectedWeb3Usage',
LOG_WEB3_SHIM_USAGE: 'metamask_logWeb3ShimUsage',
PERSONAL_SIGN: 'personal_sign',
WATCH_ASSET: 'wallet_watchAsset',
WATCH_ASSET_LEGACY: 'metamask_watchAsset',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ const handlerMap = handlers.reduce((map, handler) => {
* Eventually, we'll want to extract this middleware into its own package.
*
* @param {Object} opts - The middleware options
* @param {string} opts.origin - The origin for the middleware stack
* @param {Function} opts.sendMetrics - A function for sending a metrics event
* @returns {(req: Object, res: Object, next: Function, end: Function) => void}
*/
Expand Down
4 changes: 2 additions & 2 deletions app/scripts/lib/rpc-method-middleware/handlers/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import logWeb3Usage from './log-web3-usage'
import logWeb3ShimUsage from './log-web3-shim-usage'
import watchAsset from './watch-asset'

const handlers = [logWeb3Usage, watchAsset]
const handlers = [logWeb3ShimUsage, watchAsset]
export default handlers
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { MESSAGE_TYPE } from '../../enums'

/**
* This RPC method is called by the inpage provider whenever it detects the
* accessing of a non-existent property on our window.web3 shim.
* We collect this data to understand which sites are breaking due to the
* removal of our window.web3.
*/

const logWeb3ShimUsage = {
methodNames: [MESSAGE_TYPE.LOG_WEB3_SHIM_USAGE],
implementation: logWeb3ShimUsageHandler,
}
export default logWeb3ShimUsage

const recordedWeb3ShimUsage = {}

/**
* @typedef {Object} LogWeb3ShimUsageOptions
* @property {Function} sendMetrics - A function that registers a metrics event.
*/

/**
* @param {import('json-rpc-engine').JsonRpcRequest<unknown>} req - The JSON-RPC request object.
* @param {import('json-rpc-engine').JsonRpcResponse<true>} res - The JSON-RPC response object.
* @param {Function} _next - The json-rpc-engine 'next' callback.
* @param {Function} end - The json-rpc-engine 'end' callback.
* @param {LogWeb3ShimUsageOptions} options
*/
function logWeb3ShimUsageHandler(req, res, _next, end, { sendMetrics }) {
const { origin } = req
if (!recordedWeb3ShimUsage[origin]) {
recordedWeb3ShimUsage[origin] = true

sendMetrics({
event: `Website Accessed window.web3 Shim`,
category: 'inpage_provider',
eventContext: {
referrer: {
url: origin,
},
},
excludeMetaMetricsId: true,
})
}

res.result = true
return end()
}
63 changes: 0 additions & 63 deletions app/scripts/lib/rpc-method-middleware/handlers/log-web3-usage.js

This file was deleted.

Loading

0 comments on commit 6795298

Please sign in to comment.