Skip to content

Commit

Permalink
Merge MetamaskState defined in metametrics-controller into `initi…
Browse files Browse the repository at this point in the history
…alMetamaskState`
  • Loading branch information
MajorLift committed Nov 27, 2024
1 parent e7cc0eb commit 9033a25
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 49 deletions.
46 changes: 3 additions & 43 deletions app/scripts/controllers/metametrics-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ import {
} from 'lodash';
import { bufferToHex, keccak } from 'ethereumjs-util';
import { v4 as uuidv4 } from 'uuid';
import { NameControllerState, NameType } from '@metamask/name-controller';
import { AccountsControllerState } from '@metamask/accounts-controller';
import { NameType } from '@metamask/name-controller';
import {
getErrorMessage,
Hex,
Expand All @@ -23,22 +22,17 @@ import {
NetworkControllerGetNetworkClientByIdAction,
NetworkControllerGetStateAction,
NetworkControllerNetworkDidChangeEvent,
NetworkState,
} from '@metamask/network-controller';
import { Browser } from 'webextension-polyfill';
import {
Nft,
NftControllerState,
TokensControllerState,
} from '@metamask/assets-controllers';
import { Nft } from '@metamask/assets-controllers';
import { captureException as sentryCaptureException } from '@sentry/browser';
import {
BaseController,
ControllerGetStateAction,
ControllerStateChangeEvent,
RestrictedControllerMessenger,
} from '@metamask/base-controller';
import { AddressBookControllerState } from '@metamask/address-book-controller';
import type { MemStoreControllersComposedState } from '../metamask-controller-stores';
import { ENVIRONMENT_TYPE_BACKGROUND } from '../../../shared/constants/app';
import {
METAMETRICS_ANONYMOUS_ID,
Expand All @@ -65,7 +59,6 @@ import {
AnonymousTransactionMetaMetricsEvent,
TransactionMetaMetricsEvent,
} from '../../../shared/constants/transaction';
import { LedgerTransportTypes } from '../../../shared/constants/hardware-wallets';
import Analytics from '../lib/segment/analytics';

///: BEGIN:ONLY_INCLUDE_IF(build-main)
Expand Down Expand Up @@ -144,39 +137,6 @@ const exceptionsToFilter: Record<string, boolean> = {
*/
type SegmentEventType = 'identify' | 'track' | 'page';

// TODO: Complete MetaMaskState by adding the full state definition and relocate it after the background is converted to TypeScript.
export type MetaMaskState = {
ledgerTransportType: LedgerTransportTypes;
networkConfigurationsByChainId: NetworkState['networkConfigurationsByChainId'];
internalAccounts: AccountsControllerState['internalAccounts'];
allNfts: NftControllerState['allNfts'];
allTokens: TokensControllerState['allTokens'];
theme: string;
participateInMetaMetrics: boolean;
dataCollectionForMarketing: boolean;
ShowNativeTokenAsMainBalance: boolean;
useNftDetection: PreferencesControllerState['useNftDetection'];
openSeaEnabled: PreferencesControllerState['openSeaEnabled'];
securityAlertsEnabled: PreferencesControllerState['securityAlertsEnabled'];
useTokenDetection: PreferencesControllerState['useTokenDetection'];
tokenSortConfig: PreferencesControllerState['preferences']['tokenSortConfig'];
names: NameControllerState['names'];
security_providers: string[];
addressBook: AddressBookControllerState['addressBook'];
currentCurrency: string;
preferences: {
privacyMode: PreferencesControllerState['preferences']['privacyMode'];
tokenNetworkFilter: string[];
};
///: BEGIN:ONLY_INCLUDE_IF(build-mmi)
custodyAccountDetails: {
[address: string]: {
custodianName: string;
};
};
///: END:ONLY_INCLUDE_IF
};

/**
* {@link MetaMetricsController}'s metadata.
*
Expand Down
4 changes: 2 additions & 2 deletions shared/constants/metametrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -455,11 +455,11 @@ export type MetaMetricsUserTraits = {
/**
* Does the user opt in for metrics
*/
is_metrics_opted_in?: boolean;
is_metrics_opted_in?: boolean | null;
/**
* Does the user accepted marketing consent
*/
has_marketing_consent?: boolean;
has_marketing_consent?: boolean | null;
/**
* The date the extension was installed.
*/
Expand Down
40 changes: 36 additions & 4 deletions ui/ducks/metamask/constants.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import { Preferences } from '../../../app/scripts/controllers/preferences-controller';
import { NameType } from '@metamask/name-controller';
import { getDefaultPreferencesControllerState } from '../../../app/scripts/controllers/preferences-controller';
import { MemStoreControllersComposedState } from '../../../app/scripts/metamask-controller-stores';
import { DEFAULT_AUTO_LOCK_TIME_LIMIT } from '../../../shared/constants/preferences';
import {
DEFAULT_AUTO_LOCK_TIME_LIMIT,
ThemeType,
} from '../../../shared/constants/preferences';
import { LedgerTransportTypes } from '../../../shared/constants/hardware-wallets';

export const initialMetamaskState: Partial<{
[ControllerName in keyof MemStoreControllersComposedState]: Partial<
Expand All @@ -26,6 +31,7 @@ export const initialMetamaskState: Partial<{
approvalFlows: [],
},
CurrencyController: {
currentCurrency: 'usd',
currencyRates: {
ETH: {
conversionRate: null,
Expand All @@ -50,33 +56,59 @@ export const initialMetamaskState: Partial<{
participateInMetaMetrics: null,
dataCollectionForMarketing: null,
},
NameController: {
names: {
[NameType.ETHEREUM_ADDRESS]: {},
},
},
NetworkController: {
selectedNetworkClientId: '',
networkConfigurationsByChainId: {},
networksMetadata: {},
},
NftController: {
allNfts: {},
},
OnboardingController: {
firstTimeFlowType: null,
completedOnboarding: false,
},
PreferencesController: {
...getDefaultPreferencesControllerState(),
theme: ThemeType.os,
useBlockie: false,
use4ByteResolution: true,
useNftDetection: true,
useTokenDetection: true,
openSeaEnabled: true,
securityAlertsEnabled: true,
featureFlags: {},
currentLocale: '',
knownMethodData: {},
ledgerTransportType: undefined,
// Ledger transport type is deprecated. We currently only support webhid
// on chrome, and u2f on firefox.
ledgerTransportType: window.navigator.hid
? LedgerTransportTypes.webhid
: LedgerTransportTypes.u2f,
preferences: {
...getDefaultPreferencesControllerState().preferences,
autoLockTimeLimit: DEFAULT_AUTO_LOCK_TIME_LIMIT,
showExtensionInFullSizeView: false,
showFiatInTestnets: false,
showNativeTokenAsMainBalance: true,
showTestNetworks: false,
smartTransactionsOptInStatus: true,
petnamesEnabled: true,
featureNotificationsEnabled: false,
privacyMode: false,
showMultiRpcModal: false,
} as Preferences,
tokenSortConfig: {
key: 'tokenFiatAmount',
order: 'dsc',
sortCallback: 'stringNumeric',
},
tokenNetworkFilter: {},
},
},
SignatureController: {
unapprovedPersonalMsgs: {},
Expand Down

0 comments on commit 9033a25

Please sign in to comment.