-
Notifications
You must be signed in to change notification settings - Fork 5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Remove web3 injection * Implement logWeb3ShimUsage
- Loading branch information
Showing
8 changed files
with
52 additions
and
437 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
49 changes: 49 additions & 0 deletions
49
app/scripts/lib/rpc-method-middleware/handlers/log-web3-shim-usage.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
63
app/scripts/lib/rpc-method-middleware/handlers/log-web3-usage.js
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.