Skip to content

Commit

Permalink
Ensure phishing stale list network request is not sent during/after o…
Browse files Browse the repository at this point in the history
…nboarding if basic functionality toggle is off
  • Loading branch information
danjm committed Jun 14, 2024
1 parent 04642d2 commit 05c04fd
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
8 changes: 6 additions & 2 deletions app/scripts/metamask-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -863,8 +863,6 @@ export default class MetamaskController extends EventEmitter {
stalelistRefreshInterval: process.env.IN_TEST ? 30 * SECOND : undefined,
});

this.phishingController.maybeUpdateState();

///: BEGIN:ONLY_INCLUDE_IF(blockaid)
this.ppomController = new PPOMController({
messenger: this.controllerMessenger.getRestricted({
Expand Down Expand Up @@ -2337,7 +2335,13 @@ export default class MetamaskController extends EventEmitter {
}

postOnboardingInitialization() {
const { usePhishDetect } = this.preferencesController.store.getState();

this.networkController.lookupNetwork();

if (usePhishDetect) {
this.phishingController.maybeUpdateState();
}
}

triggerNetworkrequests() {
Expand Down
7 changes: 7 additions & 0 deletions test/e2e/tests/privacy/basic-functionality.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,17 @@ const {
tinyDelayMs,
defaultGanacheOptions,
} = require('../../helpers');
const { METAMASK_STALELIST_URL } = require('../phishing-controller/helpers');
const FixtureBuilder = require('../../fixture-builder');

async function mockApis(mockServer) {
return [
await mockServer.forGet(METAMASK_STALELIST_URL).thenCallback(() => {
return {
statusCode: 200,
body: [{ fakedata: true }],
};
}),
await mockServer
.forGet('https://token.api.cx.metamask.io/tokens/1')
.thenCallback(() => {
Expand Down
13 changes: 8 additions & 5 deletions ui/pages/onboarding-flow/privacy-settings/privacy-settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ export default function PrivacySettings() {
const defaultState = useSelector((state) => state.metamask);
const {
incomingTransactionsPreferences,
usePhishDetect,
use4ByteResolution,
useTokenDetection,
useCurrencyRateCheck,
Expand All @@ -116,8 +115,7 @@ export default function PrivacySettings() {
const petnamesEnabled = useSelector(getPetnamesEnabled);
const participateInMetaMetrics = useSelector(selectParticipateInMetaMetrics);

const [usePhishingDetection, setUsePhishingDetection] =
useState(usePhishDetect);
const [usePhishingDetection, setUsePhishingDetection] = useState(null);
const [turnOn4ByteResolution, setTurnOn4ByteResolution] =
useState(use4ByteResolution);
const [turnOnTokenDetection, setTurnOnTokenDetection] =
Expand Down Expand Up @@ -146,13 +144,18 @@ export default function PrivacySettings() {
getExternalServicesOnboardingToggleState,
);

const phishingToggleState =
usePhishingDetection === null
? externalServicesOnboardingToggleState
: usePhishingDetection;

const profileSyncingProps = useProfileSyncingProps(
externalServicesOnboardingToggleState,
);

const handleSubmit = () => {
dispatch(toggleExternalServices(externalServicesOnboardingToggleState));
dispatch(setUsePhishDetect(usePhishingDetection));
dispatch(setUsePhishDetect(phishingToggleState));
dispatch(setUse4ByteResolution(turnOn4ByteResolution));
dispatch(setUseTokenDetection(turnOnTokenDetection));
dispatch(
Expand Down Expand Up @@ -320,7 +323,7 @@ export default function PrivacySettings() {
)}

<Setting
value={usePhishingDetection}
value={phishingToggleState}
setValue={setUsePhishingDetection}
title={t('usePhishingDetection')}
description={t('onboardingUsePhishingDetectionDescription', [
Expand Down

0 comments on commit 05c04fd

Please sign in to comment.