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

Add blockaid related event parameters to signature request metrics #20950

Merged
merged 9 commits into from
Sep 27, 2023
14 changes: 14 additions & 0 deletions app/scripts/lib/createRPCMethodTrackingMiddleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ import {
MetaMetricsEventName,
MetaMetricsEventUiCustomization,
} from '../../../shared/constants/metametrics';
///: BEGIN:ONLY_INCLUDE_IN(blockaid)
import {
BlockaidReason,
BlockaidResultType,
} from '../../../shared/constants/security-provider';
///: END:ONLY_INCLUDE_IN

/**
* These types determine how the method tracking middleware handles incoming
Expand Down Expand Up @@ -183,6 +189,14 @@ export default function createRPCMethodTrackingMiddleware({
}
const paramsExamplePassword = req?.params?.[2];

///: BEGIN:ONLY_INCLUDE_IN(blockaid)
eventProperties.security_alert_response =
req.securityAlertResponse?.result_type ??
BlockaidResultType.NotApplicable;
eventProperties.security_alert_reason =
req.securityAlertResponse?.reason ?? BlockaidReason.notApplicable;
///: END:ONLY_INCLUDE_IN

const msgData = {
msgParams: {
...paramsExamplePassword,
Expand Down
10 changes: 10 additions & 0 deletions app/scripts/lib/createRPCMethodTrackingMiddleware.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import {
MetaMetricsEventUiCustomization,
} from '../../../shared/constants/metametrics';
import { SECOND } from '../../../shared/constants/time';
import {
BlockaidReason,
BlockaidResultType,
} from '../../../shared/constants/security-provider';
import createRPCMethodTrackingMiddleware from './createRPCMethodTrackingMiddleware';

const trackEvent = jest.fn();
Expand Down Expand Up @@ -115,6 +119,10 @@ describe('createRPCMethodTrackingMiddleware', () => {
const req = {
method: MESSAGE_TYPE.ETH_SIGN,
origin: 'some.dapp',
securityAlertResponse: {
result_type: BlockaidResultType.Malicious,
reason: BlockaidReason.maliciousDomain,
},
};

const res = {
Expand All @@ -128,6 +136,8 @@ describe('createRPCMethodTrackingMiddleware', () => {
event: MetaMetricsEventName.SignatureRequested,
properties: {
signature_type: MESSAGE_TYPE.ETH_SIGN,
security_alert_response: BlockaidResultType.Malicious,
security_alert_reason: BlockaidReason.maliciousDomain,
},
referrer: { url: 'some.dapp' },
});
Expand Down
Loading