Refactor configNodes
This commit is contained in:
parent
b6b5fe801f
commit
05f8e5a53b
|
@ -1,26 +1,26 @@
|
|||
import * as types from './types';
|
||||
|
||||
const addCustomNode = (
|
||||
state: types.CustomNodesState,
|
||||
state: types.ConfigCustomNodesState,
|
||||
{ payload }: types.AddCustomNodeAction
|
||||
): types.CustomNodesState => ({
|
||||
): types.ConfigCustomNodesState => ({
|
||||
...state,
|
||||
[payload.id]: payload
|
||||
});
|
||||
|
||||
function removeCustomNode(
|
||||
state: types.CustomNodesState,
|
||||
state: types.ConfigCustomNodesState,
|
||||
{ payload }: types.RemoveCustomNodeAction
|
||||
): types.CustomNodesState {
|
||||
): types.ConfigCustomNodesState {
|
||||
const stateCopy = { ...state };
|
||||
Reflect.deleteProperty(stateCopy, payload);
|
||||
return stateCopy;
|
||||
}
|
||||
|
||||
export function customNodesReducer(
|
||||
state: types.CustomNodesState = {},
|
||||
state: types.ConfigCustomNodesState = {},
|
||||
action: types.CustomNodeAction
|
||||
): types.CustomNodesState {
|
||||
): types.ConfigCustomNodesState {
|
||||
switch (action.type) {
|
||||
case types.ConfigNodesCustomActions.ADD:
|
||||
return addCustomNode(state, action);
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { CustomNodeConfig } from 'types/node';
|
||||
|
||||
export interface CustomNodesState {
|
||||
export interface ConfigCustomNodesState {
|
||||
[customNodeId: string]: CustomNodeConfig;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
export * from './types';
|
||||
export * from './reducer';
|
||||
export * from './selectors';
|
||||
import * as configNodesTypes from './types';
|
||||
import * as configNodesReducer from './reducer';
|
||||
import * as configNodesSelectors from './selectors';
|
||||
|
||||
export { configNodesTypes, configNodesReducer, configNodesSelectors };
|
||||
|
||||
export * from './custom';
|
||||
export * from './selected';
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
import { combineReducers } from 'redux';
|
||||
|
||||
import { customNodesReducer } from './custom/reducer';
|
||||
import { staticNodesReducer } from './static/reducer';
|
||||
import { selectedNodeReducer } from './selected/reducer';
|
||||
import { NodesState } from './types';
|
||||
import * as configNodesCustomReducer from './custom/reducer';
|
||||
import * as configNodesStaticReducer from './static/reducer';
|
||||
import * as configNodesSelectedReducer from './selected/reducer';
|
||||
import * as types from './types';
|
||||
|
||||
export const nodesReducer = combineReducers<NodesState>({
|
||||
customNodes: customNodesReducer,
|
||||
staticNodes: staticNodesReducer,
|
||||
selectedNode: selectedNodeReducer
|
||||
export const nodesReducer = combineReducers<types.ConfigNodesState>({
|
||||
customNodes: configNodesCustomReducer.customNodesReducer,
|
||||
staticNodes: configNodesStaticReducer.staticNodesReducer,
|
||||
selectedNode: configNodesSelectedReducer.selectedNodeReducer
|
||||
});
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
import { shepherdProvider, INode } from 'libs/nodes';
|
||||
import { CustomNodeConfig, StaticNodeConfig } from 'types/node';
|
||||
import { AppState } from 'features/reducers';
|
||||
import { getCustomNodeConfig } from './custom/selectors';
|
||||
import { getNodeId } from './selected/selectors';
|
||||
import { getStaticNodeConfig } from './static/selectors';
|
||||
import * as configNodesCustomSelectors from './custom/selectors';
|
||||
import * as configNodesSelectedSelectors from './selected/selectors';
|
||||
import * as configNodesStaticSelectors from './static/selectors';
|
||||
|
||||
function getConfig(state: AppState) {
|
||||
return state.config;
|
||||
|
@ -15,8 +15,8 @@ export function getNodes(state: AppState) {
|
|||
|
||||
export const getWeb3Node = (state: AppState): StaticNodeConfig | null => {
|
||||
const isWeb3Node = (nodeId: string) => nodeId === 'web3';
|
||||
const currNode = getStaticNodeConfig(state);
|
||||
const currNodeId = getNodeId(state);
|
||||
const currNode = configNodesStaticSelectors.getStaticNodeConfig(state);
|
||||
const currNodeId = configNodesSelectedSelectors.getNodeId(state);
|
||||
if (currNode && currNodeId && isWeb3Node(currNodeId)) {
|
||||
return currNode;
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ export const getWeb3Node = (state: AppState): StaticNodeConfig | null => {
|
|||
};
|
||||
|
||||
export function getIsWeb3Node(state: AppState): boolean {
|
||||
return getNodeId(state) === 'web3';
|
||||
return configNodesSelectedSelectors.getNodeId(state) === 'web3';
|
||||
}
|
||||
|
||||
export function getNodeLib(_: AppState): INode {
|
||||
|
@ -32,7 +32,9 @@ export function getNodeLib(_: AppState): INode {
|
|||
}
|
||||
|
||||
export function getNodeConfig(state: AppState): StaticNodeConfig | CustomNodeConfig {
|
||||
const config = getStaticNodeConfig(state) || getCustomNodeConfig(state);
|
||||
const config =
|
||||
configNodesStaticSelectors.getStaticNodeConfig(state) ||
|
||||
configNodesCustomSelectors.getCustomNodeConfig(state);
|
||||
|
||||
if (!config) {
|
||||
const { selectedNode } = getNodes(state);
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
import { CustomNodesState } from './custom/types';
|
||||
import { StaticNodesState } from './static/types';
|
||||
import { SelectedNodeState } from './selected/types';
|
||||
import * as configNodesCustomTypes from './custom/types';
|
||||
import * as configNodesStaticTypes from './static/types';
|
||||
import * as configNodesSelectedTypes from './selected/types';
|
||||
|
||||
export interface NodesState {
|
||||
customNodes: CustomNodesState;
|
||||
staticNodes: StaticNodesState;
|
||||
selectedNode: SelectedNodeState;
|
||||
export interface ConfigNodesState {
|
||||
customNodes: configNodesCustomTypes.ConfigCustomNodesState;
|
||||
staticNodes: configNodesStaticTypes.ConfigStaticNodesState;
|
||||
selectedNode: configNodesSelectedTypes.ConfigNodesSelectedState;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue