Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add metrics for provider calls coming from ppom on extension #21482

Merged
merged 2 commits into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions app/scripts/lib/createRPCMethodTrackingMiddleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,16 @@ export default function createRPCMethodTrackingMiddleware({
const paramsExamplePassword = req?.params?.[2];

///: BEGIN:ONLY_INCLUDE_IN(blockaid)
if (req.securityAlertResponse?.providerRequestsCount) {
Object.keys(req.securityAlertResponse.providerRequestsCount).forEach(
(key) => {
const metricKey = `ppom_${key}_count`;
eventProperties[metricKey] =
req.securityAlertResponse.providerRequestsCount[key];
},
);
}

eventProperties.security_alert_response =
req.securityAlertResponse?.result_type ??
BlockaidResultType.NotApplicable;
Expand Down
41 changes: 41 additions & 0 deletions app/scripts/lib/createRPCMethodTrackingMiddleware.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,47 @@ describe('createRPCMethodTrackingMiddleware', () => {
});
});

it(`should track an event with correct blockaid parameters when providerRequestsCount is provided`, async () => {
const req = {
method: MESSAGE_TYPE.ETH_SIGN,
origin: 'some.dapp',
securityAlertResponse: {
result_type: BlockaidResultType.Malicious,
reason: BlockaidReason.maliciousDomain,
providerRequestsCount: {
eth_call: 5,
eth_getCode: 3,
},
},
};

const res = {
error: null,
};
const { next } = getNext();
await handler(req, res, next);
expect(trackEvent).toHaveBeenCalledTimes(1);
/**
* TODO:
* toMatchObject matches even if the the matched object does not contain some of the properties of the expected object
* I'm not sure why toMatchObject is used but we should probably check the other tests in this file for correctness in
* another PR.
*
*/
expect(trackEvent.mock.calls[0][0]).toStrictEqual({
category: 'inpage_provider',
event: MetaMetricsEventName.SignatureRequested,
properties: {
signature_type: MESSAGE_TYPE.ETH_SIGN,
security_alert_response: BlockaidResultType.Malicious,
security_alert_reason: BlockaidReason.maliciousDomain,
ppom_eth_call_count: 5,
ppom_eth_getCode_count: 3,
},
referrer: { url: 'some.dapp' },
});
});

it(`should track a ${MetaMetricsEventName.SignatureApproved} event if the user approves`, async () => {
const req = {
method: MESSAGE_TYPE.ETH_SIGN_TYPED_DATA_V4,
Expand Down
Loading
Loading