diff --git a/app/scripts/constants/sentry-state.ts b/app/scripts/constants/sentry-state.ts index f18fb96d85fd..9823b2ada540 100644 --- a/app/scripts/constants/sentry-state.ts +++ b/app/scripts/constants/sentry-state.ts @@ -90,7 +90,6 @@ export const SENTRY_BACKGROUND_STATE = { termsOfUseLastAgreed: true, timeoutMinutes: true, trezorModel: true, - usedNetworks: true, }, MultichainBalancesController: { balances: false, diff --git a/app/scripts/controllers/app-state-controller.test.ts b/app/scripts/controllers/app-state-controller.test.ts index 4bc1cb63e390..f830e0ee1cdf 100644 --- a/app/scripts/controllers/app-state-controller.test.ts +++ b/app/scripts/controllers/app-state-controller.test.ts @@ -374,17 +374,6 @@ describe('AppStateController', () => { }); }); - describe('setFirstTimeUsedNetwork', () => { - it('updates the array of the first time used networks', () => { - const chainId = '0x1'; - - appStateController.setFirstTimeUsedNetwork(chainId); - expect(appStateController.store.getState().usedNetworks[chainId]).toBe( - true, - ); - }); - }); - describe('setLastInteractedConfirmationInfo', () => { it('sets information about last confirmation user has interacted with', () => { const lastInteractedConfirmationInfo = { diff --git a/app/scripts/controllers/app-state-controller.ts b/app/scripts/controllers/app-state-controller.ts index 605f307ec0e4..c506dc329e94 100644 --- a/app/scripts/controllers/app-state-controller.ts +++ b/app/scripts/controllers/app-state-controller.ts @@ -62,7 +62,6 @@ export type AppStateControllerState = { hadAdvancedGasFeesSetPriorToMigration92_3: boolean; qrHardware: Json; nftsDropdownState: Json; - usedNetworks: Record; surveyLinkLastClickedOrClosed: number | null; signatureSecurityAlertResponses: Record; // States used for displaying the changed network toast @@ -138,7 +137,6 @@ type AppStateControllerInitState = Partial< AppStateControllerState, | 'qrHardware' | 'nftsDropdownState' - | 'usedNetworks' | 'surveyLinkLastClickedOrClosed' | 'signatureSecurityAlertResponses' | 'switchedNetworkDetails' @@ -184,11 +182,6 @@ const getDefaultAppStateControllerState = ( ...initState, qrHardware: {}, nftsDropdownState: {}, - usedNetworks: { - '0x1': true, - '0x5': true, - '0x539': true, - }, surveyLinkLastClickedOrClosed: null, signatureSecurityAlertResponses: {}, switchedNetworkDetails: null, @@ -704,19 +697,6 @@ export class AppStateController extends EventEmitter { }); } - /** - * Updates the array of the first time used networks - * - * @param chainId - */ - setFirstTimeUsedNetwork(chainId: string): void { - const currentState = this.store.getState(); - const { usedNetworks } = currentState; - usedNetworks[chainId] = true; - - this.store.updateState({ usedNetworks }); - } - ///: BEGIN:ONLY_INCLUDE_IF(build-mmi) /** * Set the interactive replacement token with a url and the old refresh token diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js index a1cbabb9bcbe..1eaf354b4caf 100644 --- a/app/scripts/metamask-controller.js +++ b/app/scripts/metamask-controller.js @@ -3705,8 +3705,6 @@ export default class MetamaskController extends EventEmitter { appStateController.setShowNetworkBanner.bind(appStateController), updateNftDropDownState: appStateController.updateNftDropDownState.bind(appStateController), - setFirstTimeUsedNetwork: - appStateController.setFirstTimeUsedNetwork.bind(appStateController), setSwitchedNetworkDetails: appStateController.setSwitchedNetworkDetails.bind(appStateController), clearSwitchedNetworkDetails: diff --git a/app/scripts/migrations/134.test.ts b/app/scripts/migrations/134.test.ts new file mode 100644 index 000000000000..9b3d31db017f --- /dev/null +++ b/app/scripts/migrations/134.test.ts @@ -0,0 +1,62 @@ +import { cloneDeep } from 'lodash'; +import { migrate, version } from './134'; + +const oldVersion = 133; + +describe(`migration #${version}`, () => { + it('updates the version metadata', async () => { + const oldStorage = { + meta: { version: oldVersion }, + data: {}, + }; + + const newStorage = await migrate(oldStorage); + + expect(newStorage.meta).toStrictEqual({ version }); + }); + + it('Does nothing if `usedNetworks` is not in the `AppStateController` state', async () => { + const oldState = { + AppStateController: { + timeoutMinutes: 0, + }, + }; + + const transformedState = await migrate({ + meta: { version: oldVersion }, + data: cloneDeep(oldState), + }); + + expect(transformedState.data).toStrictEqual(oldState); + }); + + it('Removes `usedNetworks` from the `AppStateController` state', async () => { + const oldState: { + AppStateController: { + timeoutMinutes: number; + usedNetworks?: Record; + }; + } = { + AppStateController: { + timeoutMinutes: 0, + usedNetworks: { + '0x1': true, + '0x5': true, + '0x539': true, + }, + }, + }; + const expectedState = { + AppStateController: { + timeoutMinutes: 0, + }, + }; + + const transformedState = await migrate({ + meta: { version: oldVersion }, + data: cloneDeep(oldState), + }); + + expect(transformedState.data).toStrictEqual(expectedState); + }); +}); diff --git a/app/scripts/migrations/134.ts b/app/scripts/migrations/134.ts new file mode 100644 index 000000000000..e11b2abd9625 --- /dev/null +++ b/app/scripts/migrations/134.ts @@ -0,0 +1,41 @@ +import { hasProperty, isObject } from '@metamask/utils'; +import { cloneDeep } from 'lodash'; + +type VersionedData = { + meta: { version: number }; + data: Record; +}; + +export const version = 134; + +/** + * This migration removes `usedNetworks` from `AppStateController` state. + * + * @param originalVersionedData - Versioned MetaMask extension state, exactly what we persist to dist. + * @param originalVersionedData.meta - State metadata. + * @param originalVersionedData.meta.version - The current state version. + * @param originalVersionedData.data - The persisted MetaMask state, keyed by controller. + * @returns Updated versioned MetaMask extension state. + */ +export async function migrate( + originalVersionedData: VersionedData, +): Promise { + const versionedData = cloneDeep(originalVersionedData); + versionedData.meta.version = version; + transformState(versionedData.data); + return versionedData; +} + +function transformState( + state: Record, +): Record { + if ( + hasProperty(state, 'AppStateController') && + isObject(state.AppStateController) && + hasProperty(state.AppStateController, 'usedNetworks') + ) { + console.log('Removing usedNetworks from AppStateController'); + delete state.AppStateController.usedNetworks; + } + return state; +} diff --git a/app/scripts/migrations/index.js b/app/scripts/migrations/index.js index e95a9bf7a9da..887732ad9dbc 100644 --- a/app/scripts/migrations/index.js +++ b/app/scripts/migrations/index.js @@ -154,6 +154,7 @@ const migrations = [ require('./131'), require('./132'), require('./133'), + require('./134'), ]; export default migrations; diff --git a/test/data/mock-send-state.json b/test/data/mock-send-state.json index 73468aca6171..f9c602808719 100644 --- a/test/data/mock-send-state.json +++ b/test/data/mock-send-state.json @@ -140,11 +140,6 @@ "isAccountMenuOpen": false, "isUnlocked": true, "completedOnboarding": true, - "usedNetworks": { - "0x1": true, - "0x5": true, - "0x539": true - }, "showTestnetMessageInDropdown": true, "alertEnabledness": { "unconnectedAccount": true diff --git a/test/e2e/default-fixture.js b/test/e2e/default-fixture.js index c2fba9d63424..a6845e40ec4c 100644 --- a/test/e2e/default-fixture.js +++ b/test/e2e/default-fixture.js @@ -115,12 +115,6 @@ function defaultFixture(inputChainId = CHAIN_IDS.LOCALHOST) { trezorModel: null, newPrivacyPolicyToastClickedOrClosed: true, newPrivacyPolicyToastShownDate: Date.now(), - usedNetworks: { - [CHAIN_IDS.MAINNET]: true, - [CHAIN_IDS.LINEA_MAINNET]: true, - [CHAIN_IDS.GOERLI]: true, - [CHAIN_IDS.LOCALHOST]: true, - }, snapsInstallPrivacyWarningShown: true, }, BridgeController: { diff --git a/test/e2e/fixture-builder.js b/test/e2e/fixture-builder.js index 844c4766db3e..94e515d46ff6 100644 --- a/test/e2e/fixture-builder.js +++ b/test/e2e/fixture-builder.js @@ -40,12 +40,6 @@ function onboardingFixture() { '__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, - }, }, NetworkController: { ...mockNetworkStateOld({ diff --git a/test/e2e/tests/metrics/state-snapshots/errors-after-init-opt-in-background-state.json b/test/e2e/tests/metrics/state-snapshots/errors-after-init-opt-in-background-state.json index 1df430082f3e..8351032761a7 100644 --- a/test/e2e/tests/metrics/state-snapshots/errors-after-init-opt-in-background-state.json +++ b/test/e2e/tests/metrics/state-snapshots/errors-after-init-opt-in-background-state.json @@ -45,7 +45,6 @@ "nftsDropdownState": {}, "termsOfUseLastAgreed": "number", "qrHardware": {}, - "usedNetworks": { "0x1": true, "0x5": true, "0x539": true }, "snapsInstallPrivacyWarningShown": true, "surveyLinkLastClickedOrClosed": "object", "signatureSecurityAlertResponses": "object", diff --git a/test/e2e/tests/metrics/state-snapshots/errors-after-init-opt-in-ui-state.json b/test/e2e/tests/metrics/state-snapshots/errors-after-init-opt-in-ui-state.json index 9988234cac2e..5d79ca5964b8 100644 --- a/test/e2e/tests/metrics/state-snapshots/errors-after-init-opt-in-ui-state.json +++ b/test/e2e/tests/metrics/state-snapshots/errors-after-init-opt-in-ui-state.json @@ -95,7 +95,6 @@ "nftsDropdownState": {}, "termsOfUseLastAgreed": "number", "qrHardware": {}, - "usedNetworks": { "0x1": true, "0x5": true, "0x539": true }, "snapsInstallPrivacyWarningShown": true, "surveyLinkLastClickedOrClosed": "object", "signatureSecurityAlertResponses": "object", diff --git a/test/e2e/tests/metrics/state-snapshots/errors-before-init-opt-in-background-state.json b/test/e2e/tests/metrics/state-snapshots/errors-before-init-opt-in-background-state.json index 07b292d33b3b..1a1009c02c23 100644 --- a/test/e2e/tests/metrics/state-snapshots/errors-before-init-opt-in-background-state.json +++ b/test/e2e/tests/metrics/state-snapshots/errors-before-init-opt-in-background-state.json @@ -42,12 +42,6 @@ "trezorModel": null, "newPrivacyPolicyToastClickedOrClosed": "boolean", "newPrivacyPolicyToastShownDate": "number", - "usedNetworks": { - "0x1": true, - "0xe708": true, - "0x5": true, - "0x539": true - }, "snapsInstallPrivacyWarningShown": true }, "CurrencyController": { diff --git a/test/e2e/tests/metrics/state-snapshots/errors-before-init-opt-in-ui-state.json b/test/e2e/tests/metrics/state-snapshots/errors-before-init-opt-in-ui-state.json index f997b89bcd28..e7fe6fd2a641 100644 --- a/test/e2e/tests/metrics/state-snapshots/errors-before-init-opt-in-ui-state.json +++ b/test/e2e/tests/metrics/state-snapshots/errors-before-init-opt-in-ui-state.json @@ -42,12 +42,6 @@ "trezorModel": null, "newPrivacyPolicyToastClickedOrClosed": "boolean", "newPrivacyPolicyToastShownDate": "number", - "usedNetworks": { - "0x1": true, - "0xe708": true, - "0x5": true, - "0x539": true - }, "snapsInstallPrivacyWarningShown": true }, "BridgeController": { diff --git a/test/integration/data/integration-init-state.json b/test/integration/data/integration-init-state.json index 0c3853035080..ac58306adca8 100644 --- a/test/integration/data/integration-init-state.json +++ b/test/integration/data/integration-init-state.json @@ -2052,15 +2052,6 @@ "useSafeChainsListValidation": true, "useTokenDetection": false, "useTransactionSimulations": true, - "usedNetworks": { - "0xaa36a7": { - "rpcUrl": "https://sepolia.infura.io/v3/dummy_key", - "chainId": "0xaa36a7", - "nickname": "Sepolia Test Network", - "ticker": "ETH", - "blockExplorerUrl": "https://sepolia.etherscan.io" - } - }, "userOperations": {}, "versionFileETag": "W/\"598946a37f16c5b882a0bebbadf4509f\"", "versionInfo": [], diff --git a/test/integration/data/onboarding-completion-route.json b/test/integration/data/onboarding-completion-route.json index b2c19536a138..33d0680ab8a0 100644 --- a/test/integration/data/onboarding-completion-route.json +++ b/test/integration/data/onboarding-completion-route.json @@ -463,7 +463,6 @@ "useSafeChainsListValidation": true, "useTokenDetection": true, "useTransactionSimulations": true, - "usedNetworks": { "0x1": true, "0x5": true, "0x539": true }, "userOperations": {}, "versionFileETag": "", "versionInfo": [], diff --git a/ui/components/ui/new-network-info/new-network-info.js b/ui/components/ui/new-network-info/new-network-info.js index 15a11918afc1..9d4df0ec63ec 100644 --- a/ui/components/ui/new-network-info/new-network-info.js +++ b/ui/components/ui/new-network-info/new-network-info.js @@ -24,7 +24,6 @@ import { getParticipateInMetaMetrics, getDataCollectionForMarketing, } from '../../../selectors'; -import { setFirstTimeUsedNetwork } from '../../../store/actions'; import { PickerNetwork, Text, @@ -56,7 +55,6 @@ export default function NewNetworkInfo() { const onCloseClick = () => { setShowPopup(false); - setFirstTimeUsedNetwork(providerConfig.chainId); }; const checkTokenDetection = useCallback(async () => { diff --git a/ui/pages/routes/routes.component.test.js b/ui/pages/routes/routes.component.test.js index 14490ad6e146..e661099e1aa2 100644 --- a/ui/pages/routes/routes.component.test.js +++ b/ui/pages/routes/routes.component.test.js @@ -225,12 +225,6 @@ describe('Routes Component', () => { }, selectedAccount: account.id, }, - usedNetworks: { - '0x1': true, - '0x5': true, - '0x539': true, - [mockNewlyAddedNetwork.chainId]: false, - }, networkConfigurationsByChainId: { ...mockState.metamask.networkConfigurationsByChainId, [mockNewlyAddedNetwork.chainId]: mockNewlyAddedNetwork, @@ -312,7 +306,6 @@ describe('toast display', () => { announcements: {}, approvalFlows: [], completedOnboarding: true, - usedNetworks: [], pendingApprovals: {}, pendingApprovalCount: 0, preferences: { @@ -341,7 +334,6 @@ describe('toast display', () => { announcements: {}, approvalFlows: [], completedOnboarding: true, - usedNetworks: [], pendingApprovals: {}, pendingApprovalCount: 0, swapsState: { swapsFeatureIsLive: true }, diff --git a/ui/pages/routes/routes.container.js b/ui/pages/routes/routes.container.js index 28f4291ee37c..0342fc2e15d1 100644 --- a/ui/pages/routes/routes.container.js +++ b/ui/pages/routes/routes.container.js @@ -8,7 +8,6 @@ import { } from '../../../shared/modules/selectors/networks'; import { getAllAccountsOnNetworkAreEmpty, - getIsNetworkUsed, getNetworkIdentifier, getPreferences, getTheme, @@ -95,7 +94,6 @@ function mapStateToProps(state) { providerType: getProviderConfig(state).type, theme: getTheme(state), sendStage: getSendStage(state), - isNetworkUsed: getIsNetworkUsed(state), allAccountsOnNetworkAreEmpty: getAllAccountsOnNetworkAreEmpty(state), isTestNet: getIsTestnet(state), showExtensionInFullSizeView: getShowExtensionInFullSizeView(state), diff --git a/ui/selectors/selectors.js b/ui/selectors/selectors.js index 2baaa1a0c931..deb18c1c5309 100644 --- a/ui/selectors/selectors.js +++ b/ui/selectors/selectors.js @@ -2726,13 +2726,6 @@ export function getBlockExplorerLinkText( return blockExplorerLinkText; } -export function getIsNetworkUsed(state) { - const chainId = getCurrentChainId(state); - const { usedNetworks } = state.metamask; - - return Boolean(usedNetworks[chainId]); -} - export function getAllAccountsOnNetworkAreEmpty(state) { const balances = getMetaMaskCachedBalances(state) ?? {}; const hasNoNativeFundsOnAnyAccounts = Object.values(balances).every( diff --git a/ui/store/actions.ts b/ui/store/actions.ts index 9b402f476a7e..01b8b9e458d9 100644 --- a/ui/store/actions.ts +++ b/ui/store/actions.ts @@ -5201,10 +5201,6 @@ export function setUseTransactionSimulations(val: boolean): void { } } -export function setFirstTimeUsedNetwork(chainId: string) { - return submitRequestToBackground('setFirstTimeUsedNetwork', [chainId]); -} - // QR Hardware Wallets export async function submitQRHardwareCryptoHDKey(cbor: Hex) { await submitRequestToBackground('submitQRHardwareCryptoHDKey', [cbor]);