Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 3 additions & 4 deletions app/components/hooks/useThunkDispatch.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { ThunkAction as ReduxThunkAction, ThunkDispatch } from 'redux-thunk';
import { useDispatch } from 'react-redux';
import { AnyAction } from 'redux';
import { RootState } from '../../reducers';
import { RootAction, RootState } from '../../reducers';

export type ThunkAction = ReduxThunkAction<void, RootState, unknown, AnyAction>;
export type ThunkAction = ReduxThunkAction<void, RootState, unknown, RootAction>;

function useThunkDispatch() {
return useDispatch<ThunkDispatch<RootState, unknown, AnyAction>>();
return useDispatch<ThunkDispatch<RootState, unknown, RootAction>>();
}

export default useThunkDispatch;
11 changes: 4 additions & 7 deletions app/core/DeeplinkManager/DeeplinkManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

import { NavigationProp, ParamListBase } from '@react-navigation/native';
import { ParseOutput } from 'eth-url-parser';
import { AnyAction, Dispatch, Store } from 'redux';
import { Dispatch } from 'redux';
import { RootAction } from '../../reducers';
import handleBrowserUrl from './Handlers/handleBrowserUrl';
import handleEthereumUrl from './Handlers/handleEthereumUrl';
import handleRampUrl from './Handlers/handleRampUrl';
Expand All @@ -14,18 +15,14 @@ import { RampType } from '../../reducers/fiatOrders/types';
class DeeplinkManager {
public navigation: NavigationProp<ParamListBase>;
public pendingDeeplink: string | null;
// TODO: Replace "any" with type
// eslint-disable-next-line @typescript-eslint/no-explicit-any
public dispatch: Dispatch<any>;
public dispatch: Dispatch<RootAction>;

constructor({
navigation,
dispatch,
}: {
navigation: NavigationProp<ParamListBase>;
// TODO: Replace "any" with type
// eslint-disable-next-line @typescript-eslint/no-explicit-any
dispatch: Store<any, AnyAction>['dispatch'];
dispatch: Dispatch<RootAction>;
}) {
this.navigation = navigation;
this.pendingDeeplink = null;
Expand Down
7 changes: 3 additions & 4 deletions app/core/redux/types.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { AnyAction, Store } from 'redux';
import { RootState } from '../../reducers';
import { Store } from 'redux';
import { RootAction, RootState } from '../../reducers';

/**
* Redux store type
* TODO: Replace AnyAction with union type of all actions
*/
export type ReduxStore = Store<RootState, AnyAction>;
export type ReduxStore = Store<RootState, RootAction>;
27 changes: 26 additions & 1 deletion app/reducers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,15 @@ import collectiblesReducer from './collectibles';
import navigationReducer, { NavigationState } from './navigation';
import networkOnboardReducer from './networkSelector';
import securityReducer, { SecurityState } from './security';
import { combineReducers, Reducer } from 'redux';
import { Action, combineReducers, Reducer } from 'redux';
import { UserAction } from '../actions/user/types';
import { NavigationAction } from '../actions/navigation/types';
import { OnboardingActionTypes } from '../actions/onboarding';
import { Action as SecurityAction } from '../actions/security';
import { Action as SdkAction } from '../actions/sdk';
import { Action as FiatOrdersAction } from './fiatOrders/types';
import { iAccountActions } from '../actions/accounts';
import { iEventAction } from '../actions/rpcEvents';
import experimentalSettingsReducer from './experimentalSettings';
import { EngineState } from '../core/Engine';
import rpcEventReducer from './rpcEvents';
Expand Down Expand Up @@ -126,6 +134,23 @@ export interface RootState {
performance?: PerformanceState;
}

/**
* Union of all typed Redux actions in the app.
* As more action modules are migrated to TypeScript with proper types,
* add them to this union. {@link Action Action<string>} serves as a base
* for untyped JS actions and RTK slice actions.
*/
export type RootAction =
| UserAction
| NavigationAction
| OnboardingActionTypes
| SecurityAction
| SdkAction
| FiatOrdersAction
| iAccountActions
| iEventAction
| Action<string>;

const baseReducers = {
legalNotices: legalNoticesReducer,
collectibles: collectiblesReducer,
Expand Down
6 changes: 2 additions & 4 deletions app/store/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { AnyAction } from 'redux';
import { configureStore } from '@reduxjs/toolkit';
import { persistStore, persistReducer, Persistor } from 'redux-persist';
import createSagaMiddleware from 'redux-saga';
import { rootSaga } from './sagas';
import rootReducer, { RootState } from '../reducers';
import rootReducer, { RootAction, RootState } from '../reducers';
import ReadOnlyNetworkStore from '../util/test/network-store';
import { isE2E } from '../util/test/utils';
import { trace, endTrace, TraceName, TraceOperation } from '../util/trace';
Expand All @@ -16,8 +15,7 @@ import ReduxService, { ReduxStore } from '../core/redux';
import { onPersistedDataLoaded } from '../actions/user';
import { toggleBasicFunctionality } from '../actions/settings';

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