Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Remove blockaid env variable #10215

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
1 change: 0 additions & 1 deletion .js.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ export WALLET_CONNECT_PROJECT_ID=""
# CDN for blockaid files
export BLOCKAID_FILE_CDN=""
export BLOCKAID_PUBLIC_KEY=""
export MM_BLOCKAID_UI_ENABLED=""

# Default PORT for metro
export WATCHER_PORT=8081
Expand Down
3 changes: 1 addition & 2 deletions app/components/Nav/App/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ import {
} from '../../../actions/navigation';
import { findRouteNameFromNavigatorState } from '../../../util/general';
import { Authentication } from '../../../core/';
import { isBlockaidFeatureEnabled } from '../../../util/blockaid';
import { useTheme } from '../../../util/theme';
import Device from '../../../util/device';
import SDKConnect from '../../../core/SDKConnect/SDKConnect';
Expand Down Expand Up @@ -783,7 +782,7 @@ const App = ({ userLoggedIn }) => {
{
///: END:ONLY_INCLUDE_IF
}
{isBlockaidFeatureEnabled() && <PPOMView />}
<PPOMView />
<NavigationContainer
// Prevents artifacts when navigating between screens
theme={{
Expand Down
69 changes: 33 additions & 36 deletions app/components/UI/WhatsNewModal/whatsNewList.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/* eslint-disable import/no-commonjs, import/prefer-default-export, @typescript-eslint/no-require-imports */
import { strings } from '../../../../locales/i18n';
import Routes from '../../../constants/navigation/Routes';
import { isBlockaidFeatureEnabled } from '../../../util/blockaid';
import { WhatsNew } from './types';

export const whatsNew: WhatsNew = {
Expand All @@ -17,41 +16,39 @@ export const whatsNew: WhatsNew = {
* Both slide count and slide content will be rendered in the same order as the data set.
*/
slides: [
...(isBlockaidFeatureEnabled()
? ([
[
{
type: 'title',
title: strings('whats_new.blockaid.title'),
},
{
type: 'image',
image: require('../../../images/whats_new_blockaid.png'),
},
{
type: 'description',
description: strings('whats_new.blockaid.description_1'),
},
{
type: 'description',
description: strings('whats_new.blockaid.description_2'),
},
{
type: 'description',
description: strings('whats_new.blockaid.description_3'),
},
{
type: 'button',
buttonText: strings('whats_new.blockaid.got_it'),
buttonType: 'blue',
onPress: (props) =>
props.navigation.navigate(Routes.SETTINGS_VIEW, {
screen: Routes.SETTINGS.EXPERIMENTAL_SETTINGS,
}),
},
],
] as WhatsNew['slides'])
: []),
...([
[
{
type: 'title',
title: strings('whats_new.blockaid.title'),
},
{
type: 'image',
image: require('../../../images/whats_new_blockaid.png'),
},
{
type: 'description',
description: strings('whats_new.blockaid.description_1'),
},
{
type: 'description',
description: strings('whats_new.blockaid.description_2'),
},
{
type: 'description',
description: strings('whats_new.blockaid.description_3'),
},
{
type: 'button',
buttonText: strings('whats_new.blockaid.got_it'),
buttonType: 'blue',
onPress: (props) =>
props.navigation.navigate(Routes.SETTINGS_VIEW, {
screen: Routes.SETTINGS.EXPERIMENTAL_SETTINGS,
}),
},
],
] as WhatsNew['slides']),
[
{
type: 'image',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ import Button, {
ButtonSize,
ButtonWidthTypes,
} from '../../../../component-library/components/Buttons/Button';
import { isBlockaidFeatureEnabled } from '../../../../util/blockaid';
import trackErrorAsAnalytics from '../../../../util/metrics/TrackError/trackErrorAsAnalytics';
import BasicFunctionalityComponent from '../../../UI/BasicFunctionality/BasicFunctionality';
import Routes from '../../../../constants/navigation/Routes';
Expand Down Expand Up @@ -997,7 +996,7 @@ const Settings: React.FC = () => {
<RememberMeOptionSection />
</View>
<RevealPrivateKey />
{isBlockaidFeatureEnabled() && <BlockaidSettings />}
<BlockaidSettings />
<Heading>{strings('app_settings.privacy_heading')}</Heading>
<View>
<Text
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,11 @@ jest.mock('../../../../../core/Engine', () => ({
}),
updateSecurityAlertResponse: jest.fn(),
},
PreferencesController: {
state: {
securityAlertsEnabled: true,
},
},
},
}));
jest.mock('../../../../../util/custom-gas', () => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ 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
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React, { useEffect, useState } from 'react';
import { ActivityIndicator } from 'react-native';
import { useSelector } from 'react-redux';
import { View } from 'react-native-animatable';
import { captureException } from '@sentry/react-native';
import { deflate } from 'react-native-gzip';
Expand All @@ -18,10 +17,7 @@ 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,
isBlockaidSupportedOnCurrentChain,
} from '../../../../../util/blockaid';
import { isBlockaidFeatureEnabled } from '../../../../../util/blockaid';
import {
FALSE_POSITIVE_REPOST_LINE_TEST_ID,
REASON_DESCRIPTION_I18N_KEY_MAP,
Expand All @@ -39,7 +35,6 @@ import {
UTM_SOURCE,
} from '../../../../../constants/urls';
import { BLOCKAID_SUPPORTED_NETWORK_NAMES } from '../../../../../util/networks';
import { selectIsSecurityAlertsEnabled } from '../../../../../selectors/preferencesController';
import BlockaidVersionInfo from '../../../../../lib/ppom/blockaid-version';
import ButtonIcon, {
ButtonIconSizes,
Expand Down Expand Up @@ -74,7 +69,6 @@ const BlockaidBanner = (bannerProps: BlockaidBannerProps) => {
const { styles, theme } = useStyles(styleSheet, { style });
const [displayPositiveResponse, setDisplayPositiveResponse] = useState(false);
const [reportUrl, setReportUrl] = useState<string>('');
const isSecurityAlertsEnabled = useSelector(selectIsSecurityAlertsEnabled);

useEffect(() => {
if (securityAlertResponse?.reason === Reason.requestInProgress) {
Expand Down Expand Up @@ -115,12 +109,7 @@ const BlockaidBanner = (bannerProps: BlockaidBannerProps) => {
})();
}, [securityAlertResponse]);

if (
!securityAlertResponse ||
!isBlockaidFeatureEnabled() ||
!isBlockaidSupportedOnCurrentChain() ||
pedronfigueiredo marked this conversation as resolved.
Show resolved Hide resolved
!isSecurityAlertsEnabled
) {
if (!securityAlertResponse || !isBlockaidFeatureEnabled()) {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ jest.mock('../../../../../core/Engine', () => ({
keyrings: [],
},
},
PreferencesController: {
state: {
securityAlertsEnabled: true,
},
},
},
}));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,14 @@ import { TESTID_ACCORDIONHEADER } from '../../../../../component-library/compone
import { ResultType, Reason } from '../BlockaidBanner/BlockaidBanner.types';
import TransactionBlockaidBanner from './TransactionBlockaidBanner';

jest.mock('../../../../../util/blockaid', () => ({
isBlockaidFeatureEnabled: jest.fn().mockReturnValue(true),
isBlockaidSupportedOnCurrentChain: jest.fn().mockReturnValue(true),
jest.mock('../../../../../core/Engine', () => ({
context: {
PreferencesController: {
state: {
securityAlertsEnabled: true,
},
},
},
}));

jest.mock('react-native-gzip', () => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ jest.mock('../../../../../core/Engine', () => ({
],
},
},
PreferencesController: {
state: {
securityAlertsEnabled: true,
},
},
},
}));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ jest.mock('../../../../../core/Engine', () => ({
removeListener: jest.fn(),
},
},
PreferencesController: {
state: {
securityAlertsEnabled: true,
},
},
},
controllerMessenger: {
subscribe: jest.fn(),
Expand Down
11 changes: 3 additions & 8 deletions app/core/Engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,6 @@ import {
} from './Snaps';
import { getRpcMethodMiddleware } from './RPCMethods/RPCMethodMiddleware';
///: END:ONLY_INCLUDE_IF
import { isBlockaidFeatureEnabled } from '../util/blockaid';
import {
getCaveatSpecifications,
getPermissionSpecifications,
Expand Down Expand Up @@ -1299,10 +1298,7 @@ class Engine {
subjectMetadataController,
///: END:ONLY_INCLUDE_IF
accountsController,
];

if (isBlockaidFeatureEnabled()) {
const ppomController = new PPOMController({
new PPOMController({
chainId: networkController.state.providerConfig.chainId,
blockaidPublicKey: process.env.BLOCKAID_PUBLIC_KEY as string,
cdnBaseUrl: process.env.BLOCKAID_FILE_CDN as string,
Expand Down Expand Up @@ -1334,9 +1330,8 @@ class Engine {
// TODO: Replace "any" with type
// eslint-disable-next-line @typescript-eslint/no-explicit-any
nativeCrypto: Crypto as any,
});
controllers.push(ppomController);
}
}),
];

// set initial state
// TODO: Pass initial state into each controller constructor instead
Expand Down
10 changes: 3 additions & 7 deletions app/core/EngineService/EngineService.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import UntypedEngine from '../Engine';
import AppConstants from '../AppConstants';
import { getVaultFromBackup } from '../BackupVault';
import { isBlockaidFeatureEnabled } from '../../util/blockaid';
import { store as importedStore } from '../../store';
import Logger from '../../util/Logger';
import {
Expand Down Expand Up @@ -115,14 +114,11 @@ class EngineService {
name: 'AccountsController',
key: `${engine.context.AccountsController.name}:stateChange`,
},
];

if (isBlockaidFeatureEnabled()) {
controllers.push({
{
name: 'PPOMController',
key: `${engine.context.PPOMController.name}:stateChange`,
});
}
},
];

engine?.datamodel?.subscribe?.(() => {
if (!engine.context.KeyringController.metadata.vault) {
Expand Down
13 changes: 11 additions & 2 deletions app/lib/ppom/ppom-util.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { normalizeTransactionParams } from '@metamask/transaction-controller';
import * as SignatureRequestActions from '../../actions/signatureRequest'; // eslint-disable-line import/no-namespace
import * as TransactionActions from '../../actions/transaction'; // eslint-disable-line import/no-namespace
import * as NetworkControllerSelectors from '../../selectors/networkController'; // eslint-disable-line import/no-namespace
import Engine from '../../core/Engine';
import PPOMUtil from './ppom-util';
import {
Expand Down Expand Up @@ -34,6 +35,13 @@ jest.mock('../../core/Engine', () => ({
},
},
},
backgroundState: {
NetworkController: {
providerConfig: {
chainId: 0x1,
},
},
},
}));

const MockEngine = jest.mocked(Engine);
Expand Down Expand Up @@ -115,8 +123,9 @@ describe('PPOM Utils', () => {
TransactionActions,
'setTransactionSecurityAlertResponse',
);
MockEngine.context.NetworkController.state.providerConfig.chainId =
'0xfa';
jest
.spyOn(NetworkControllerSelectors, 'selectChainId')
.mockReturnValue('0xfa');
await PPOMUtil.validateRequest(mockRequest, CHAIN_ID_MOCK);
expect(MockEngine.context.PPOMController?.usePPOM).toBeCalledTimes(0);
expect(spyTransactionAction).toBeCalledTimes(0);
Expand Down
21 changes: 3 additions & 18 deletions app/lib/ppom/ppom-util.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import setSignatureRequestSecurityAlertResponse from '../../actions/signatureRequest';
import { setTransactionSecurityAlertResponse } from '../../actions/transaction';
import { BLOCKAID_SUPPORTED_CHAIN_IDS } from '../../util/networks';
import {
Reason,
ResultType,
Expand Down Expand Up @@ -57,26 +56,12 @@ const SECURITY_ALERT_RESPONSE_IN_PROGRESS = {
};

async function validateRequest(req: PPOMRequest, transactionId?: string) {
const {
PPOMController: ppomController,
PreferencesController,
NetworkController,
} = Engine.context;
const { PPOMController: ppomController, NetworkController } = Engine.context;

const chainId = NetworkController.state.providerConfig.chainId;
const isConfirmationMethod = CONFIRMATION_METHODS.includes(req.method);
const isSupportedChain = BLOCKAID_SUPPORTED_CHAIN_IDS.includes(chainId);

const isSecurityAlertsEnabled =
PreferencesController.state.securityAlertsEnabled;

if (
!ppomController ||
!isBlockaidFeatureEnabled() ||
!isSecurityAlertsEnabled ||
!isConfirmationMethod ||
!isSupportedChain
) {

if (!ppomController || !isBlockaidFeatureEnabled() || !isConfirmationMethod) {
return;
}

Expand Down
Loading
Loading