Skip to content

Commit

Permalink
Add blockaid related event parameters to signature request metrics (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
jpuri authored Sep 27, 2023
1 parent 7317e63 commit d4ba5e0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
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

0 comments on commit d4ba5e0

Please sign in to comment.