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

fix: Move foreground state properties from metamask slice to appState slice #28703

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
3e9ed7c
Move non controller-derived properties from `metamask` slice to `appS…
MajorLift Nov 25, 2024
27acc98
fix breaking tests
MajorLift Nov 26, 2024
236191a
Narrow `unknown` entries in `AppState` type
MajorLift Nov 26, 2024
071a7b6
Fix confirmations test
MajorLift Nov 26, 2024
8899b38
Fix assets test
MajorLift Nov 26, 2024
2cc116e
Move `isInitialized` back to `metamask` slice
MajorLift Dec 2, 2024
6f908cf
Update `mapStateToProps`
MajorLift Dec 2, 2024
773f345
Update sentry UI_STATE object
MajorLift Dec 2, 2024
ca24021
Update test objects
MajorLift Dec 2, 2024
ad7eed8
e2e: fix `errors-after-init-opt-in-ui-state`
MajorLift Dec 2, 2024
670be0a
Clean up traces of removed `appState` property `gasIsLoading`
MajorLift Dec 6, 2024
537fef8
Group `appState` selectors in `ui/selectors/selectors/js` file
MajorLift Dec 6, 2024
f2da87c
Merge branch 'main' into jongsun/perf/redux/241122-move-metamask-slic…
MajorLift Dec 10, 2024
fd07d5a
Merge branch 'main' into jongsun/perf/redux/241122-move-metamask-slic…
MajorLift Dec 11, 2024
f60be42
Merge branch 'main' into jongsun/perf/redux/241122-move-metamask-slic…
MajorLift Dec 11, 2024
2cd847b
Merge branch 'main' into jongsun/perf/redux/241122-move-metamask-slic…
MajorLift Dec 18, 2024
402f00c
Add missing `appState` properties to test mocks
MajorLift Jan 8, 2025
391f5d2
Merge branch 'main' into jongsun/perf/redux/241122-move-metamask-slic…
MajorLift Jan 8, 2025
41b2bc5
Linter fix
MajorLift Jan 8, 2025
859ae89
Merge branch 'main' into jongsun/perf/redux/241122-move-metamask-slic…
MajorLift Jan 10, 2025
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
12 changes: 6 additions & 6 deletions .storybook/test-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,6 @@ const state = {
connectedAccounts: ['0x64a845a5b02460acf8a3d84503b0d68d028b4bb4'],
isInitialized: true,
isUnlocked: true,
isAccountMenuOpen: false,
rpcUrl: 'https://rawtestrpc.metamask.io/',
internalAccounts: {
accounts: {
Expand Down Expand Up @@ -677,8 +676,6 @@ const state = {
],
},
],
pendingTokens: {},
customNonceValue: '',
send: {
gasLimit: '0xcb28',
gasPrice: null,
Expand All @@ -702,7 +699,6 @@ const state = {
},
useBlockie: false,
featureFlags: {},
welcomeScreenSeen: false,
slides: [],
currentLocale: 'en',
preferences: {
Expand Down Expand Up @@ -731,7 +727,6 @@ const state = {
},
},
participateInMetaMetrics: true,
nextNonce: 71,
connectedStatusPopoverHasBeenShown: true,
swapsWelcomeMessageHasBeenShown: true,
defaultHomeActiveTabName: 'Tokens',
Expand Down Expand Up @@ -1630,6 +1625,12 @@ const state = {
openSeaEnabled: true,
},
appState: {
isAccountMenuOpen: false,
welcomeScreenSeen: false,
pendingTokens: {},
confirmationExchangeRates: {},
customNonceValue: '',
nextNonce: 71,
DDDDDanica marked this conversation as resolved.
Show resolved Hide resolved
shouldClose: false,
menuOpen: false,
modal: {
Expand Down Expand Up @@ -1665,7 +1666,6 @@ const state = {
isLoading: false,
warning: null,
buyView: {},
gasIsLoading: false,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🕵🏻‍♂️

defaultHdPaths: {
trezor: "m/44'/60'/0'/0",
ledger: "m/44'/60'/0'/0/0",
Expand Down
11 changes: 6 additions & 5 deletions app/scripts/constants/sentry-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -426,11 +426,7 @@ const flattenedBackgroundStateMask = Object.values(
export const SENTRY_UI_STATE = {
gas: true,
history: true,
metamask: {
...flattenedBackgroundStateMask,
// This property comes from the background but isn't in controller state
isInitialized: true,
// These properties are in the `metamask` slice but not in the background state
appState: {
customNonceValue: true,
isAccountMenuOpen: true,
isNetworkMenuOpen: true,
Expand All @@ -439,6 +435,11 @@ export const SENTRY_UI_STATE = {
welcomeScreenSeen: true,
slides: false,
confirmationExchangeRates: true,
},
metamask: {
...flattenedBackgroundStateMask,
// This property comes from the background but isn't in controller state
isInitialized: true,
useSafeChainsListValidation: true,
watchEthereumAccountEnabled: false,
bitcoinSupportEnabled: false,
Expand Down
1 change: 0 additions & 1 deletion docs/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ const generateGasEstimatorProps = (overrides) => ({

const generateAppState = (overrides) => ({
networkDropdownOpen: false,
gasIsLoading: false,
isLoading: false,
modal: {
open: false,
Expand Down
1 change: 0 additions & 1 deletion test/data/mock-send-state.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
"networkDropdownOpen": false,
"importNftsModal": { "open": false },
"showPermittedNetworkToastOpen": false,
"gasIsLoading": false,
"isLoading": false,
"importTokensModalOpen": false,
"modal": {
Expand Down
14 changes: 8 additions & 6 deletions test/data/mock-state.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,17 @@
"url": "https://metamask.github.io/test-dapp/"
},
"appState": {
"isAccountMenuOpen": false,
"confirmationExchangeRates": {},
"nextNonce": 71,
"welcomeScreenSeen": false,
"pendingTokens": {},
"customTokenAmount": "10",
"networkDropdownOpen": false,
DDDDDanica marked this conversation as resolved.
Show resolved Hide resolved
"importNftsModal": {
"open": false
},
"showPermittedNetworkToastOpen": false,
"gasIsLoading": false,
"isLoading": false,
"modal": {
"open": false,
Expand All @@ -27,8 +32,7 @@
"name": null
}
},
"warning": null,
"customTokenAmount": "10"
"warning": null
},
"confirmAlerts": {
"alerts": [],
Expand Down Expand Up @@ -419,11 +423,9 @@
"key": "tokenFiatAmount",
"order": "dsc",
"sortCallback": "stringNumeric"
},
"tokenNetworkFilter": {}
}
},
"ensResolutionsByAddress": {},
"isAccountMenuOpen": false,
"isUnlocked": true,
"alertEnabledness": {
"unconnectedAccount": true
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,71 @@
{
"DNS": "object",
"activeTab": "object",
"appState": "object",
"appState": {
"customNonceValue": "",
"isAccountMenuOpen": false,
"isNetworkMenuOpen": false,
"nextNonce": null,
"confirmationExchangeRates": {},
"ledgerTransportStatus": "string",
"ledgerWebHidConnectedStatus": "string",
"loadingMessage": "undefined",
"menuOpen": "boolean",
"modal": "object",
"alertOpen": "boolean",
"alertMessage": null,
"networkDropdownOpen": "boolean",
"importNftsModal": "object",
"keyringRemovalSnapModal": "object",
"importTokensModalOpen": "boolean",
"deprecatedNetworkModalOpen": "boolean",
"accountDetail": "object",
"isLoading": "boolean",
"isNftStillFetchingIndication": "boolean",
"buyView": "object",
"defaultHdPaths": "object",
"networksTabSelectedRpcUrl": "string",
"requestAccountTabs": "object",
"currentWindowTab": "object",
"gasLoadingAnimationIsShowing": "boolean",
"externalServicesOnboardingToggleState": "boolean",
"newNftAddedMessage": "string",
"removeNftMessage": "string",
"newNetworkAddedName": "string",
"editedNetwork": "undefined",
"newNetworkAddedConfigurationId": "string",
"newTokensImported": "string",
"newTokensImportedError": "string",
"onboardedInThisUISession": "boolean",
"customTokenAmount": "string",
"accountDetailsAddress": "string",
"isAddingNewNetwork": "boolean",
"isMultiRpcOnboarding": "boolean",
"errorInSettings": null,
"openMetaMaskTabs": "object",
"pendingTokens": "object",
"qrCodeData": null,
"selectedNetworkConfigurationId": "string",
"scrollToBottom": "boolean",
"sendInputCurrencySwitched": "boolean",
"shouldClose": "boolean",
"showBasicFunctionalityModal": "boolean",
"showDataDeletionErrorModal": "boolean",
"showDeleteMetaMetricsDataModal": "boolean",
"showIpfsModalOpen": "boolean",
"showKeyringRemovalSnapModal": "boolean",
"showNftDetectionEnablementToast": "boolean",
"showPermittedNetworkToastOpen": "boolean",
"showTermsOfUsePopup": "boolean",
"showWhatsNewPopup": "boolean",
"singleExceptions": "object",
"smartTransactionsError": null,
"smartTransactionsErrorMessageDismissed": "boolean",
"snapsInstallPrivacyWarningShown": "boolean",
"txId": null,
"warning": "string",
"welcomeScreenSeen": false
},
"bridge": "object",
"confirmAlerts": "object",
"confirmTransaction": "object",
Expand All @@ -12,18 +76,12 @@
"metamask": {
"isInitialized": true,
"isUnlocked": true,
"isAccountMenuOpen": false,
"isNetworkMenuOpen": false,
"internalAccounts": { "accounts": "object", "selectedAccount": "string" },
"transactions": "object",
"networkConfigurations": "object",
"addressBook": "object",
"confirmationExchangeRates": {},
"pendingTokens": "object",
"customNonceValue": "",
"useBlockie": false,
"featureFlags": {},
"welcomeScreenSeen": false,
"currentLocale": "en",
"preferences": {
"hideZeroBalanceTokens": false,
Expand All @@ -48,7 +106,6 @@
"use4ByteResolution": true,
"participateInMetaMetrics": true,
"dataCollectionForMarketing": "boolean",
"nextNonce": null,
"currencyRates": {
"ETH": {
"conversionDate": "number",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, { useContext } from 'react';
import { useSelector } from 'react-redux';
import {
getCurrentNetwork,
getPendingTokens,
getTestNetworkBackgroundColor,
getTokenList,
} from '../../../selectors';
Expand All @@ -22,7 +23,6 @@ import {
AlignItems,
FlexDirection,
} from '../../../helpers/constants/design-system';
import { getPendingTokens } from '../../../ducks/metamask/metamask';
import TokenBalance from '../../ui/token-balance/token-balance';
import { I18nContext } from '../../../contexts/i18n';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
getCurrentNetwork,
getTestNetworkBackgroundColor,
getTokenExchangeRates,
getPendingTokens,
} from '../../../selectors';
import {
addImportedTokens,
Expand Down Expand Up @@ -90,10 +91,7 @@ import {
} from '../../../helpers/utils/util';
import { tokenInfoGetter } from '../../../helpers/utils/token-util';
import { MetaMetricsContext } from '../../../contexts/metametrics';
import {
getNativeCurrency,
getPendingTokens,
} from '../../../ducks/metamask/metamask';
import { getNativeCurrency } from '../../../ducks/metamask/metamask';
import {
MetaMetricsEventCategory,
MetaMetricsEventName,
Expand Down
69 changes: 69 additions & 0 deletions ui/ducks/app/app.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -358,4 +358,73 @@ describe('App State', () => {

expect(state.errorInSettings).toBeNull();
});

it('toggles account menu', () => {
const state = reduceApp(
{},
{
type: actionConstants.TOGGLE_ACCOUNT_MENU,
},
);

expect(state.isAccountMenuOpen).toStrictEqual(true);
});

it('toggles network menu', () => {
const state = reduceApp(
{},
{
type: actionConstants.TOGGLE_NETWORK_MENU,
},
);

expect(state.isNetworkMenuOpen).toStrictEqual(true);
});

it('close welcome screen', () => {
const state = reduceApp(
{},
{
type: actionConstants.CLOSE_WELCOME_SCREEN,
},
);

expect(state.welcomeScreenSeen).toStrictEqual(true);
});

it('sets pending tokens', () => {
const payload = {
address: '0x617b3f8050a0bd94b6b1da02b4384ee5b4df13f4',
decimals: 18,
symbol: 'META',
};

const pendingTokensState = reduceApp(
{},
{
type: actionConstants.SET_PENDING_TOKENS,
payload,
},
);

expect(pendingTokensState.pendingTokens).toStrictEqual(payload);
});

it('clears pending tokens', () => {
const payload = {
address: '0x617b3f8050a0bd94b6b1da02b4384ee5b4df13f4',
decimals: 18,
symbol: 'META',
};

const pendingTokensState = {
pendingTokens: payload,
};

const state = reduceApp(pendingTokensState, {
type: actionConstants.CLEAR_PENDING_TOKENS,
});

expect(state.pendingTokens).toStrictEqual({});
});
});
Loading
Loading