Refactor configMetaNetworks
This commit is contained in:
parent
97bfbba51f
commit
09308e3071
|
@ -1,11 +1,11 @@
|
||||||
import { CONFIG_NETWORKS, ChangeNetworkRequestedAction } from './types';
|
import * as types from './types';
|
||||||
|
|
||||||
export type TChangeNetworkRequested = typeof changeNetworkRequested;
|
export type TChangeNetworkRequested = typeof changeNetworkRequested;
|
||||||
export function changeNetworkRequested(
|
export function changeNetworkRequested(
|
||||||
payload: ChangeNetworkRequestedAction['payload']
|
payload: types.ChangeNetworkRequestedAction['payload']
|
||||||
): ChangeNetworkRequestedAction {
|
): types.ChangeNetworkRequestedAction {
|
||||||
return {
|
return {
|
||||||
type: CONFIG_NETWORKS.CHANGE_NETWORK_REQUESTED,
|
type: types.ConfigNetworksActions.CHANGE_NETWORK_REQUESTED,
|
||||||
payload
|
payload
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,14 @@
|
||||||
export * from './types';
|
import * as configNetworksTypes from './types';
|
||||||
export * from './actions';
|
import * as configNetworksActions from './actions';
|
||||||
export * from './reducer';
|
import * as configNetworksReducer from './reducer';
|
||||||
export * from './selectors';
|
import * as configNetworksSelectors from './selectors';
|
||||||
|
|
||||||
|
export {
|
||||||
|
configNetworksTypes,
|
||||||
|
configNetworksActions,
|
||||||
|
configNetworksReducer,
|
||||||
|
configNetworksSelectors
|
||||||
|
};
|
||||||
|
|
||||||
export * from './custom';
|
export * from './custom';
|
||||||
export * from './static';
|
export * from './static';
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
import { combineReducers } from 'redux';
|
import { combineReducers } from 'redux';
|
||||||
|
|
||||||
import { customNetworksReducer } from './custom/reducer';
|
import * as configNetworksCustomReducer from './custom/reducer';
|
||||||
import { staticNetworksReducer } from './static/reducer';
|
import * as configStaticCustomReducer from './static/reducer';
|
||||||
import { NetworksState } from './types';
|
import * as types from './types';
|
||||||
|
|
||||||
export const networksReducer = combineReducers<NetworksState>({
|
export const networksReducer = combineReducers<types.NetworksState>({
|
||||||
customNetworks: customNetworksReducer,
|
customNetworks: configNetworksCustomReducer.customNetworksReducer,
|
||||||
staticNetworks: staticNetworksReducer
|
staticNetworks: configStaticCustomReducer.staticNetworksReducer
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import { StaticNetworkIds } from 'types/network';
|
import { StaticNetworkIds } from 'types/network';
|
||||||
import { AppState } from 'features/reducers';
|
import { AppState } from 'features/reducers';
|
||||||
import { getCustomNetworkConfigs } from './custom/selectors';
|
import * as configMetaNetworksCustomSelectors from './custom/selectors';
|
||||||
import { isStaticNetworkId, getStaticNetworkConfigs } from './static/selectors';
|
import * as configMetaNetworksStaticSelectors from './static/selectors';
|
||||||
|
|
||||||
const getConfig = (state: AppState) => state.config;
|
const getConfig = (state: AppState) => state.config;
|
||||||
|
|
||||||
|
@ -11,14 +11,18 @@ export const getStaticNetworkIds = (state: AppState): StaticNetworkIds[] =>
|
||||||
Object.keys(getNetworks(state).staticNetworks) as StaticNetworkIds[];
|
Object.keys(getNetworks(state).staticNetworks) as StaticNetworkIds[];
|
||||||
|
|
||||||
export const getNetworkConfigById = (state: AppState, networkId: string) =>
|
export const getNetworkConfigById = (state: AppState, networkId: string) =>
|
||||||
isStaticNetworkId(state, networkId)
|
configMetaNetworksStaticSelectors.isStaticNetworkId(state, networkId)
|
||||||
? getStaticNetworkConfigs(state)[networkId]
|
? configMetaNetworksStaticSelectors.getStaticNetworkConfigs(state)[networkId]
|
||||||
: getCustomNetworkConfigs(state)[networkId];
|
: configMetaNetworksCustomSelectors.getCustomNetworkConfigs(state)[networkId];
|
||||||
|
|
||||||
export const getNetworkByChainId = (state: AppState, chainId: number | string) => {
|
export const getNetworkByChainId = (state: AppState, chainId: number | string) => {
|
||||||
const network =
|
const network =
|
||||||
Object.values(getStaticNetworkConfigs(state)).find(n => +n.chainId === +chainId) ||
|
Object.values(configMetaNetworksStaticSelectors.getStaticNetworkConfigs(state)).find(
|
||||||
Object.values(getCustomNetworkConfigs(state)).find(n => +n.chainId === +chainId);
|
n => +n.chainId === +chainId
|
||||||
|
) ||
|
||||||
|
Object.values(configMetaNetworksCustomSelectors.getCustomNetworkConfigs(state)).find(
|
||||||
|
n => +n.chainId === +chainId
|
||||||
|
);
|
||||||
if (!network) {
|
if (!network) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@ import { EXTRA_PATHS } from 'config/dpaths';
|
||||||
import { stripWeb3Network } from 'libs/nodes';
|
import { stripWeb3Network } from 'libs/nodes';
|
||||||
import { StaticNetworkIds } from 'types/network';
|
import { StaticNetworkIds } from 'types/network';
|
||||||
import { AppState } from 'features/reducers';
|
import { AppState } from 'features/reducers';
|
||||||
import { PathType } from './types';
|
import * as types from './types';
|
||||||
|
|
||||||
function getNetworks(state: AppState) {
|
function getNetworks(state: AppState) {
|
||||||
return state.config.networks;
|
return state.config.networks;
|
||||||
|
@ -21,7 +21,7 @@ export function isStaticNetworkId(
|
||||||
return Object.keys(getStaticNetworkConfigs(state)).includes(stripWeb3Network(networkId));
|
return Object.keys(getStaticNetworkConfigs(state)).includes(stripWeb3Network(networkId));
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getPaths(state: AppState, pathType: PathType): DPath[] {
|
export function getPaths(state: AppState, pathType: types.PathType): DPath[] {
|
||||||
const paths = Object.values(getStaticNetworkConfigs(state))
|
const paths = Object.values(getStaticNetworkConfigs(state))
|
||||||
.reduce((networkPaths: DPath[], { dPathFormats }): DPath[] => {
|
.reduce((networkPaths: DPath[], { dPathFormats }): DPath[] => {
|
||||||
if (dPathFormats && dPathFormats[pathType]) {
|
if (dPathFormats && dPathFormats[pathType]) {
|
||||||
|
|
|
@ -1,16 +1,16 @@
|
||||||
import { CustomNetworksState } from './custom/types';
|
import * as configNetworksCustomTypes from './custom/types';
|
||||||
import { StaticNetworksState } from './static/types';
|
import * as configNetworksStaticTypes from './static/types';
|
||||||
|
|
||||||
export enum CONFIG_NETWORKS {
|
export enum ConfigNetworksActions {
|
||||||
CHANGE_NETWORK_REQUESTED = 'CONFIG_NETWORK_CHANGE_NETWORK_REQUESTED'
|
CHANGE_NETWORK_REQUESTED = 'CONFIG_NETWORK_CHANGE_NETWORK_REQUESTED'
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface NetworksState {
|
export interface NetworksState {
|
||||||
customNetworks: CustomNetworksState;
|
customNetworks: configNetworksCustomTypes.CustomNetworksState;
|
||||||
staticNetworks: StaticNetworksState;
|
staticNetworks: configNetworksStaticTypes.StaticNetworksState;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ChangeNetworkRequestedAction {
|
export interface ChangeNetworkRequestedAction {
|
||||||
type: CONFIG_NETWORKS.CHANGE_NETWORK_REQUESTED;
|
type: ConfigNetworksActions.CHANGE_NETWORK_REQUESTED;
|
||||||
payload: string;
|
payload: string;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue