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 2, 2024
1 parent 172c601 commit 61588b4
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 @@ -366,7 +365,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 @@ -108,8 +111,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 61588b4

Please sign in to comment.