diff --git a/test/e2e/default-fixture.js b/test/e2e/default-fixture.js deleted file mode 100644 index 98413671caca..000000000000 --- a/test/e2e/default-fixture.js +++ /dev/null @@ -1,265 +0,0 @@ -const { NetworkStatus } = require('@metamask/network-controller'); -const { CHAIN_IDS } = require('../../shared/constants/network'); -const { FirstTimeFlowType } = require('../../shared/constants/onboarding'); - -const FIXTURE_STATE_METADATA_VERSION = 74; - -const E2E_SRP = - 'spread raise short crane omit tent fringe mandate neglect detail suspect cradle'; - -function defaultFixture(inputChainId = CHAIN_IDS.LOCALHOST) { - return { - data: { - AuthenticationController: { - isSignedIn: true, - }, - UserStorageController: { - isProfileSyncingEnabled: true, - }, - MetamaskNotificationsController: { - subscriptionAccountsSeen: [], - isFeatureAnnouncementsEnabled: false, - isMetamaskNotificationsEnabled: false, - isMetamaskNotificationsFeatureSeen: false, - metamaskNotificationsList: [], - metamaskNotificationsReadList: [], - }, - AccountsController: { - internalAccounts: { - selectedAccount: 'd5e45e4a-3b04-4a09-a5e1-39762e5c6be4', - accounts: { - 'd5e45e4a-3b04-4a09-a5e1-39762e5c6be4': { - id: 'd5e45e4a-3b04-4a09-a5e1-39762e5c6be4', - address: '0x5cfe73b6021e818b776b421b1c4db2474086a7e1', - metadata: { - name: 'Account 1', - lastSelected: 1665507600000, - keyring: { - type: 'HD Key Tree', - }, - }, - options: {}, - methods: [ - 'personal_sign', - 'eth_sign', - 'eth_signTransaction', - 'eth_signTypedData_v1', - 'eth_signTypedData_v3', - 'eth_signTypedData_v4', - ], - type: 'eip155:eoa', - }, - }, - }, - }, - AlertController: { - alertEnabledness: { - unconnectedAccount: true, - web3ShimUsage: true, - }, - unconnectedAccountAlertShownOrigins: {}, - web3ShimUsageOrigins: {}, - }, - AnnouncementController: { - announcements: { - 8: { - date: '2021-11-01', - id: 8, - isShown: false, - }, - }, - }, - NetworkOrderController: { - orderedNetworkList: [ - { - networkId: '0x1', - networkRpcUrl: - 'https://mainnet.infura.io/v3/00000000000000000000000000000000', - }, - { - networkId: '0xe708', - networkRpcUrl: - 'https://linea-mainnet.infura.io/v3/00000000000000000000000000000000', - }, - { - networkId: '0x539', - networkRpcUrl: 'http://localhost:8545', - }, - ], - }, - AccountOrderController: { - pinnedAccountList: [], - hiddenAccountList: [], - }, - AppStateController: { - browserEnvironment: {}, - nftsDropdownState: {}, - connectedStatusPopoverHasBeenShown: true, - termsOfUseLastAgreed: - '__FIXTURE_SUBSTITUTION__currentDateInMilliseconds', - defaultHomeActiveTabName: null, - fullScreenGasPollTokens: [], - notificationGasPollTokens: [], - popupGasPollTokens: [], - qrHardware: {}, - recoveryPhraseReminderHasBeenShown: true, - recoveryPhraseReminderLastShown: - '__FIXTURE_SUBSTITUTION__currentDateInMilliseconds', - showTestnetMessageInDropdown: true, - trezorModel: null, - usedNetworks: { - [CHAIN_IDS.MAINNET]: true, - [CHAIN_IDS.LINEA_MAINNET]: true, - [CHAIN_IDS.GOERLI]: true, - [CHAIN_IDS.LOCALHOST]: true, - }, - snapsInstallPrivacyWarningShown: true, - }, - CurrencyController: { - currentCurrency: 'usd', - currencyRates: { - ETH: { - conversionDate: 1665507600.0, - conversionRate: 1700.0, - usdConversionRate: 1700.0, - }, - }, - }, - GasFeeController: { - estimatedGasFeeTimeBounds: {}, - gasEstimateType: 'none', - gasFeeEstimates: {}, - }, - KeyringController: { - vault: - '{"data":"WHaP1FrrtV4zUonudIppDifsLHF39g6oPkVksAIdWAHBRzax1uy1asfAJprR7u72t4/HuYz5yPIFQrnNnv+hwQu9GRuty88VKMnvMy+sq8MNtoXI+C54bZpWa8r4iUQfa0Mj/cfJbpFpzOdF1ZYXahTfTcU5WsrHwvJew842CiJR4B2jmCHHXfm/DxLK3WazsVQwXJGx/U71UelGoOOrT8NI28EKrAwgPn+7Xmv0j92gmhau30N7Bo2fr6Zv","iv":"LfD8/tY1EjXzxuemSmDVdA==","keyMetadata":{"algorithm":"PBKDF2","params":{"iterations":600000}},"salt":"nk4xdpmMR+1s5BYe4Vnk++XAQwrISI2bCtbMg7V1wUA="}', - }, - MetaMetricsController: { - eventsBeforeMetricsOptIn: [], - fragments: {}, - metaMetricsId: null, - participateInMetaMetrics: false, - dataCollectionForMarketing: false, - traits: {}, - }, - NetworkController: { - selectedNetworkClientId: 'networkConfigurationId', - networksMetadata: { - networkConfigurationId: { - EIPS: {}, - status: NetworkStatus.Available, - }, - }, - providerConfig: { - chainId: inputChainId, - nickname: 'Localhost 8545', - rpcPrefs: {}, - rpcUrl: 'http://localhost:8545', - ticker: 'ETH', - type: 'rpc', - id: 'networkConfigurationId', - }, - networkConfigurations: { - networkConfigurationId: { - chainId: inputChainId, - nickname: 'Localhost 8545', - rpcPrefs: {}, - rpcUrl: 'http://localhost:8545', - ticker: 'ETH', - networkConfigurationId: 'networkConfigurationId', - }, - }, - }, - OnboardingController: { - completedOnboarding: true, - firstTimeFlowType: FirstTimeFlowType.import, - onboardingTabs: {}, - seedPhraseBackedUp: true, - }, - PermissionController: { - subjects: {}, - }, - PreferencesController: { - advancedGasFee: null, - currentLocale: 'en', - useExternalServices: true, - dismissSeedBackUpReminder: true, - featureFlags: {}, - forgottenPassword: false, - identities: { - '0x5cfe73b6021e818b776b421b1c4db2474086a7e1': { - address: '0x5cfe73b6021e818b776b421b1c4db2474086a7e1', - lastSelected: 1665507600000, - name: 'Account 1', - }, - }, - ipfsGateway: 'dweb.link', - knownMethodData: {}, - ledgerTransportType: 'webhid', - lostIdentities: {}, - openSeaEnabled: false, - preferences: { - hideZeroBalanceTokens: false, - showExtensionInFullSizeView: false, - showFiatInTestnets: false, - showTestNetworks: false, - smartTransactionsOptInStatus: false, - useNativeCurrencyAsPrimaryCurrency: true, - petnamesEnabled: true, - showTokenAutodetectModal: false, - }, - selectedAddress: '0x5cfe73b6021e818b776b421b1c4db2474086a7e1', - theme: 'light', - useBlockie: false, - useNftDetection: false, - useNonceField: false, - usePhishDetect: true, - useTokenDetection: false, - useCurrencyRateCheck: true, - useMultiAccountBalanceChecker: true, - useRequestQueue: true, - }, - SelectedNetworkController: { - domains: {}, - }, - SmartTransactionsController: { - smartTransactionsState: { - fees: {}, - liveness: true, - smartTransactions: { - [CHAIN_IDS.MAINNET]: [], - }, - }, - }, - SubjectMetadataController: { - subjectMetadata: { - 'https://metamask.github.io': { - extensionId: null, - iconUrl: null, - name: 'MetaMask < = > Ledger Bridge', - origin: 'https://metamask.github.io', - subjectType: 'website', - }, - }, - }, - TokensController: { - allDetectedTokens: {}, - allIgnoredTokens: {}, - allTokens: {}, - detectedTokens: [], - ignoredTokens: [], - tokens: [], - }, - TransactionController: { - transactions: {}, - }, - config: {}, - firstTimeInfo: { - date: 1665507600000, - version: '10.21.0', - }, - }, - }; -} - -module.exports = { defaultFixture, FIXTURE_STATE_METADATA_VERSION, E2E_SRP }; diff --git a/test/e2e/fixture-builder.js b/test/e2e/fixture-builder.js index 6cec07fa3e81..b57bb64211f6 100644 --- a/test/e2e/fixture-builder.js +++ b/test/e2e/fixture-builder.js @@ -114,6 +114,7 @@ function defaultFixture(inputChainId = CHAIN_IDS.LOCALHOST) { fragments: {}, metaMetricsId: null, participateInMetaMetrics: false, + dataCollectionForMarketing: false, traits: {}, }, NetworkController: { diff --git a/ui/pages/settings/security-tab/metametrics-toggle/metametrics-toggle.test.tsx b/ui/pages/settings/security-tab/metametrics-toggle/metametrics-toggle.test.tsx deleted file mode 100644 index 5e93bc9feaab..000000000000 --- a/ui/pages/settings/security-tab/metametrics-toggle/metametrics-toggle.test.tsx +++ /dev/null @@ -1,88 +0,0 @@ -import React from 'react'; -import { Provider } from 'react-redux'; -import configureMockStore from 'redux-mock-store'; -import { render, fireEvent } from '@testing-library/react'; -import * as MetametricsHooks from '../../../../hooks/metamask-notifications/useMetametrics'; -import MetametricsToggle from './metametrics-toggle'; - -let mockUseSelectorReturnValue = false; - -jest.mock('react-redux', () => ({ - ...jest.requireActual('react-redux'), - useSelector: jest.fn(() => mockUseSelectorReturnValue), -})); - -const mockStore = configureMockStore(); -const initialState = { - metamask: { - isSignedIn: false, - }, -}; -const store = mockStore(initialState); - -describe('MetametricsToggle', () => { - const enableMetametricsMock = jest.fn(() => Promise.resolve()); - const disableMetametricsMock = jest.fn(() => Promise.resolve()); - - beforeEach(() => { - jest.spyOn(MetametricsHooks, 'useEnableMetametrics').mockReturnValue({ - enableMetametrics: enableMetametricsMock, - loading: false, - error: null, - }); - jest.spyOn(MetametricsHooks, 'useDisableMetametrics').mockReturnValue({ - disableMetametrics: disableMetametricsMock, - loading: false, - error: null, - }); - jest.spyOn(store, 'dispatch').mockImplementation(jest.fn()); - }); - - afterEach(() => { - jest.clearAllMocks(); - }); - - it('renders correctly', () => { - mockUseSelectorReturnValue = false; - const { getByTestId } = render( - - {}} - /> - , - ); - expect(getByTestId('profileSyncToggle')).toBeInTheDocument(); - }); - - it('calls enableMetametrics when toggle is turned on and profile syncing is disabled', () => { - mockUseSelectorReturnValue = false; - const { getByTestId } = render( - - {}} - /> - , - ); - fireEvent.click(getByTestId('toggleButton')); - expect(enableMetametricsMock).toHaveBeenCalled(); - }); - - it('calls disableMetametrics when toggle is turned off and profile syncing is enabled', () => { - mockUseSelectorReturnValue = true; - const { getByTestId } = render( - - {}} - /> - , - ); - fireEvent.click(getByTestId('toggleButton')); - expect(disableMetametricsMock).toHaveBeenCalled(); - }); -}); diff --git a/ui/pages/settings/security-tab/metametrics-toggle/metametrics-toggle.tsx b/ui/pages/settings/security-tab/metametrics-toggle/metametrics-toggle.tsx deleted file mode 100644 index 661dd7f974b4..000000000000 --- a/ui/pages/settings/security-tab/metametrics-toggle/metametrics-toggle.tsx +++ /dev/null @@ -1,130 +0,0 @@ -import React, { useContext } from 'react'; -import { useSelector } from 'react-redux'; -import { useI18nContext } from '../../../../hooks/useI18nContext'; -import { MetaMetricsContext } from '../../../../contexts/metametrics'; -import { - useEnableMetametrics, - useDisableMetametrics, -} from '../../../../hooks/metamask-notifications/useMetametrics'; -import { selectIsProfileSyncingEnabled } from '../../../../selectors/metamask-notifications/profile-syncing'; -import { selectParticipateInMetaMetrics } from '../../../../selectors/metamask-notifications/authentication'; -import { - MetaMetricsEventCategory, - MetaMetricsEventName, -} from '../../../../../shared/constants/metametrics'; -import { Box, Text } from '../../../../components/component-library'; -import ToggleButton from '../../../../components/ui/toggle-button'; -import { - Display, - FlexDirection, - JustifyContent, - TextColor, - TextVariant, -} from '../../../../helpers/constants/design-system'; - -const MetametricsToggle = ({ - dataCollectionForMarketing, - setDataCollectionForMarketing, -}: { - dataCollectionForMarketing: boolean; - setDataCollectionForMarketing: (value: boolean) => void; -}) => { - const t = useI18nContext(); - const trackEvent = useContext(MetaMetricsContext); - const { enableMetametrics, error: enableMetametricsError } = - useEnableMetametrics(); - const { disableMetametrics, error: disableMetametricsError } = - useDisableMetametrics(); - - const error = enableMetametricsError || disableMetametricsError; - - const isProfileSyncingEnabled = useSelector(selectIsProfileSyncingEnabled); - const participateInMetaMetrics = useSelector(selectParticipateInMetaMetrics); - - const handleUseParticipateInMetaMetrics = async () => { - if (participateInMetaMetrics) { - await disableMetametrics(); - trackEvent({ - category: MetaMetricsEventCategory.Settings, - event: MetaMetricsEventName.TurnOffMetaMetrics, - properties: { - isProfileSyncingEnabled, - participateInMetaMetrics, - }, - }); - - trackEvent({ - category: MetaMetricsEventCategory.Settings, - event: MetaMetricsEventName.AnalyticsPreferenceSelected, - properties: { - is_metrics_opted_in: false, - has_marketing_consent: false, - location: 'Settings', - }, - }); - } else { - await enableMetametrics(); - trackEvent({ - category: MetaMetricsEventCategory.Settings, - event: MetaMetricsEventName.TurnOnMetaMetrics, - properties: { - isProfileSyncingEnabled, - participateInMetaMetrics, - }, - }); - } - - if (dataCollectionForMarketing) { - setDataCollectionForMarketing(false); - } - }; - - return ( - - -
- {t('participateInMetaMetrics')} -
- {t('participateInMetaMetricsDescription')} -
-
- -
- -
-
- {error && ( - - - {t('notificationsSettingsBoxError')} - - - )} -
- ); -}; - -export default MetametricsToggle; diff --git a/ui/pages/settings/security-tab/security-tab.component.js b/ui/pages/settings/security-tab/security-tab.component.js index fd5b163ad6e5..5fe9c477ddeb 100644 --- a/ui/pages/settings/security-tab/security-tab.component.js +++ b/ui/pages/settings/security-tab/security-tab.component.js @@ -344,8 +344,12 @@ export default class SecurityTab extends PureComponent { renderMetaMetricsOptIn() { const { t } = this.context; - const { participateInMetaMetrics, setParticipateInMetaMetrics, dataCollectionForMarketing, setDataCollectionForMarketing } = - this.props; + const { + participateInMetaMetrics, + setParticipateInMetaMetrics, + dataCollectionForMarketing, + setDataCollectionForMarketing, + } = this.props; return (