mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-30 16:18:07 +01:00
885125ad03
See [`no-case-declarations`](https://eslint.org/docs/rules/no-case-declarations) for more information. This change enables `no-case-declarations` and fixes the issues raised by the rule.
34 lines
862 B
JavaScript
34 lines
862 B
JavaScript
/**
|
|
* Returns a middleware that implements the following RPC methods:
|
|
* - metamask_logInjectedWeb3Usage
|
|
*
|
|
* @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: any, res: any, next: Function, end: Function) => void}
|
|
*/
|
|
export default function createMethodMiddleware ({ origin, sendMetrics }) {
|
|
return function methodMiddleware (req, res, next, end) {
|
|
switch (req.method) {
|
|
|
|
case 'metamask_logInjectedWeb3Usage': {
|
|
|
|
const { action, name } = req.params[0]
|
|
|
|
sendMetrics({
|
|
action,
|
|
name,
|
|
customVariables: { origin },
|
|
})
|
|
|
|
res.result = true
|
|
break
|
|
}
|
|
|
|
default:
|
|
return next()
|
|
}
|
|
return end()
|
|
}
|
|
}
|