From c4494513c2646e5c7bd048224ce464d9c2cccc24 Mon Sep 17 00:00:00 2001 From: Jyoti Puri Date: Tue, 19 Sep 2023 15:40:49 +0530 Subject: [PATCH 1/3] Add blockaid related event parameters to signature request metrics --- app/scripts/lib/createRPCMethodTrackingMiddleware.js | 12 ++++++++++++ .../lib/createRPCMethodTrackingMiddleware.test.js | 10 ++++++++++ 2 files changed, 22 insertions(+) diff --git a/app/scripts/lib/createRPCMethodTrackingMiddleware.js b/app/scripts/lib/createRPCMethodTrackingMiddleware.js index d34404beb4be..5cef8431a7f1 100644 --- a/app/scripts/lib/createRPCMethodTrackingMiddleware.js +++ b/app/scripts/lib/createRPCMethodTrackingMiddleware.js @@ -11,6 +11,10 @@ import { MetaMetricsEventName, MetaMetricsEventUiCustomization, } from '../../../shared/constants/metametrics'; +import { + BlockaidReason, + BlockaidResultType, +} from '../../../shared/constants/security-provider'; /** * These types determine how the method tracking middleware handles incoming @@ -183,6 +187,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, diff --git a/app/scripts/lib/createRPCMethodTrackingMiddleware.test.js b/app/scripts/lib/createRPCMethodTrackingMiddleware.test.js index 5da8206fa763..490d7cc6109f 100644 --- a/app/scripts/lib/createRPCMethodTrackingMiddleware.test.js +++ b/app/scripts/lib/createRPCMethodTrackingMiddleware.test.js @@ -7,6 +7,10 @@ import { } from '../../../shared/constants/metametrics'; import { SECOND } from '../../../shared/constants/time'; import createRPCMethodTrackingMiddleware from './createRPCMethodTrackingMiddleware'; +import { + BlockaidReason, + BlockaidResultType, +} from '../../../shared/constants/security-provider'; const trackEvent = jest.fn(); const metricsState = { participateInMetaMetrics: null }; @@ -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 = { @@ -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' }, }); From b48494070b5df937d9d57b1400bfb99fd699d7f9 Mon Sep 17 00:00:00 2001 From: Jyoti Puri Date: Tue, 19 Sep 2023 15:42:40 +0530 Subject: [PATCH 2/3] Add blockaid related event parameters to signature request metrics --- app/scripts/lib/createRPCMethodTrackingMiddleware.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/scripts/lib/createRPCMethodTrackingMiddleware.test.js b/app/scripts/lib/createRPCMethodTrackingMiddleware.test.js index 490d7cc6109f..16c83c31f2b2 100644 --- a/app/scripts/lib/createRPCMethodTrackingMiddleware.test.js +++ b/app/scripts/lib/createRPCMethodTrackingMiddleware.test.js @@ -6,11 +6,11 @@ import { MetaMetricsEventUiCustomization, } from '../../../shared/constants/metametrics'; import { SECOND } from '../../../shared/constants/time'; -import createRPCMethodTrackingMiddleware from './createRPCMethodTrackingMiddleware'; import { BlockaidReason, BlockaidResultType, } from '../../../shared/constants/security-provider'; +import createRPCMethodTrackingMiddleware from './createRPCMethodTrackingMiddleware'; const trackEvent = jest.fn(); const metricsState = { participateInMetaMetrics: null }; From 33a308b55fa842cbe7f40868bc576fd9c71bfff2 Mon Sep 17 00:00:00 2001 From: Jyoti Puri Date: Tue, 19 Sep 2023 18:17:07 +0530 Subject: [PATCH 3/3] Add blockaid related event parameters to signature request metrics --- app/scripts/lib/createRPCMethodTrackingMiddleware.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/scripts/lib/createRPCMethodTrackingMiddleware.js b/app/scripts/lib/createRPCMethodTrackingMiddleware.js index 5cef8431a7f1..bd9e4b357998 100644 --- a/app/scripts/lib/createRPCMethodTrackingMiddleware.js +++ b/app/scripts/lib/createRPCMethodTrackingMiddleware.js @@ -11,10 +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