diff --git a/app/scripts/lib/transaction/metrics.test.ts b/app/scripts/lib/transaction/metrics.test.ts index 82c781461d49..b4fb52e4d366 100644 --- a/app/scripts/lib/transaction/metrics.test.ts +++ b/app/scripts/lib/transaction/metrics.test.ts @@ -17,7 +17,10 @@ import { } from '../../../../shared/constants/metametrics'; import { TRANSACTION_ENVELOPE_TYPE_NAMES } from '../../../../shared/lib/transactions-controller-utils'; ///: BEGIN:ONLY_INCLUDE_IN(blockaid) -import { BlockaidReason } from '../../../../shared/constants/security-provider'; +import { + BlockaidReason, + BlockaidResultType, +} from '../../../../shared/constants/security-provider'; ///: END:ONLY_INCLUDE_IN(blockaid) import { handleTransactionAdded, @@ -107,8 +110,9 @@ describe('Transaction metrics', () => { // copy mockTransactionMeta and add blockaid data mockTransactionMetaWithBlockaid = { ...JSON.parse(JSON.stringify(mockTransactionMeta)), - securityProviderResponse: { - flagAsDangerous: 1, + securityAlertResponse: { + result_type: BlockaidResultType.Malicious, + reason: BlockaidReason.maliciousDomain, providerRequestsCount: { eth_call: 5, eth_getCode: 3, @@ -230,6 +234,8 @@ describe('Transaction metrics', () => { persist: true, properties: { ...expectedProperties, + security_alert_reason: BlockaidReason.maliciousDomain, + security_alert_response: 'Malicious', ui_customizations: ['flagged_as_malicious'], ppom_eth_call_count: 5, ppom_eth_getCode_count: 3, @@ -315,6 +321,8 @@ describe('Transaction metrics', () => { properties: { ...expectedProperties, ui_customizations: ['flagged_as_malicious'], + security_alert_reason: BlockaidReason.maliciousDomain, + security_alert_response: 'Malicious', ppom_eth_call_count: 5, ppom_eth_getCode_count: 3, }, @@ -330,6 +338,8 @@ describe('Transaction metrics', () => { properties: { ...expectedProperties, ui_customizations: ['flagged_as_malicious'], + security_alert_reason: BlockaidReason.maliciousDomain, + security_alert_response: 'Malicious', ppom_eth_call_count: 5, ppom_eth_getCode_count: 3, }, @@ -442,6 +452,8 @@ describe('Transaction metrics', () => { properties: { ...expectedProperties, ui_customizations: ['flagged_as_malicious'], + security_alert_reason: BlockaidReason.maliciousDomain, + security_alert_response: 'Malicious', ppom_eth_call_count: 5, ppom_eth_getCode_count: 3, }, @@ -460,6 +472,8 @@ describe('Transaction metrics', () => { properties: { ...expectedProperties, ui_customizations: ['flagged_as_malicious'], + security_alert_reason: BlockaidReason.maliciousDomain, + security_alert_response: 'Malicious', ppom_eth_call_count: 5, ppom_eth_getCode_count: 3, }, @@ -627,6 +641,8 @@ describe('Transaction metrics', () => { properties: { ...expectedProperties, ui_customizations: ['flagged_as_malicious'], + security_alert_reason: BlockaidReason.maliciousDomain, + security_alert_response: 'Malicious', ppom_eth_call_count: 5, ppom_eth_getCode_count: 3, }, @@ -647,6 +663,8 @@ describe('Transaction metrics', () => { properties: { ...expectedProperties, ui_customizations: ['flagged_as_malicious'], + security_alert_reason: BlockaidReason.maliciousDomain, + security_alert_response: 'Malicious', ppom_eth_call_count: 5, ppom_eth_getCode_count: 3, }, @@ -750,6 +768,8 @@ describe('Transaction metrics', () => { properties: { ...expectedProperties, ui_customizations: ['flagged_as_malicious'], + security_alert_reason: BlockaidReason.maliciousDomain, + security_alert_response: 'Malicious', ppom_eth_call_count: 5, ppom_eth_getCode_count: 3, }, @@ -769,6 +789,8 @@ describe('Transaction metrics', () => { properties: { ...expectedProperties, ui_customizations: ['flagged_as_malicious'], + security_alert_reason: BlockaidReason.maliciousDomain, + security_alert_response: 'Malicious', ppom_eth_call_count: 5, ppom_eth_getCode_count: 3, }, @@ -867,6 +889,8 @@ describe('Transaction metrics', () => { properties: { ...expectedProperties, ui_customizations: ['flagged_as_malicious'], + security_alert_reason: BlockaidReason.maliciousDomain, + security_alert_response: 'Malicious', ppom_eth_call_count: 5, ppom_eth_getCode_count: 3, }, @@ -882,6 +906,8 @@ describe('Transaction metrics', () => { properties: { ...expectedProperties, ui_customizations: ['flagged_as_malicious'], + security_alert_reason: BlockaidReason.maliciousDomain, + security_alert_response: 'Malicious', ppom_eth_call_count: 5, ppom_eth_getCode_count: 3, }, diff --git a/app/scripts/lib/transaction/metrics.ts b/app/scripts/lib/transaction/metrics.ts index 90fed3dbdd8e..5805362c4948 100644 --- a/app/scripts/lib/transaction/metrics.ts +++ b/app/scripts/lib/transaction/metrics.ts @@ -37,6 +37,7 @@ import { BlockaidReason, BlockaidResultType, } from '../../../../shared/constants/security-provider'; +import { getBlockaidMetricsParams } from '../../../../ui/helpers/utils/metrics'; ///: END:ONLY_INCLUDE_IN import { getSnapAndHardwareInfoForMetrics, @@ -926,36 +927,25 @@ async function buildEventFragmentProperties({ } let uiCustomizations; + let additionalBlockaidParams; + + // eslint-disable-next-line no-lonely-if + if (securityProviderResponse?.flagAsDangerous === 1) { + uiCustomizations = ['flagged_as_malicious']; + } else if (securityProviderResponse?.flagAsDangerous === 2) { + uiCustomizations = ['flagged_as_safety_unknown']; + } else { + uiCustomizations = null; + } ///: BEGIN:ONLY_INCLUDE_IN(blockaid) if (securityAlertResponse?.result_type === BlockaidResultType.Failed) { uiCustomizations = ['security_alert_failed']; } else { - ///: END:ONLY_INCLUDE_IN - // eslint-disable-next-line no-lonely-if - if (securityProviderResponse?.flagAsDangerous === 1) { - uiCustomizations = ['flagged_as_malicious']; - } else if (securityProviderResponse?.flagAsDangerous === 2) { - uiCustomizations = ['flagged_as_safety_unknown']; - } else { - uiCustomizations = null; - } - ///: BEGIN:ONLY_INCLUDE_IN(blockaid) + additionalBlockaidParams = getBlockaidMetricsParams(securityAlertResponse); + uiCustomizations = additionalBlockaidParams?.ui_customizations ?? null; } - ///: END:ONLY_INCLUDE_IN - ///: BEGIN:ONLY_INCLUDE_IN(blockaid) - const additionalBlockaidParams = {} as Record; - - if (securityProviderResponse?.providerRequestsCount) { - Object.keys(securityProviderResponse.providerRequestsCount).forEach( - (key) => { - const metricKey = `ppom_${key}_count`; - additionalBlockaidParams[metricKey] = - securityProviderResponse.providerRequestsCount[key]; - }, - ); - } ///: END:ONLY_INCLUDE_IN if (simulationFails) { @@ -985,13 +975,13 @@ async function buildEventFragmentProperties({ token_standard: tokenStandard, transaction_type: transactionType, transaction_speed_up: type === TransactionType.retry, - ui_customizations: uiCustomizations, + ...additionalBlockaidParams, + ui_customizations: uiCustomizations?.length > 0 ? uiCustomizations : null, ///: BEGIN:ONLY_INCLUDE_IN(blockaid) security_alert_response: securityAlertResponse?.result_type ?? BlockaidResultType.NotApplicable, security_alert_reason: securityAlertResponse?.reason ?? BlockaidReason.notApplicable, - ...additionalBlockaidParams, ///: END:ONLY_INCLUDE_IN gas_estimation_failed: Boolean(simulationFails), } as Record; diff --git a/ui/components/app/signature-request-original/signature-request-original.component.js b/ui/components/app/signature-request-original/signature-request-original.component.js index 176bd5c3bce5..b53499c03f7b 100644 --- a/ui/components/app/signature-request-original/signature-request-original.component.js +++ b/ui/components/app/signature-request-original/signature-request-original.component.js @@ -44,11 +44,6 @@ import { ///: END:ONLY_INCLUDE_IN } from '../../component-library'; ///: BEGIN:ONLY_INCLUDE_IN(blockaid) -import { - MetaMetricsEventCategory, - MetaMetricsEventName, -} from '../../../../shared/constants/metametrics'; -import { getBlockaidMetricsParams } from '../../../helpers/utils/metrics'; import BlockaidBannerAlert from '../security-provider-banner-alert/blockaid-banner-alert/blockaid-banner-alert'; ///: END:ONLY_INCLUDE_IN import ConfirmPageContainerNavigation from '../confirm-page-container/confirm-page-container-navigation'; @@ -96,26 +91,6 @@ export default class SignatureRequestOriginal extends Component { showSignatureRequestWarning: false, }; - ///: BEGIN:ONLY_INCLUDE_IN(blockaid) - componentDidMount() { - const { txData } = this.props; - if (txData.securityAlertResponse) { - const blockaidMetricsParams = getBlockaidMetricsParams( - txData.securityAlertResponse, - ); - - this.context.trackEvent({ - category: MetaMetricsEventCategory.Transactions, - event: MetaMetricsEventName.SignatureRequested, - properties: { - action: 'Sign Request', - ...blockaidMetricsParams, - }, - }); - } - } - ///: END:ONLY_INCLUDE_IN - msgHexToText = (hex) => { try { const stripped = stripHexPrefix(hex); diff --git a/ui/components/app/signature-request-siwe/signature-request-siwe.js b/ui/components/app/signature-request-siwe/signature-request-siwe.js index 7d85ea1cf159..e4efee227615 100644 --- a/ui/components/app/signature-request-siwe/signature-request-siwe.js +++ b/ui/components/app/signature-request-siwe/signature-request-siwe.js @@ -89,7 +89,7 @@ export default function SignatureRequestSIWE({ txData }) { }, }); } - }, [txData?.securityAlertResponse]); + }, []); ///: END:ONLY_INCLUDE_IN const { diff --git a/ui/components/app/signature-request/signature-request.js b/ui/components/app/signature-request/signature-request.js index b3ec8c83eb9f..e5de3f67cca0 100644 --- a/ui/components/app/signature-request/signature-request.js +++ b/ui/components/app/signature-request/signature-request.js @@ -96,7 +96,6 @@ import { showCustodyConfirmLink } from '../../../store/institutional/institution import { useMMICustodySignMessage } from '../../../hooks/useMMICustodySignMessage'; ///: END:ONLY_INCLUDE_IN ///: BEGIN:ONLY_INCLUDE_IN(blockaid) -import { getBlockaidMetricsParams } from '../../../helpers/utils/metrics'; import BlockaidBannerAlert from '../security-provider-banner-alert/blockaid-banner-alert/blockaid-banner-alert'; ///: END:ONLY_INCLUDE_IN @@ -256,27 +255,6 @@ const SignatureRequest = ({ txData }) => { ]); ///: END:ONLY_INCLUDE_IN - ///: BEGIN:ONLY_INCLUDE_IN(blockaid) - useEffect(() => { - if (txData.securityAlertResponse) { - const blockaidMetricsParams = getBlockaidMetricsParams( - txData.securityAlertResponse, - ); - - trackEvent({ - category: MetaMetricsEventCategory.Transactions, - event: MetaMetricsEventName.SignatureRequested, - properties: { - action: 'Sign Request', - type, - version, - ...blockaidMetricsParams, - }, - }); - } - }, []); - ///: END:ONLY_INCLUDE_IN - return (
diff --git a/ui/components/app/transaction-alerts/transaction-alerts.js b/ui/components/app/transaction-alerts/transaction-alerts.js index 00f0c6ab58ac..3596aee31b0b 100644 --- a/ui/components/app/transaction-alerts/transaction-alerts.js +++ b/ui/components/app/transaction-alerts/transaction-alerts.js @@ -2,7 +2,6 @@ import React, { ///: BEGIN:ONLY_INCLUDE_IN(blockaid) useCallback, useContext, - useEffect, ///: END:ONLY_INCLUDE_IN } from 'react'; import PropTypes from 'prop-types'; @@ -33,7 +32,6 @@ import { MetaMetricsEventCategory, MetaMetricsEventName, } from '../../../../shared/constants/metametrics'; -import { getBlockaidMetricsParams } from '../../../helpers/utils/metrics'; ///: END:ONLY_INCLUDE_IN const TransactionAlerts = ({ @@ -74,25 +72,6 @@ const TransactionAlerts = ({ const trackEvent = useContext(MetaMetricsContext); ///: END:ONLY_INCLUDE_IN - ///: BEGIN:ONLY_INCLUDE_IN(blockaid) - useEffect(() => { - if (txData.securityAlertResponse) { - const blockaidMetricsParams = getBlockaidMetricsParams( - txData.securityAlertResponse, - ); - - trackEvent({ - category: MetaMetricsEventCategory.Transactions, - event: MetaMetricsEventName.SignatureRequested, - properties: { - action: 'Sign Request', - ...blockaidMetricsParams, - }, - }); - } - }, [txData?.securityAlertResponse]); - ///: END:ONLY_INCLUDE_IN - ///: BEGIN:ONLY_INCLUDE_IN(blockaid) const onClickSupportLink = useCallback(() => { trackEvent({ diff --git a/ui/helpers/utils/metrics.js b/ui/helpers/utils/metrics.js index 796377bcdee6..65f1642767a7 100644 --- a/ui/helpers/utils/metrics.js +++ b/ui/helpers/utils/metrics.js @@ -39,6 +39,10 @@ export const getBlockaidMetricsParams = (securityAlertResponse = null) => { additionalParams.ui_customizations = ['flagged_as_malicious']; } + if (resultType === BlockaidResultType.Failed) { + additionalParams.ui_customizations = ['security_alert_failed']; + } + if (resultType !== BlockaidResultType.Benign) { additionalParams.security_alert_reason = BlockaidReason.notApplicable; diff --git a/ui/pages/confirm-approve/confirm-approve-content/confirm-approve-content.component.js b/ui/pages/confirm-approve/confirm-approve-content/confirm-approve-content.component.js index fe2820637278..e435b9206891 100644 --- a/ui/pages/confirm-approve/confirm-approve-content/confirm-approve-content.component.js +++ b/ui/pages/confirm-approve/confirm-approve-content/confirm-approve-content.component.js @@ -23,11 +23,6 @@ import { ConfirmPageContainerWarning } from '../../../components/app/confirm-pag import LedgerInstructionField from '../../../components/app/ledger-instruction-field'; ///: BEGIN:ONLY_INCLUDE_IN(blockaid) import BlockaidBannerAlert from '../../../components/app/security-provider-banner-alert/blockaid-banner-alert/blockaid-banner-alert'; -import { getBlockaidMetricsParams } from '../../../helpers/utils/metrics'; -import { - MetaMetricsEventCategory, - MetaMetricsEventName, -} from '../../../../shared/constants/metametrics'; ///: END:ONLY_INCLUDE_IN import { isSuspiciousResponse } from '../../../../shared/modules/security-provider.utils'; @@ -103,26 +98,6 @@ export default class ConfirmApproveContent extends Component { setShowContractDetails: false, }; - ///: BEGIN:ONLY_INCLUDE_IN(blockaid) - componentDidMount() { - const { txData } = this.props; - if (txData.securityAlertResponse) { - const blockaidMetricsParams = getBlockaidMetricsParams( - txData.securityAlertResponse, - ); - - this.context.trackEvent({ - category: MetaMetricsEventCategory.Transactions, - event: MetaMetricsEventName.SignatureRequested, - properties: { - action: 'Sign Request', - ...blockaidMetricsParams, - }, - }); - } - } - ///: END:ONLY_INCLUDE_IN - renderApproveContentCard({ showHeader = true, symbol, diff --git a/ui/pages/token-allowance/token-allowance.js b/ui/pages/token-allowance/token-allowance.js index 78ac171323db..2bae6f067205 100644 --- a/ui/pages/token-allowance/token-allowance.js +++ b/ui/pages/token-allowance/token-allowance.js @@ -63,12 +63,6 @@ import { import { isSuspiciousResponse } from '../../../shared/modules/security-provider.utils'; ///: BEGIN:ONLY_INCLUDE_IN(blockaid) import BlockaidBannerAlert from '../../components/app/security-provider-banner-alert/blockaid-banner-alert/blockaid-banner-alert'; -import { getBlockaidMetricsParams } from '../../helpers/utils/metrics'; -import { - MetaMetricsEventCategory, - MetaMetricsEventName, -} from '../../../shared/constants/metametrics'; -import { MetaMetricsContext } from '../../contexts/metametrics'; ///: END:ONLY_INCLUDE_IN import { ConfirmPageContainerNavigation } from '../../components/app/confirm-page-container'; import { useSimulationFailureWarning } from '../../hooks/useSimulationFailureWarning'; @@ -143,29 +137,6 @@ export default function TokenAllowance({ const nextNonce = useSelector(getNextSuggestedNonce); const customNonceValue = useSelector(getCustomNonceValue); - ///: BEGIN:ONLY_INCLUDE_IN(blockaid) - const trackEvent = useContext(MetaMetricsContext); - ///: END:ONLY_INCLUDE_IN - - ///: BEGIN:ONLY_INCLUDE_IN(blockaid) - useEffect(() => { - if (txData.securityAlertResponse) { - const blockaidMetricsParams = getBlockaidMetricsParams( - txData.securityAlertResponse, - ); - - trackEvent({ - category: MetaMetricsEventCategory.Transactions, - event: MetaMetricsEventName.SignatureRequested, - properties: { - action: 'Sign Request', - ...blockaidMetricsParams, - }, - }); - } - }, [txData?.securityAlertResponse]); - ///: END:ONLY_INCLUDE_IN - /** * We set the customSpendingCap to the dappProposedTokenAmount, if provided, rather than setting customTokenAmount * because customTokenAmount is reserved for custom user input. This is only set once when the component is mounted.