Fix minor issues with web3 metrics (#9895)

* Fix minor issues with web3 metrics

* Log error, use try/catch
feature/default_network_editable
Erik Marks 4 years ago committed by GitHub
parent daf783a0d8
commit 2687163dbb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 14
      app/scripts/lib/setupWeb3.js

@ -71,6 +71,7 @@ export default function setupWeb3(log) {
for (const [key, path] of applyTrapKeys) { for (const [key, path] of applyTrapKeys) {
web3[topKey][key] = new Proxy(web3[topKey][key], { web3[topKey][key] = new Proxy(web3[topKey][key], {
apply: (...params) => { apply: (...params) => {
try {
window.ethereum.request({ window.ethereum.request({
method: 'metamask_logInjectedWeb3Usage', method: 'metamask_logInjectedWeb3Usage',
params: [ params: [
@ -80,6 +81,9 @@ export default function setupWeb3(log) {
}, },
], ],
}) })
} catch (error) {
log.debug('Failed to log web3 usage.', error)
}
// Call function normally // Call function normally
return Reflect.apply(...params) return Reflect.apply(...params)
@ -93,6 +97,7 @@ export default function setupWeb3(log) {
const name = stringifyKey(key) const name = stringifyKey(key)
if (getTrapKeys.has(name)) { if (getTrapKeys.has(name)) {
try {
window.ethereum.request({ window.ethereum.request({
method: 'metamask_logInjectedWeb3Usage', method: 'metamask_logInjectedWeb3Usage',
params: [ params: [
@ -102,6 +107,9 @@ export default function setupWeb3(log) {
}, },
], ],
}) })
} catch (error) {
log.debug('Failed to log web3 usage.', error)
}
} }
// return value normally // return value normally
@ -109,7 +117,6 @@ export default function setupWeb3(log) {
}, },
}) })
}) })
}
const topLevelFunctions = [ const topLevelFunctions = [
'isConnected', 'isConnected',
@ -133,6 +140,7 @@ export default function setupWeb3(log) {
if (typeof web3[key] === 'function') { if (typeof web3[key] === 'function') {
web3[key] = new Proxy(web3[key], { web3[key] = new Proxy(web3[key], {
apply: (...params) => { apply: (...params) => {
try {
window.ethereum.request({ window.ethereum.request({
method: 'metamask_logInjectedWeb3Usage', method: 'metamask_logInjectedWeb3Usage',
params: [ params: [
@ -142,6 +150,9 @@ export default function setupWeb3(log) {
}, },
], ],
}) })
} catch (error) {
log.debug('Failed to log web3 usage.', error)
}
// Call function normally // Call function normally
return Reflect.apply(...params) return Reflect.apply(...params)
@ -149,6 +160,7 @@ export default function setupWeb3(log) {
}) })
} }
}) })
}
const web3Proxy = new Proxy(web3, { const web3Proxy = new Proxy(web3, {
get: (...params) => { get: (...params) => {

Loading…
Cancel
Save