Skip to content

Commit

Permalink
Remove types TemporaryBackgroundState, TemporaryMessageDataType a…
Browse files Browse the repository at this point in the history
…nd merge into `initialMetamaskState` for inference of `metamask` slice type
  • Loading branch information
MajorLift committed Nov 27, 2024
1 parent 01d3814 commit e7cc0eb
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 96 deletions.
30 changes: 27 additions & 3 deletions ui/ducks/metamask/constants.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Preferences } 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 { Preferences } from '../../../app/scripts/controllers/preferences-controller';
import { MemStoreControllersComposedState } from '../../../app/scripts/metamask-controller-stores';
import { DEFAULT_AUTO_LOCK_TIME_LIMIT } from '../../../shared/constants/preferences';

export const initialMetamaskState: Partial<{
[ControllerName in keyof MemStoreControllersComposedState]: Partial<
Expand All @@ -9,6 +9,7 @@ export const initialMetamaskState: Partial<{
}> = {
KeyringController: {
isUnlocked: false,
keyrings: [],
},
AccountsController: {
internalAccounts: { accounts: {}, selectedAccount: '' },
Expand All @@ -20,6 +21,10 @@ export const initialMetamaskState: Partial<{
AddressBookController: {
addressBook: {},
},
ApprovalController: {
pendingApprovals: {},
approvalFlows: [],
},
CurrencyController: {
currencyRates: {
ETH: {
Expand All @@ -29,12 +34,26 @@ export const initialMetamaskState: Partial<{
},
},
},
///: BEGIN:ONLY_INCLUDE_IF(build-mmi)
CustodyController: {
custodyAccountDetails: {},
},
///: END:ONLY_INCLUDE_IF
DecryptMessageController: {
unapprovedDecryptMsgs: {},
},
GasFeeController: {
gasFeeEstimates: {},
gasEstimateType: 'none',
},
MetaMetricsController: {
participateInMetaMetrics: null,
dataCollectionForMarketing: null,
},
NetworkController: {
selectedNetworkClientId: '',
networkConfigurationsByChainId: {},
networksMetadata: {},
},
OnboardingController: {
firstTimeFlowType: null,
Expand All @@ -46,6 +65,7 @@ export const initialMetamaskState: Partial<{
featureFlags: {},
currentLocale: '',
knownMethodData: {},
ledgerTransportType: undefined,
preferences: {
autoLockTimeLimit: DEFAULT_AUTO_LOCK_TIME_LIMIT,
showExtensionInFullSizeView: false,
Expand All @@ -58,6 +78,10 @@ export const initialMetamaskState: Partial<{
showMultiRpcModal: false,
} as Preferences,
},
SignatureController: {
unapprovedPersonalMsgs: {},
unapprovedTypedMessages: {},
},
TokensController: {
allTokens: {},
},
Expand Down
94 changes: 1 addition & 93 deletions ui/store/store.ts
Original file line number Diff line number Diff line change
@@ -1,107 +1,15 @@
import { StoreEnhancer } from 'redux';
import { configureStore as baseConfigureStore } from '@reduxjs/toolkit';
import devtoolsEnhancer from 'remote-redux-devtools';
import { ApprovalControllerState } from '@metamask/approval-controller';
import { GasEstimateType, GasFeeEstimates } from '@metamask/gas-fee-controller';
import { TransactionMeta } from '@metamask/transaction-controller';
import { InternalAccount } from '@metamask/keyring-api';
import {
NftControllerState,
TokensControllerState,
} from '@metamask/assets-controllers';
import { NotificationServicesControllerState } from '@metamask/notification-services-controller/notification-services';
import rootReducer from '../ducks';
import { LedgerTransportTypes } from '../../shared/constants/hardware-wallets';
import type { NetworkStatus } from '../../shared/constants/network';

/**
* This interface is temporary and is copied from the message-manager.js file
* and is the 'msgParams' key of the interface declared there. We should get a
* universal Message type to use for this, the Message manager and all
* the other types of messages.
*
* TODO: Replace this
*/
export type TemporaryMessageDataType = {
id: string;
type: string;
msgParams: {
metamaskId: string;
data: string;
};
///: BEGIN:ONLY_INCLUDE_IF(build-mmi)
metadata?: {
custodyId?: string;
};
status?: string;
///: END:ONLY_INCLUDE_IF
};

export type MessagesIndexedById = {
[id: string]: TemporaryMessageDataType;
};

/**
* This interface is a temporary interface to describe the state tree that is
* sent from the background. Ideally we can build this using Types in the
* backend when we compose the stores, then we can import it here and use it.
*
* Some of this is duplicated in the metamask redux duck. In *most* cases the
* state received from the background takes precedence over anything in the
* metamask reducer.
*/
type TemporaryBackgroundState = NftControllerState &
NotificationServicesControllerState &
TokensControllerState & {
addressBook: {
[chainId: string]: {
name: string;
}[];
};
// todo: can this be deleted post network controller v20
providerConfig: {
chainId: string;
};
transactions: TransactionMeta[];
ledgerTransportType: LedgerTransportTypes;
unapprovedDecryptMsgs: MessagesIndexedById;
unapprovedPersonalMsgs: MessagesIndexedById;
unapprovedTypedMessages: MessagesIndexedById;
networksMetadata: {
[NetworkClientId: string]: {
EIPS: { [eip: string]: boolean };
status: NetworkStatus;
};
};
selectedNetworkClientId: string;
pendingApprovals: ApprovalControllerState['pendingApprovals'];
approvalFlows: ApprovalControllerState['approvalFlows'];
knownMethodData?: {
[fourBytePrefix: string]: Record<string, unknown>;
};
gasFeeEstimates: GasFeeEstimates;
gasEstimateType: GasEstimateType;
///: BEGIN:ONLY_INCLUDE_IF(build-mmi)
// TODO: Replace `any` with type
// eslint-disable-next-line @typescript-eslint/no-explicit-any
custodyAccountDetails?: { [key: string]: any };
///: END:ONLY_INCLUDE_IF
internalAccounts: {
accounts: {
[key: string]: InternalAccount;
};
selectedAccount: string;
};
keyrings: { type: string; accounts: string[] }[];
};

type RootReducerReturnType = ReturnType<typeof rootReducer>;

export type CombinedBackgroundAndReduxState = RootReducerReturnType & {
activeTab: {
origin: string;
};
metamask: RootReducerReturnType['metamask'] & TemporaryBackgroundState;
metamask: RootReducerReturnType['metamask'];
appState: RootReducerReturnType['appState'];
send: RootReducerReturnType['send'];
DNS: RootReducerReturnType['DNS'];
Expand Down

0 comments on commit e7cc0eb

Please sign in to comment.