mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Fix minor issues with web3 metrics (#9895)
* Fix minor issues with web3 metrics * Log error, use try/catch
This commit is contained in:
parent
daf783a0d8
commit
2687163dbb
@ -71,15 +71,19 @@ 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) => {
|
||||||
window.ethereum.request({
|
try {
|
||||||
method: 'metamask_logInjectedWeb3Usage',
|
window.ethereum.request({
|
||||||
params: [
|
method: 'metamask_logInjectedWeb3Usage',
|
||||||
{
|
params: [
|
||||||
action: 'apply',
|
{
|
||||||
path,
|
action: 'apply',
|
||||||
},
|
path,
|
||||||
],
|
},
|
||||||
})
|
],
|
||||||
|
})
|
||||||
|
} 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,15 +97,19 @@ export default function setupWeb3(log) {
|
|||||||
const name = stringifyKey(key)
|
const name = stringifyKey(key)
|
||||||
|
|
||||||
if (getTrapKeys.has(name)) {
|
if (getTrapKeys.has(name)) {
|
||||||
window.ethereum.request({
|
try {
|
||||||
method: 'metamask_logInjectedWeb3Usage',
|
window.ethereum.request({
|
||||||
params: [
|
method: 'metamask_logInjectedWeb3Usage',
|
||||||
{
|
params: [
|
||||||
action: 'get',
|
{
|
||||||
path: getTrapKeys.get(name),
|
action: 'get',
|
||||||
},
|
path: getTrapKeys.get(name),
|
||||||
],
|
},
|
||||||
})
|
],
|
||||||
|
})
|
||||||
|
} catch (error) {
|
||||||
|
log.debug('Failed to log web3 usage.', error)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// return value normally
|
// return value normally
|
||||||
@ -109,47 +117,51 @@ export default function setupWeb3(log) {
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const topLevelFunctions = [
|
||||||
|
'isConnected',
|
||||||
|
'setProvider',
|
||||||
|
'reset',
|
||||||
|
'sha3',
|
||||||
|
'toHex',
|
||||||
|
'toAscii',
|
||||||
|
'fromAscii',
|
||||||
|
'toDecimal',
|
||||||
|
'fromDecimal',
|
||||||
|
'fromWei',
|
||||||
|
'toWei',
|
||||||
|
'toBigNumber',
|
||||||
|
'isAddress',
|
||||||
|
]
|
||||||
|
|
||||||
|
// apply-trap top-level functions
|
||||||
|
topLevelFunctions.forEach((key) => {
|
||||||
|
// This type check is probably redundant, but we've been burned before.
|
||||||
|
if (typeof web3[key] === 'function') {
|
||||||
|
web3[key] = new Proxy(web3[key], {
|
||||||
|
apply: (...params) => {
|
||||||
|
try {
|
||||||
|
window.ethereum.request({
|
||||||
|
method: 'metamask_logInjectedWeb3Usage',
|
||||||
|
params: [
|
||||||
|
{
|
||||||
|
action: 'apply',
|
||||||
|
path: `web3.${key}`,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
})
|
||||||
|
} catch (error) {
|
||||||
|
log.debug('Failed to log web3 usage.', error)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Call function normally
|
||||||
|
return Reflect.apply(...params)
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const topLevelFunctions = [
|
|
||||||
'isConnected',
|
|
||||||
'setProvider',
|
|
||||||
'reset',
|
|
||||||
'sha3',
|
|
||||||
'toHex',
|
|
||||||
'toAscii',
|
|
||||||
'fromAscii',
|
|
||||||
'toDecimal',
|
|
||||||
'fromDecimal',
|
|
||||||
'fromWei',
|
|
||||||
'toWei',
|
|
||||||
'toBigNumber',
|
|
||||||
'isAddress',
|
|
||||||
]
|
|
||||||
|
|
||||||
// apply-trap top-level functions
|
|
||||||
topLevelFunctions.forEach((key) => {
|
|
||||||
// This type check is probably redundant, but we've been burned before.
|
|
||||||
if (typeof web3[key] === 'function') {
|
|
||||||
web3[key] = new Proxy(web3[key], {
|
|
||||||
apply: (...params) => {
|
|
||||||
window.ethereum.request({
|
|
||||||
method: 'metamask_logInjectedWeb3Usage',
|
|
||||||
params: [
|
|
||||||
{
|
|
||||||
action: 'apply',
|
|
||||||
path: `web3.${key}`,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
})
|
|
||||||
|
|
||||||
// Call function normally
|
|
||||||
return Reflect.apply(...params)
|
|
||||||
},
|
|
||||||
})
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
const web3Proxy = new Proxy(web3, {
|
const web3Proxy = new Proxy(web3, {
|
||||||
get: (...params) => {
|
get: (...params) => {
|
||||||
// get the time of use
|
// get the time of use
|
||||||
|
Loading…
x
Reference in New Issue
Block a user