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

Loading…
Cancel
Save