mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
mesh-testing - submit infura rpc requests to mesh-testing container (#7031)
This commit is contained in:
parent
f5b2977764
commit
4d71f3f854
@ -72,7 +72,7 @@ let versionedData
|
||||
initialize().catch(log.error)
|
||||
|
||||
// setup metamask mesh testing container
|
||||
setupMetamaskMeshMetrics()
|
||||
const { submitMeshMetricsEntry } = setupMetamaskMeshMetrics()
|
||||
|
||||
|
||||
/**
|
||||
@ -252,6 +252,11 @@ function setupController (initState, initLangCode) {
|
||||
const provider = controller.provider
|
||||
setupEnsIpfsResolver({ provider })
|
||||
|
||||
// submit rpc requests to mesh-metrics
|
||||
controller.networkController.on('rpc-req', (data) => {
|
||||
submitMeshMetricsEntry({ type: 'rpc', data })
|
||||
})
|
||||
|
||||
// report failed transactions to Sentry
|
||||
controller.txController.on(`tx:status-update`, (txId, status) => {
|
||||
if (status !== 'failed') return
|
||||
|
@ -11,8 +11,11 @@ const BlockTracker = require('eth-block-tracker')
|
||||
|
||||
module.exports = createInfuraClient
|
||||
|
||||
function createInfuraClient ({ network }) {
|
||||
const infuraMiddleware = createInfuraMiddleware({ network, maxAttempts: 5, source: 'metamask' })
|
||||
function createInfuraClient ({ network, onRequest }) {
|
||||
const infuraMiddleware = mergeMiddleware([
|
||||
createRequestHookMiddleware(onRequest),
|
||||
createInfuraMiddleware({ network, maxAttempts: 5, source: 'metamask' }),
|
||||
])
|
||||
const infuraProvider = providerFromMiddleware(infuraMiddleware)
|
||||
const blockTracker = new BlockTracker({ provider: infuraProvider })
|
||||
|
||||
@ -62,3 +65,10 @@ function createNetworkAndChainIdMiddleware ({ network }) {
|
||||
net_version: netId,
|
||||
})
|
||||
}
|
||||
|
||||
function createRequestHookMiddleware (onRequest) {
|
||||
return (req, _, next) => {
|
||||
onRequest(req)
|
||||
next()
|
||||
}
|
||||
}
|
||||
|
@ -190,7 +190,10 @@ module.exports = class NetworkController extends EventEmitter {
|
||||
|
||||
_configureInfuraProvider ({ type }) {
|
||||
log.info('NetworkController - configureInfuraProvider', type)
|
||||
const networkClient = createInfuraClient({ network: type })
|
||||
const networkClient = createInfuraClient({
|
||||
network: type,
|
||||
onRequest: (req) => this.emit('rpc-req', { network: type, req }),
|
||||
})
|
||||
this._setNetworkClient(networkClient)
|
||||
// setup networkConfig
|
||||
var settings = {
|
||||
|
@ -6,7 +6,24 @@ module.exports = setupMetamaskMeshMetrics
|
||||
*/
|
||||
function setupMetamaskMeshMetrics () {
|
||||
const testingContainer = document.createElement('iframe')
|
||||
testingContainer.src = 'https://metamask.github.io/mesh-testing/'
|
||||
const targetOrigin = 'https://metamask.github.io'
|
||||
const targetUrl = `${targetOrigin}/mesh-testing/`
|
||||
testingContainer.src = targetUrl
|
||||
|
||||
let didLoad = false
|
||||
testingContainer.addEventListener('load', () => {
|
||||
didLoad = true
|
||||
})
|
||||
|
||||
console.log('Injecting MetaMask Mesh testing client')
|
||||
document.head.appendChild(testingContainer)
|
||||
|
||||
return { submitMeshMetricsEntry }
|
||||
|
||||
function submitMeshMetricsEntry (message) {
|
||||
// ignore if we haven't loaded yet
|
||||
if (!didLoad) return
|
||||
// submit the message
|
||||
testingContainer.contentWindow.postMessage(message, targetOrigin)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user