Skip to content

Commit

Permalink
Define type ReduxState
Browse files Browse the repository at this point in the history
  • Loading branch information
MajorLift committed Dec 3, 2024
1 parent 82a9bf7 commit fa4ea81
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
5 changes: 2 additions & 3 deletions app/core/Engine/Engine.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@ import { zeroAddress } from 'ethereumjs-util';
import { createMockAccountsControllerState } from '../../util/test/accountsControllerTestUtils';
import { mockNetworkState } from '../../util/test/network';
import MetaMetrics from '../Analytics/MetaMetrics';
import { store } from '../../store';
import { ReduxState, store } from '../../store';
import { MetaMetricsEvents } from '../Analytics';
import { NetworkState } from '@metamask/network-controller';
import { Hex } from '@metamask/utils';
import { MarketDataDetails } from '../../components/UI/Tokens';
import { TransactionMeta } from '@metamask/transaction-controller';
import { RootState } from '../../reducers';
import { MetricsEventBuilder } from '../Analytics/MetricsEventBuilder';

jest.unmock('./Engine');
Expand Down Expand Up @@ -369,7 +368,7 @@ describe('Transaction event handlers', () => {
beforeEach(() => {
engine = Engine.init({});
jest.spyOn(MetaMetrics.getInstance(), 'trackEvent').mockImplementation();
jest.spyOn(store, 'getState').mockReturnValue({} as RootState);
jest.spyOn(store, 'getState').mockReturnValue({} as ReduxState);
});

afterEach(() => {
Expand Down
9 changes: 7 additions & 2 deletions app/store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ import getUIStartupSpan from '../core/Performance/UIStartup';
import { ToolkitStore } from '@reduxjs/toolkit/dist/configureStore';

// TODO: Improve type safety by using real Action types instead of `any`
const pReducer = persistReducer<RootState, AnyAction>(persistConfig, rootReducer);
const pReducer = persistReducer<RootState, AnyAction>(
persistConfig,
rootReducer,
);

// TODO: Fix the Action type. It's set to `any` now because some of the
// TypeScript reducers have invalid actions
Expand Down Expand Up @@ -103,8 +106,10 @@ const createStoreAndPersistor = async () => {

export { store, persistor };

export type ReduxState = ReturnType<typeof pReducer>;

export type ReduxStore = ToolkitStore<
ReturnType<typeof pReducer>,
ReduxState,
AnyAction,
[ReturnType<typeof createSagaMiddleware<typeof rootSaga>>, typeof thunk]
>;

0 comments on commit fa4ea81

Please sign in to comment.