Skip to content

Commit

Permalink
fx: update blockaid false positive report url. (#22403)
Browse files Browse the repository at this point in the history
  • Loading branch information
jpuri committed Jan 10, 2024
1 parent 2f894db commit ee05011
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 17 deletions.
3 changes: 2 additions & 1 deletion shared/constants/security-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,6 @@ export const SECURITY_PROVIDER_MESSAGE_SEVERITY = {
NOT_SAFE: 2,
};

export const FALSE_POSITIVE_REPORT_BASE_URL = 'https://report.blockaid.io/tx';
export const FALSE_POSITIVE_REPORT_BASE_URL =
'https://blockaid-false-positive-portal.metamask.io';
export const UTM_SOURCE = 'metamask-ppom';
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ exports[`Blockaid Banner Alert should render 'danger' UI when securityAlertRespo
Something doesn't look right?
<a
class="mm-box mm-text mm-button-base mm-button-link mm-button-link--size-inherit mm-text--body-md-medium mm-box--padding-0 mm-box--padding-right-0 mm-box--padding-left-0 mm-box--display-inline-flex mm-box--justify-content-center mm-box--align-items-center mm-box--color-primary-default mm-box--background-color-transparent"
href="https://report.blockaid.io/tx?data=mockedEncodedData&utm_source=metamask-ppom"
href="https://blockaid-false-positive-portal.metamask.io?data=%7B%22classification%22%3A%22set_approval_for_all%22%2C%22blockaidVersion%22%3A%221.3.3%22%2C%22resultType%22%3A%22Malicious%22%7D&utm_source=metamask-ppom"
rel="noopener noreferrer"
target="_blank"
>
Expand Down Expand Up @@ -142,7 +142,7 @@ exports[`Blockaid Banner Alert should render 'warning' UI when securityAlertResp
Something doesn't look right?
<a
class="mm-box mm-text mm-button-base mm-button-link mm-button-link--size-inherit mm-text--body-md-medium mm-box--padding-0 mm-box--padding-right-0 mm-box--padding-left-0 mm-box--display-inline-flex mm-box--justify-content-center mm-box--align-items-center mm-box--color-primary-default mm-box--background-color-transparent"
href="https://report.blockaid.io/tx?data=mockedEncodedData&utm_source=metamask-ppom"
href="https://blockaid-false-positive-portal.metamask.io?data=%7B%22classification%22%3A%22set_approval_for_all%22%2C%22blockaidVersion%22%3A%221.3.3%22%2C%22resultType%22%3A%22Failed%22%7D&utm_source=metamask-ppom"
rel="noopener noreferrer"
target="_blank"
>
Expand Down Expand Up @@ -212,7 +212,7 @@ exports[`Blockaid Banner Alert should render 'warning' UI when securityAlertResp
Something doesn't look right?
<a
class="mm-box mm-text mm-button-base mm-button-link mm-button-link--size-inherit mm-text--body-md-medium mm-box--padding-0 mm-box--padding-right-0 mm-box--padding-left-0 mm-box--display-inline-flex mm-box--justify-content-center mm-box--align-items-center mm-box--color-primary-default mm-box--background-color-transparent"
href="https://report.blockaid.io/tx?data=mockedEncodedData&utm_source=metamask-ppom"
href="https://blockaid-false-positive-portal.metamask.io?data=%7B%22classification%22%3A%22set_approval_for_all%22%2C%22blockaidVersion%22%3A%221.3.3%22%2C%22resultType%22%3A%22Warning%22%7D&utm_source=metamask-ppom"
rel="noopener noreferrer"
target="_blank"
>
Expand Down Expand Up @@ -305,7 +305,7 @@ exports[`Blockaid Banner Alert should render details section even when features
Something doesn't look right?
<a
class="mm-box mm-text mm-button-base mm-button-link mm-button-link--size-inherit mm-text--body-md-medium mm-box--padding-0 mm-box--padding-right-0 mm-box--padding-left-0 mm-box--display-inline-flex mm-box--justify-content-center mm-box--align-items-center mm-box--color-primary-default mm-box--background-color-transparent"
href="https://report.blockaid.io/tx?data=mockedEncodedData&utm_source=metamask-ppom"
href="https://blockaid-false-positive-portal.metamask.io?data=%7B%22classification%22%3A%22set_approval_for_all%22%2C%22blockaidVersion%22%3A%221.3.3%22%2C%22resultType%22%3A%22Warning%22%7D&utm_source=metamask-ppom"
rel="noopener noreferrer"
target="_blank"
>
Expand Down Expand Up @@ -411,7 +411,7 @@ exports[`Blockaid Banner Alert should render details when provided 1`] = `
Something doesn't look right?
<a
class="mm-box mm-text mm-button-base mm-button-link mm-button-link--size-inherit mm-text--body-md-medium mm-box--padding-0 mm-box--padding-right-0 mm-box--padding-left-0 mm-box--display-inline-flex mm-box--justify-content-center mm-box--align-items-center mm-box--color-primary-default mm-box--background-color-transparent"
href="https://report.blockaid.io/tx?data=mockedEncodedData&utm_source=metamask-ppom"
href="https://blockaid-false-positive-portal.metamask.io?data=%7B%22classification%22%3A%22set_approval_for_all%22%2C%22blockaidVersion%22%3A%221.3.3%22%2C%22resultType%22%3A%22Warning%22%2C%22reproduce%22%3A%22%5B%5C%22Operator%20is%20an%20EOA%5C%22%2C%5C%22Operator%20is%20untrusted%20according%20to%20previous%20activity%5C%22%5D%22%7D&utm_source=metamask-ppom"
rel="noopener noreferrer"
target="_blank"
>
Expand Down Expand Up @@ -505,7 +505,7 @@ exports[`Blockaid Banner Alert should render link to report url 1`] = `
Something doesn't look right?
<a
class="mm-box mm-text mm-button-base mm-button-link mm-button-link--size-inherit mm-text--body-md-medium mm-box--padding-0 mm-box--padding-right-0 mm-box--padding-left-0 mm-box--display-inline-flex mm-box--justify-content-center mm-box--align-items-center mm-box--color-primary-default mm-box--background-color-transparent"
href="https://report.blockaid.io/tx?data=mockedEncodedData&utm_source=metamask-ppom"
href="https://blockaid-false-positive-portal.metamask.io?data=%7B%22classification%22%3A%22set_approval_for_all%22%2C%22blockaidVersion%22%3A%221.3.3%22%2C%22resultType%22%3A%22Warning%22%7D&utm_source=metamask-ppom"
rel="noopener noreferrer"
target="_blank"
>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
import React, { useContext } from 'react';
import PropTypes from 'prop-types';
import { captureException } from '@sentry/browser';
import BlockaidPackage from '@blockaid/ppom_release/package.json';

import { Text } from '../../../component-library';
import { NETWORK_TO_NAME_MAP } from '../../../../../shared/constants/network';
import {
OverflowWrap,
Severity,
} from '../../../../helpers/constants/design-system';
import { I18nContext } from '../../../../contexts/i18n';

import {
BlockaidReason,
BlockaidResultType,
SecurityProvider,
} from '../../../../../shared/constants/security-provider';
import { Text } from '../../../component-library';

import SecurityProviderBannerAlert from '../security-provider-banner-alert';
import { getReportUrl } from './blockaid-banner-utils';

Expand Down Expand Up @@ -50,15 +52,21 @@ const REASON_TO_TITLE_TKEY = Object.freeze({
});

function BlockaidBannerAlert({ txData, ...props }) {
const { securityAlertResponse, origin, msgParams, type, txParams } = txData;
const { securityAlertResponse, origin, msgParams, type, txParams, chainId } =
txData;

const t = useContext(I18nContext);

if (!securityAlertResponse) {
return null;
}

const { reason, result_type: resultType, features } = securityAlertResponse;
const {
reason,
result_type: resultType,
features,
block,
} = securityAlertResponse;

if (resultType === BlockaidResultType.Benign) {
return null;
Expand Down Expand Up @@ -91,8 +99,14 @@ function BlockaidBannerAlert({ txData, ...props }) {
domain: origin ?? msgParams?.origin,
jsonRpcMethod: type,
jsonRpcParams: JSON.stringify(txParams ?? msgParams),
blockNumber: block,
chain: NETWORK_TO_NAME_MAP[chainId],
classification: reason,
blockaidVersion: BlockaidPackage.version,
resultType,
reproduce: JSON.stringify(features),
};

const jsonData = JSON.stringify(reportData);

const encodedData = zlib?.gzipSync?.(jsonData) ?? jsonData;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,8 @@ import {
} from '../../../../../shared/constants/security-provider';
import BlockaidBannerAlert from '.';

jest.mock('./blockaid-banner-utils', () => ({
getReportUrl: jest
.fn()
.mockReturnValue(
'https://report.blockaid.io/tx?data=mockedEncodedData&utm_source=metamask-ppom',
),
jest.mock('zlib', () => ({
gzipSync: (val) => val,
}));

const mockSecurityAlertResponse = {
Expand Down Expand Up @@ -205,6 +201,22 @@ describe('Blockaid Banner Alert', () => {
expect(getByRole('link', { name: 'Report an issue' })).toBeInTheDocument();
});

it('should pass required data in Report an issue URL', () => {
const { getByRole } = renderWithLocalization(
<BlockaidBannerAlert
txData={{
securityAlertResponse: mockSecurityAlertResponse,
features: undefined,
}}
/>,
);

const elm = getByRole('link', { name: 'Report an issue' });
expect(elm.href).toBe(
'https://blockaid-false-positive-portal.metamask.io/?data=%7B%22classification%22%3A%22set_approval_for_all%22%2C%22blockaidVersion%22%3A%221.3.3%22%2C%22resultType%22%3A%22Warning%22%7D&utm_source=metamask-ppom',
);
});

describe('when rendering description', () => {
Object.entries({
[BlockaidReason.approvalFarming]:
Expand Down

0 comments on commit ee05011

Please sign in to comment.