Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion app/scripts/constants/sentry-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ export const SENTRY_BACKGROUND_STATE = {
currentPopupId: false,
onboardingDate: false,
currentExtensionPopupId: false,
defaultHomeActiveTabName: true,
enableEnforcedSimulations: true,
enableEnforcedSimulationsForTransactions: false,
fullScreenGasPollTokens: true,
Expand Down
17 changes: 0 additions & 17 deletions app/scripts/controllers/app-state-controller.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
ORIGIN_METAMASK,
POLLING_TOKEN_ENVIRONMENT_TYPES,
} from '../../../shared/constants/app';
import { AccountOverviewTabKey } from '../../../shared/constants/app-state';
import { MINUTE } from '../../../shared/constants/time';
import { AppStateController } from './app-state-controller';
import type {
Expand Down Expand Up @@ -188,18 +187,6 @@ describe('AppStateController', () => {
});
});

describe('setDefaultHomeActiveTabName', () => {
it('sets the default home tab name', async () => {
await withController(({ controller }) => {
controller.setDefaultHomeActiveTabName(AccountOverviewTabKey.Activity);

expect(controller.state.defaultHomeActiveTabName).toBe(
AccountOverviewTabKey.Activity,
);
});
});
});

describe('setConnectedStatusPopoverHasBeenShown', () => {
it('sets connected status popover as shown', async () => {
await withController(({ controller }) => {
Expand Down Expand Up @@ -763,7 +750,6 @@ describe('AppStateController', () => {
"connectedStatusPopoverHasBeenShown": true,
"currentExtensionPopupId": 0,
"currentPopupId": 0,
"defaultHomeActiveTabName": null,
"enableEnforcedSimulations": true,
"enableEnforcedSimulationsForTransactions": {},
"enforcedSimulationsSlippage": 10,
Expand Down Expand Up @@ -852,7 +838,6 @@ describe('AppStateController', () => {
"connectedStatusPopoverHasBeenShown": true,
"currentExtensionPopupId": 0,
"currentPopupId": 0,
"defaultHomeActiveTabName": null,
"enableEnforcedSimulations": true,
"enableEnforcedSimulationsForTransactions": {},
"enforcedSimulationsSlippage": 10,
Expand Down Expand Up @@ -937,7 +922,6 @@ describe('AppStateController', () => {
"browserEnvironment": {},
"canTrackWalletFundsObtained": true,
"connectedStatusPopoverHasBeenShown": true,
"defaultHomeActiveTabName": null,
"enableEnforcedSimulations": true,
"enforcedSimulationsSlippage": 10,
"hadAdvancedGasFeesSetPriorToMigration92_3": false,
Expand Down Expand Up @@ -1017,7 +1001,6 @@ describe('AppStateController', () => {
"connectedStatusPopoverHasBeenShown": true,
"currentExtensionPopupId": 0,
"currentPopupId": 0,
"defaultHomeActiveTabName": null,
"enableEnforcedSimulations": true,
"enableEnforcedSimulationsForTransactions": {},
"enforcedSimulationsSlippage": 10,
Expand Down
21 changes: 0 additions & 21 deletions app/scripts/controllers/app-state-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
import { LastInteractedConfirmationInfo } from '../../../shared/types/confirm';
import { SecurityAlertResponse } from '../lib/ppom/types';
import {
AccountOverviewTabKey,

Check failure on line 38 in app/scripts/controllers/app-state-controller.ts

View workflow job for this annotation

GitHub Actions / test-lint / Test lint

'AccountOverviewTabKey' is defined but never used
CarouselSlide,
NetworkConnectionBanner,
} from '../../../shared/constants/app-state';
Expand Down Expand Up @@ -73,7 +73,6 @@
// States used for displaying the changed network toast
currentExtensionPopupId: number;
currentPopupId?: number;
defaultHomeActiveTabName: AccountOverviewTabKey | null;
enableEnforcedSimulations: boolean;
enableEnforcedSimulationsForTransactions: Record<string, boolean>;
enforcedSimulationsSlippage: number;
Expand Down Expand Up @@ -234,7 +233,6 @@
appActiveTab: undefined,
browserEnvironment: {},
connectedStatusPopoverHasBeenShown: true,
defaultHomeActiveTabName: null,
enableEnforcedSimulations: true,
enableEnforcedSimulationsForTransactions: {},
enforcedSimulationsSlippage: 10,
Expand Down Expand Up @@ -342,12 +340,6 @@
includeInDebugSnapshot: true,
usedInUi: true,
},
defaultHomeActiveTabName: {
includeInStateLogs: true,
persist: true,
includeInDebugSnapshot: true,
usedInUi: true,
},
enableEnforcedSimulations: {
includeInStateLogs: true,
persist: true,
Expand Down Expand Up @@ -757,19 +749,6 @@
this.#acceptApproval();
}

/**
* Sets the default home tab
*
* @param defaultHomeActiveTabName - the tab name
*/
setDefaultHomeActiveTabName(
defaultHomeActiveTabName: AccountOverviewTabKey | null,
): void {
this.update((state) => {
state.defaultHomeActiveTabName = defaultHomeActiveTabName;
});
}

/**
* Record that the user has seen the connected status info popover
*/
Expand Down
2 changes: 0 additions & 2 deletions app/scripts/metamask-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -2768,8 +2768,6 @@ export default class MetamaskController extends EventEmitter {
appStateController.setCurrentExtensionPopupId.bind(appStateController),
setBrowserEnvironment:
appStateController.setBrowserEnvironment.bind(appStateController),
setDefaultHomeActiveTabName:
appStateController.setDefaultHomeActiveTabName.bind(appStateController),
setConnectedStatusPopoverHasBeenShown:
appStateController.setConnectedStatusPopoverHasBeenShown.bind(
appStateController,
Expand Down
1 change: 0 additions & 1 deletion shared/types/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ export type ControllerStatePropertiesEnumerated = {
pendingApprovalCount: ApprovalControllerState['pendingApprovalCount'];
timeoutMinutes: AppStateControllerState['timeoutMinutes'];
connectedStatusPopoverHasBeenShown: AppStateControllerState['connectedStatusPopoverHasBeenShown'];
defaultHomeActiveTabName: AppStateControllerState['defaultHomeActiveTabName'];
browserEnvironment: AppStateControllerState['browserEnvironment'];
popupGasPollTokens: AppStateControllerState['popupGasPollTokens'];
notificationGasPollTokens: AppStateControllerState['notificationGasPollTokens'];
Expand Down
1 change: 0 additions & 1 deletion test/e2e/default-fixture.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ function defaultFixture(inputChainId = CHAIN_IDS.LOCALHOST) {
connectedStatusPopoverHasBeenShown: true,
termsOfUseLastAgreed:
'__FIXTURE_SUBSTITUTION__currentDateInMilliseconds',
defaultHomeActiveTabName: null,
fullScreenGasPollTokens: [],
notificationGasPollTokens: [],
popupGasPollTokens: [],
Expand Down
1 change: 0 additions & 1 deletion test/e2e/fixtures/onboarding-fixture.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
"os": "mac"
},
"connectedStatusPopoverHasBeenShown": true,
"defaultHomeActiveTabName": null,
"enableEnforcedSimulations": true,
"enforcedSimulationsSlippage": 10,
"hadAdvancedGasFeesSetPriorToMigration92_3": false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
"browserEnvironment": { "os": "string", "browser": "string" },
"canTrackWalletFundsObtained": false,
"connectedStatusPopoverHasBeenShown": true,
"defaultHomeActiveTabName": null,
"enableEnforcedSimulations": true,
"enableEnforcedSimulationsForTransactions": "object",
"enforcedSimulationsSlippage": "number",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@
"appActiveTab": "object",
"browserEnvironment": { "os": "string", "browser": "string" },
"connectedStatusPopoverHasBeenShown": true,
"defaultHomeActiveTabName": null,
"enableEnforcedSimulations": true,
"enableEnforcedSimulationsForTransactions": "object",
"enforcedSimulationsSlippage": "number",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
"nftsDropdownState": {},
"connectedStatusPopoverHasBeenShown": true,
"termsOfUseLastAgreed": "number",
"defaultHomeActiveTabName": null,
"fullScreenGasPollTokens": "object",
"notificationGasPollTokens": "object",
"popupGasPollTokens": "object",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
"nftsDropdownState": {},
"connectedStatusPopoverHasBeenShown": true,
"termsOfUseLastAgreed": "number",
"defaultHomeActiveTabName": null,
"fullScreenGasPollTokens": "object",
"notificationGasPollTokens": "object",
"popupGasPollTokens": "object",
Expand Down
1 change: 0 additions & 1 deletion test/integration/data/integration-init-state.json
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,6 @@
}
}
},
"defaultHomeActiveTabName": "activity",
"desktopEnabled": false,
"detectedTokens": [],
"dismissSeedBackUpReminder": false,
Expand Down
1 change: 0 additions & 1 deletion test/integration/data/onboarding-completion-route.json
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@
"customNonceValue": "",
"database": null,
"databaseUnavailable": false,
"defaultHomeActiveTabName": null,
"desktopEnabled": false,
"detectedTokens": [],
"dismissSeedBackUpReminder": false,
Expand Down
1 change: 0 additions & 1 deletion ui/components/app/wallet-overview/eth-overview.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import {
} from '../../../../shared/constants/metametrics';
import EthOverview from './eth-overview';

// We need to mock `dispatch` since we use it for `setDefaultHomeActiveTabName`.
const mockDispatch = jest.fn().mockReturnValue(() => jest.fn());
jest.mock('react-redux', () => ({
...jest.requireActual('react-redux'),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
import { SolScope } from '@metamask/keyring-api';
import { renderHookWithProvider } from '../../../../../test/lib/render-helpers-navigate';
import {
sendMultichainTransaction,
setDefaultHomeActiveTabName,
} from '../../../../store/actions';
import { sendMultichainTransaction } from '../../../../store/actions';
import { SOLANA_WALLET_SNAP_ID } from '../../../../../shared/lib/accounts/solana-wallet-snap';
import { CONFIRMATION_V_NEXT_ROUTE } from '../../../../helpers/constants/routes';
import { mockMultichainNetworkState } from '../../../../../test/stub/networks';
import { useHandleSendNonEvm } from './useHandleSendNonEvm';

jest.mock('../../../../store/actions', () => ({
sendMultichainTransaction: jest.fn(),
setDefaultHomeActiveTabName: jest.fn(),
}));

const mockDispatch = jest.fn();
Expand Down Expand Up @@ -65,7 +61,6 @@ const mockState = {
requestData: {},
},
],
defaultHomeActiveTabName: 'activity',
selectedMultichainNetworkChainId: SolScope.Mainnet,
isEvmSelected: false,
remoteFeatureFlags: {
Expand Down Expand Up @@ -147,8 +142,6 @@ describe('useHandleSendNonEvm', () => {
const handleSendNonEvm = result.current;

await handleSendNonEvm();

expect(setDefaultHomeActiveTabName).toHaveBeenCalledWith('activity');
});

describe('when a caipAssetType is provided', () => {
Expand Down
29 changes: 15 additions & 14 deletions ui/components/app/wallet-overview/hooks/useHandleSendNonEvm.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import { SnapId } from '@metamask/snaps-sdk';
import { parseCaipAssetType, CaipAssetType } from '@metamask/utils';
import { useEffect } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import { useNavigate } from 'react-router-dom-v5-compat';
import {
sendMultichainTransaction,
setDefaultHomeActiveTabName,
} from '../../../../store/actions';
import { useSelector } from 'react-redux';
import { useNavigate, useLocation } from 'react-router-dom-v5-compat';
import { sendMultichainTransaction } from '../../../../store/actions';
import {
getMemoizedUnapprovedTemplatedConfirmations,
getSelectedInternalAccount,
} from '../../../../selectors';
import { getSelectedMultichainNetworkConfiguration } from '../../../../selectors/multichain/networks';
import { isMultichainWalletSnap } from '../../../../../shared/lib/accounts/snaps';
import { CONFIRMATION_V_NEXT_ROUTE } from '../../../../helpers/constants/routes';
import {
CONFIRMATION_V_NEXT_ROUTE,
DEFAULT_ROUTE,
} from '../../../../helpers/constants/routes';

/**
* Use this hook to trigger the send flow for non-EVM accounts.
Expand All @@ -31,12 +31,11 @@ export const useHandleSendNonEvm = (caipAssetType?: CaipAssetType) => {

const account = useSelector(getSelectedInternalAccount);
const navigate = useNavigate();
const dispatch = useDispatch();
const location = useLocation();

const currentActivityTabName = useSelector(
// @ts-expect-error TODO: fix state type
(state) => state.metamask.defaultHomeActiveTabName,
);
// Get the current tab from URL query params
const params = new URLSearchParams(location.search);
const currentTab = params.get('tab');

const unapprovedTemplatedConfirmations = useSelector(
getMemoizedUnapprovedTemplatedConfirmations,
Expand Down Expand Up @@ -92,15 +91,17 @@ export const useHandleSendNonEvm = (caipAssetType?: CaipAssetType) => {
try {
// FIXME: We switch the tab before starting the send flow (we
// faced some inconsistencies when changing it after).
await dispatch(setDefaultHomeActiveTabName('activity'));
navigate(`${DEFAULT_ROUTE}?tab=activity`);
await sendMultichainTransaction(account.metadata.snap.id, {
account: account.id,
scope: chainId,
assetType: assetTypeToUse,
});
} catch (error) {
// Restore the previous tab in case of any error (see FIXME comment above).
await dispatch(setDefaultHomeActiveTabName(currentActivityTabName));
if (currentTab) {
navigate(`${DEFAULT_ROUTE}?tab=${currentTab}`);
}
}
};
};
2 changes: 0 additions & 2 deletions ui/components/app/wallet-overview/non-evm-overview.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import useMultiPolling from '../../../hooks/useMultiPolling';
import { BITCOIN_WALLET_SNAP_ID } from '../../../../shared/lib/accounts/bitcoin-wallet-snap';
import NonEvmOverview from './non-evm-overview';

// We need to mock `dispatch` since we use it for `setDefaultHomeActiveTabName`.
const mockDispatch = jest.fn().mockReturnValue(() => jest.fn());
jest.mock('react-redux', () => ({
...jest.requireActual('react-redux'),
Expand All @@ -29,7 +28,6 @@ jest.mock('react-redux', () => ({
jest.mock('../../../store/actions', () => ({
handleSnapRequest: jest.fn(),
sendMultichainTransaction: jest.fn(),
setDefaultHomeActiveTabName: jest.fn(),
tokenBalancesStartPolling: jest.fn().mockResolvedValue('pollingToken'),
tokenBalancesStopPollingByPollingToken: jest.fn(),
}));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { useState, useCallback, useContext, useEffect } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import { useSearchParams } from 'react-router-dom-v5-compat';
import {
BtcAccountType,
EthAccountType,
Expand All @@ -16,7 +17,6 @@ import { MetaMetricsContext } from '../../../contexts/metametrics';
import {
getAllChainsToPoll,
getConnectedSubjectsForAllAddresses,
getDefaultHomeActiveTabName,
getHDEntropyIndex,
getOriginOfCurrentTab,
getSelectedInternalAccount,
Expand Down Expand Up @@ -75,11 +75,20 @@ export const MultichainAccountListMenu = ({
) as AccountConnections;
const currentTabOrigin = useSelector(getOriginOfCurrentTab);
const dispatch = useDispatch();
const [searchParams] = useSearchParams();

const walletAccountCollection = useSelector(getWalletsWithAccountsSimplified);
const defaultHomeActiveTabName: AccountOverviewTabKey = useSelector(
getDefaultHomeActiveTabName,
);

// Get current tab from URL query parameters
const currentTabFromUrl = searchParams.get('tab');
const currentTab: AccountOverviewTabKey =
currentTabFromUrl &&
Object.values(AccountOverviewTabKey).includes(
currentTabFromUrl as AccountOverviewTabKey,
)
? (currentTabFromUrl as AccountOverviewTabKey)
: AccountOverviewTabKey.Tokens;

const [searchPattern, setSearchPattern] = useState<string>('');

// Here we are getting the keyring of the last selected account
Expand All @@ -98,26 +107,15 @@ export const MultichainAccountListMenu = ({
},
});
endTrace({
name: ACCOUNT_OVERVIEW_TAB_KEY_TO_TRACE_NAME_MAP[
defaultHomeActiveTabName
],
name: ACCOUNT_OVERVIEW_TAB_KEY_TO_TRACE_NAME_MAP[currentTab],
});
trace({
name: ACCOUNT_OVERVIEW_TAB_KEY_TO_TRACE_NAME_MAP[
defaultHomeActiveTabName
],
name: ACCOUNT_OVERVIEW_TAB_KEY_TO_TRACE_NAME_MAP[currentTab],
});
dispatch(setSelectedAccount(account.address));
dispatch(detectNfts(allChainIds));
},
[
dispatch,
onClose,
trackEvent,
defaultHomeActiveTabName,
hdEntropyIndex,
allChainIds,
],
[dispatch, onClose, trackEvent, currentTab, hdEntropyIndex, allChainIds],
);

const onSearchBarChange = useCallback(
Expand Down
Loading
Loading