Skip to content

Commit 2f5e64c

Browse files
digiwandseaona
authored andcommitted
[Bug|Feat] blockaid external link clicked metric update (#22631)
## **Description** Various updates related to Blockaid metrics ### Fixes - Remove duplicate SignatureRequested SIWE event - related: #21955) - Removes `security_alert_response` and `security_alert_reason` transaction, event fragment prop if unnecessary. Previously would add "not applicable" values to all transaction metrics. ### Feat - Add 'external_link_clicked' transaction fragment prop - Add `security_alert_failed ` ui_customization metric prop - Removes ExternalLinkClicked from "Report an issue" click - related: #22667 - Add test coverage: - utils/metrics: - test not applicable resultType and reason - test when type is failed, malicious, and benign ### Cleanup - removes current MetaMetricsEventName.ExternalLinkClicked / onSupportLinkClicked metric events for Blockaid - adds external_link_clicked fragment prop to transaction metrics related to Blockaid - `let uiCustomizations` → `const uiCustomizations = [];` - other various cleanup e.g.: - rename variables - update test phrases ## **Related issues** Fixes: MetaMask/MetaMask-planning#1756 ## **Manual testing steps** ## **Screenshots/Recordings** <!-- If applicable, add screenshots and/or recordings to visualize the before and after of your change. --> ### **Before** <!-- [screenshots/recordings] --> ### **After** <!-- [screenshots/recordings] --> ## **Pre-merge author checklist** - [ ] I’ve followed [MetaMask Coding Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md). - [ ] I've clearly explained what problem this PR is solving and how it is solved. - [ ] I've linked related issues - [ ] I've included manual testing steps - [ ] I've included screenshots/recordings if applicable - [ ] I’ve included tests if applicable - [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [ ] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. - [ ] I’ve properly set the pull request status: - [ ] In case it's not yet "ready for review", I've set it to "draft". - [ ] In case it's "ready for review", I've changed it from "draft" to "non-draft". ## **Pre-merge reviewer checklist** - [ ] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [ ] I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.
1 parent 0c433f6 commit 2f5e64c

File tree

16 files changed

+352
-347
lines changed

16 files changed

+352
-347
lines changed

app/scripts/lib/transaction/metrics.test.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,6 @@ describe('Transaction metrics', () => {
135135
gas_edit_type: 'none',
136136
network: mockNetworkId,
137137
referrer: ORIGIN_METAMASK,
138-
security_alert_reason: BlockaidReason.notApplicable,
139-
security_alert_response: BlockaidReason.notApplicable,
140138
source: MetaMetricsTransactionEventSource.User,
141139
status: 'unapproved',
142140
token_standard: TokenStandard.none,

app/scripts/lib/transaction/metrics.ts

Lines changed: 18 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import {
2525
MetaMetricsEventCategory,
2626
MetaMetricsEventFragment,
2727
MetaMetricsEventName,
28+
MetaMetricsEventUiCustomization,
2829
MetaMetricsPageObject,
2930
MetaMetricsReferrerObject,
3031
} from '../../../../shared/constants/metametrics';
@@ -35,11 +36,7 @@ import {
3536
TRANSACTION_ENVELOPE_TYPE_NAMES,
3637
} from '../../../../shared/lib/transactions-controller-utils';
3738
///: BEGIN:ONLY_INCLUDE_IF(blockaid)
38-
import {
39-
BlockaidReason,
40-
BlockaidResultType,
41-
} from '../../../../shared/constants/security-provider';
42-
import { getBlockaidMetricsParams } from '../../../../ui/helpers/utils/metrics';
39+
import { getBlockaidMetricsProps } from '../../../../ui/helpers/utils/metrics';
4340
///: END:ONLY_INCLUDE_IF
4441
import {
4542
getSnapAndHardwareInfoForMetrics,
@@ -763,9 +760,6 @@ async function buildEventFragmentProperties({
763760
finalApprovalAmount,
764761
contractMethodName,
765762
securityProviderResponse,
766-
///: BEGIN:ONLY_INCLUDE_IF(blockaid)
767-
securityAlertResponse,
768-
///: END:ONLY_INCLUDE_IF
769763
simulationFails,
770764
} = transactionMeta;
771765
const query = new EthQuery(transactionMetricsRequest.provider);
@@ -928,37 +922,30 @@ async function buildEventFragmentProperties({
928922
}
929923
}
930924

931-
let uiCustomizations;
932-
let additionalBlockaidParams;
925+
const uiCustomizations = [];
933926

927+
/** securityProviderResponse is used by the OpenSea <> Blockaid provider */
934928
// eslint-disable-next-line no-lonely-if
935929
if (securityProviderResponse?.flagAsDangerous === 1) {
936-
uiCustomizations = ['flagged_as_malicious'];
930+
uiCustomizations.push(MetaMetricsEventUiCustomization.FlaggedAsMalicious);
937931
} else if (securityProviderResponse?.flagAsDangerous === 2) {
938-
uiCustomizations = ['flagged_as_safety_unknown'];
939-
} else {
940-
uiCustomizations = null;
932+
uiCustomizations.push(
933+
MetaMetricsEventUiCustomization.FlaggedAsSafetyUnknown,
934+
);
941935
}
942936

943937
///: BEGIN:ONLY_INCLUDE_IF(blockaid)
944-
if (securityAlertResponse?.result_type === BlockaidResultType.Failed) {
945-
uiCustomizations = ['security_alert_failed'];
946-
} else {
947-
additionalBlockaidParams = getBlockaidMetricsParams(
948-
securityAlertResponse as any,
949-
);
950-
uiCustomizations = additionalBlockaidParams?.ui_customizations ?? null;
951-
}
938+
const blockaidProperties: any = getBlockaidMetricsProps(transactionMeta);
952939

940+
if (blockaidProperties?.ui_customizations?.length > 0) {
941+
uiCustomizations.push(...blockaidProperties.ui_customizations);
942+
}
953943
///: END:ONLY_INCLUDE_IF
954944

955945
if (simulationFails) {
956-
if (uiCustomizations === null) {
957-
uiCustomizations = ['gas_estimation_failed'];
958-
} else {
959-
uiCustomizations.push('gas_estimation_failed');
960-
}
946+
uiCustomizations.push(MetaMetricsEventUiCustomization.GasEstimationFailed);
961947
}
948+
962949
/** The transaction status property is not considered sensitive and is now included in the non-anonymous event */
963950
let properties = {
964951
chain_id: chainId,
@@ -969,6 +956,7 @@ async function buildEventFragmentProperties({
969956
eip_1559_version: eip1559Version,
970957
gas_edit_type: 'none',
971958
gas_edit_attempted: 'none',
959+
gas_estimation_failed: Boolean(simulationFails),
972960
account_type: await transactionMetricsRequest.getAccountType(
973961
transactionMetricsRequest.getSelectedAddress(),
974962
),
@@ -979,15 +967,11 @@ async function buildEventFragmentProperties({
979967
token_standard: tokenStandard,
980968
transaction_type: transactionType,
981969
transaction_speed_up: type === TransactionType.retry,
982-
...additionalBlockaidParams,
983-
ui_customizations: uiCustomizations?.length > 0 ? uiCustomizations : null,
984970
///: BEGIN:ONLY_INCLUDE_IF(blockaid)
985-
security_alert_response:
986-
securityAlertResponse?.result_type ?? BlockaidResultType.NotApplicable,
987-
security_alert_reason:
988-
securityAlertResponse?.reason ?? BlockaidReason.notApplicable,
971+
...blockaidProperties,
989972
///: END:ONLY_INCLUDE_IF
990-
gas_estimation_failed: Boolean(simulationFails),
973+
// ui_customizations must come after ...blockaidProperties
974+
ui_customizations: uiCustomizations.length > 0 ? uiCustomizations : null,
991975
} as Record<string, any>;
992976

993977
const snapAndHardwareInfo = await getSnapAndHardwareInfoForMetrics(

shared/constants/metametrics.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,11 @@ export const REJECT_NOTIFICATION_CLOSE = 'Cancel Via Notification Close';
492492
export const REJECT_NOTIFICATION_CLOSE_SIG =
493493
'Cancel Sig Request Via Notification Close';
494494

495+
/**
496+
* The name of the event. Event definitions with corresponding properties can be found in the following document:
497+
*
498+
* @see {@link https://www.notion.so/f2997ab32326441793ff790ba5c60a6a?v=267d984721cd4a26be610b5caa3e25b7&pvs=4}
499+
*/
495500
export enum MetaMetricsEventName {
496501
AccountAdded = 'Account Added',
497502
AccountAddSelected = 'Account Add Selected',
@@ -754,7 +759,9 @@ export enum MetaMetricsEventLocation {
754759
export enum MetaMetricsEventUiCustomization {
755760
FlaggedAsMalicious = 'flagged_as_malicious',
756761
FlaggedAsSafetyUnknown = 'flagged_as_safety_unknown',
762+
FlaggedAsWarning = 'flagged_as_warning',
757763
GasEstimationFailed = 'gas_estimation_failed',
764+
SecurityAlertFailed = 'security_alert_failed',
758765
Siwe = 'sign_in_with_ethereum',
759766
}
760767

ui/components/app/security-provider-banner-alert/blockaid-banner-alert/blockaid-banner-alert.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
Severity,
1010
} from '../../../../helpers/constants/design-system';
1111
import { I18nContext } from '../../../../contexts/i18n';
12+
import { useTransactionEventFragment } from '../../../../hooks/useTransactionEventFragment';
1213
import {
1314
BlockaidReason,
1415
BlockaidResultType,
@@ -57,6 +58,7 @@ function BlockaidBannerAlert({ txData, ...props }) {
5758
txData;
5859

5960
const t = useContext(I18nContext);
61+
const { updateTransactionEventFragment } = useTransactionEventFragment();
6062

6163
if (
6264
!securityAlertResponse ||
@@ -121,6 +123,17 @@ function BlockaidBannerAlert({ txData, ...props }) {
121123

122124
const reportUrl = getReportUrl(encodedData);
123125

126+
const onClickSupportLink = () => {
127+
updateTransactionEventFragment(
128+
{
129+
properties: {
130+
external_link_clicked: 'security_alert_support_link',
131+
},
132+
},
133+
txData.id,
134+
);
135+
};
136+
124137
return (
125138
<SecurityProviderBannerAlert
126139
description={description}
@@ -129,6 +142,7 @@ function BlockaidBannerAlert({ txData, ...props }) {
129142
severity={severity}
130143
title={title}
131144
reportUrl={reportUrl}
145+
onClickSupportLink={onClickSupportLink}
132146
{...props}
133147
/>
134148
);

0 commit comments

Comments
 (0)