Skip to content

Commit

Permalink
Blockaid experimental settings should be visible on all networks (#8412)
Browse files Browse the repository at this point in the history
  • Loading branch information
jpuri authored Jan 26, 2024
1 parent 807f1fc commit d2e926e
Show file tree
Hide file tree
Showing 11 changed files with 129 additions and 124 deletions.
17 changes: 6 additions & 11 deletions app/components/UI/ApproveTransactionReview/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,7 @@ import TransactionReviewDetailsCard from '../../UI/TransactionReview/Transaction
import AppConstants from '../../../core/AppConstants';
import { UINT256_HEX_MAX_VALUE } from '../../../constants/transaction';
import { WALLET_CONNECT_ORIGIN } from '../../../util/walletconnect';
import {
isBlockaidFeatureEnabled,
getBlockaidMetricsParams,
} from '../../../util/blockaid';
import { getBlockaidMetricsParams } from '../../../util/blockaid';
import { withNavigation } from '@react-navigation/compat';
import {
isTestNet,
Expand Down Expand Up @@ -822,13 +819,11 @@ class ApproveTransactionReview extends PureComponent {
style={styles.accountApprovalWrapper}
onStartShouldSetResponder={() => true}
>
{isBlockaidFeatureEnabled() && (
<TransactionBlockaidBanner
transactionId={transactionId}
style={styles.blockaidWarning}
onContactUsClicked={this.onContactUsClicked}
/>
)}
<TransactionBlockaidBanner
transactionId={transactionId}
style={styles.blockaidWarning}
onContactUsClicked={this.onContactUsClicked}
/>
<Text variant={TextVariant.HeadingMD} style={styles.title}>
{strings(
`spend_limit_edition.${
Expand Down
1 change: 1 addition & 0 deletions app/components/UI/BlockaidBanner/BlockaidBanner.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import renderWithProvider from '../../../util/test/renderWithProvider';

jest.mock('../../../util/blockaid', () => ({
isBlockaidFeatureEnabled: jest.fn().mockReturnValue(true),
isBlockaidSupportedOnCurrentChain: jest.fn().mockReturnValue(true),
}));

jest.mock('react-native-gzip', () => ({
Expand Down
14 changes: 6 additions & 8 deletions app/components/UI/BlockaidBanner/BlockaidBanner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ import {
import Icon from '../../../component-library/components/Icons/Icon/Icon';
import Text from '../../../component-library/components/Texts/Text/Text';
import { useStyles } from '../../../component-library/hooks/useStyles';
import { isBlockaidFeatureEnabled } from '../../../util/blockaid';
import {
isBlockaidFeatureEnabled,
isBlockaidSupportedOnCurrentChain,
} from '../../../util/blockaid';
import {
ATTRIBUTION_LINE_TEST_ID,
FALSE_POSITIVE_REPOST_LINE_TEST_ID,
Expand All @@ -38,11 +41,7 @@ import {
FALSE_POSITIVE_REPORT_BASE_URL,
UTM_SOURCE,
} from '../../../constants/urls';
import {
BLOCKAID_SUPPORTED_CHAIN_IDS,
BLOCKAID_SUPPORTED_NETWORK_NAMES,
} from '../../../util/networks';
import { selectChainId } from '../../../selectors/networkController';
import { BLOCKAID_SUPPORTED_NETWORK_NAMES } from '../../../util/networks';
import { selectIsSecurityAlertsEnabled } from '../../../selectors/preferencesController';
import BlockaidVersionInfo from '../../../lib/ppom/blockaid-version';

Expand Down Expand Up @@ -99,7 +98,6 @@ const BlockaidBanner = (bannerProps: BlockaidBannerProps) => {
} = bannerProps;
const { styles, theme } = useStyles(styleSheet, { style });
const [displayPositiveResponse, setDisplayPositiveResponse] = useState(false);
const networkChainId = useSelector(selectChainId);
const [reportUrl, setReportUrl] = useState<string>('');
const isSecurityAlertsEnabled = useSelector(selectIsSecurityAlertsEnabled);

Expand Down Expand Up @@ -141,7 +139,7 @@ const BlockaidBanner = (bannerProps: BlockaidBannerProps) => {
if (
!securityAlertResponse ||
!isBlockaidFeatureEnabled() ||
!BLOCKAID_SUPPORTED_CHAIN_IDS.includes(networkChainId) ||
!isBlockaidSupportedOnCurrentChain() ||
!isSecurityAlertsEnabled
) {
return null;
Expand Down
13 changes: 5 additions & 8 deletions app/components/UI/SignatureRequest/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { selectProviderType } from '../../../selectors/networkController';
import { fontStyles } from '../../../styles/common';
import { isHardwareAccount } from '../../../util/address';
import AnalyticsV2 from '../../../util/analyticsV2';
import { isBlockaidFeatureEnabled } from '../../../util/blockaid';
import { getHost } from '../../../util/browser';
import { getAnalyticsParams } from '../../../util/confirmation/signatureUtils';
import Device from '../../../util/device';
Expand Down Expand Up @@ -367,13 +366,11 @@ class SignatureRequest extends PureComponent {
</TouchableOpacity>
) : null}
</View>
{isBlockaidFeatureEnabled() && (
<BlockaidBanner
securityAlertResponse={securityAlertResponse}
style={styles.blockaidBanner}
onContactUsClicked={this.onContactUsClicked}
/>
)}
<BlockaidBanner
securityAlertResponse={securityAlertResponse}
style={styles.blockaidBanner}
onContactUsClicked={this.onContactUsClicked}
/>
{this.renderActionViewChildren()}
</View>
</ActionView>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import TransactionBlockaidBanner from './TransactionBlockaidBanner';

jest.mock('../../../util/blockaid', () => ({
isBlockaidFeatureEnabled: jest.fn().mockReturnValue(true),
isBlockaidSupportedOnCurrentChain: jest.fn().mockReturnValue(true),
}));

jest.mock('react-native-gzip', () => ({
Expand Down
17 changes: 6 additions & 11 deletions app/components/UI/TransactionReview/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,7 @@ import {
} from '../../../util/number';
import { safeToChecksumAddress } from '../../../util/address';
import Device from '../../../util/device';
import {
isBlockaidFeatureEnabled,
getBlockaidMetricsParams,
} from '../../../util/blockaid';
import { getBlockaidMetricsParams } from '../../../util/blockaid';
import TransactionReviewInformation from './TransactionReviewInformation';
import TransactionReviewSummary from './TransactionReviewSummary';
import TransactionReviewData from './TransactionReviewData';
Expand Down Expand Up @@ -518,13 +515,11 @@ class TransactionReview extends PureComponent {
style={styles.accountTransactionWrapper}
onStartShouldSetResponder={() => true}
>
{isBlockaidFeatureEnabled() && (
<TransactionBlockaidBanner
transactionId={transactionId}
style={styles.blockaidWarning}
onContactUsClicked={this.onContactUsClicked}
/>
)}
<TransactionBlockaidBanner
transactionId={transactionId}
style={styles.blockaidWarning}
onContactUsClicked={this.onContactUsClicked}
/>
<TransactionReviewSummary
actionKey={actionKey}
assetAmount={assetAmount}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ jest.mock('@react-navigation/native', () => ({

jest.mock('../../../../util/blockaid', () => ({
isBlockaidFeatureEnabled: jest.fn().mockReturnValue(true),
isBlockaidSupportedOnCurrentChain: jest.fn().mockReturnValue(true),
}));

jest.mock('../../../../core/Engine', () => ({
Expand Down
21 changes: 5 additions & 16 deletions app/core/RPCMethods/RPCMethodMiddleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import Networks, {
blockTagParamIndex,
getAllNetworks,
} from '../../util/networks';
import { isBlockaidFeatureEnabled } from '../../util/blockaid';
import { polyfillGasPrice } from './utils';
import ImportedEngine from '../Engine';
import { strings } from '../../../locales/i18n';
Expand Down Expand Up @@ -550,9 +549,7 @@ export const getRpcMethodMiddleware = ({
address: req.params[0].from,
checkSelectedAddress: isMMSDK || isWalletConnect,
});
if (isBlockaidFeatureEnabled()) {
PPOMUtil.validateRequest(req);
}
PPOMUtil.validateRequest(req);
const rawSig = await SignatureController.newUnsignedMessage({
data: req.params[1],
from: req.params[0],
Expand Down Expand Up @@ -600,9 +597,7 @@ export const getRpcMethodMiddleware = ({
checkSelectedAddress: isMMSDK || isWalletConnect,
});

if (isBlockaidFeatureEnabled()) {
PPOMUtil.validateRequest(req);
}
PPOMUtil.validateRequest(req);

const rawSig = await SignatureController.newUnsignedPersonalMessage({
...params,
Expand Down Expand Up @@ -649,9 +644,7 @@ export const getRpcMethodMiddleware = ({
checkSelectedAddress: isMMSDK || isWalletConnect,
});

if (isBlockaidFeatureEnabled()) {
PPOMUtil.validateRequest(req);
}
PPOMUtil.validateRequest(req);

const rawSig = await SignatureController.newUnsignedTypedMessage(
{
Expand All @@ -673,9 +666,7 @@ export const getRpcMethodMiddleware = ({
? JSON.parse(req.params[1])
: req.params[1];
const chainId = data.domain.chainId;
if (isBlockaidFeatureEnabled()) {
PPOMUtil.validateRequest(req);
}
PPOMUtil.validateRequest(req);
res.result = await generateRawSignature({
version: 'V3',
req,
Expand All @@ -695,9 +686,7 @@ export const getRpcMethodMiddleware = ({
eth_signTypedData_v4: async () => {
const data = JSON.parse(req.params[1]);
const chainId = data.domain.chainId;
if (isBlockaidFeatureEnabled()) {
PPOMUtil.validateRequest(req);
}
PPOMUtil.validateRequest(req);
res.result = await generateRawSignature({
version: 'V4',
req,
Expand Down
5 changes: 1 addition & 4 deletions app/core/RPCMethods/eth_sendTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
} from '@metamask/transaction-controller';
import { ethErrors } from 'eth-json-rpc-errors';
import ppomUtil from '../../lib/ppom/ppom-util';
import { isBlockaidFeatureEnabled } from '../../util/blockaid';

/**
* A JavaScript object that is not `null`, a function, or an array.
Expand Down Expand Up @@ -99,9 +98,7 @@ async function eth_sendTransaction({
origin: hostname,
});

if (isBlockaidFeatureEnabled()) {
ppomUtil.validateRequest(req, transactionMeta?.id);
}
ppomUtil.validateRequest(req, transactionMeta?.id);

res.result = await result;
}
Expand Down
Loading

0 comments on commit d2e926e

Please sign in to comment.