From efe55e108e461216231b44e9164215d85756767f Mon Sep 17 00:00:00 2001 From: Will O'Beirne Date: Wed, 7 Mar 2018 18:45:16 -0500 Subject: [PATCH] Wrangle types due to webpack weirdness. --- .../config/networks/customNetworks.ts | 7 +------ common/reducers/config/networks/index.ts | 5 +++-- .../config/networks/staticNetworks.ts | 5 ++--- common/reducers/config/networks/types.ts | 10 +++++++++ common/reducers/config/nodes/customNodes.ts | 6 +----- common/reducers/config/nodes/index.ts | 7 ++++--- common/reducers/config/nodes/selectedNode.ts | 15 ++----------- common/reducers/config/nodes/staticNodes.ts | 4 +--- common/reducers/config/nodes/types.ts | 21 +++++++++++++++++++ 9 files changed, 45 insertions(+), 35 deletions(-) create mode 100644 common/reducers/config/networks/types.ts create mode 100644 common/reducers/config/nodes/types.ts diff --git a/common/reducers/config/networks/customNetworks.ts b/common/reducers/config/networks/customNetworks.ts index fb49972c..55bedf31 100644 --- a/common/reducers/config/networks/customNetworks.ts +++ b/common/reducers/config/networks/customNetworks.ts @@ -4,12 +4,7 @@ import { CustomNetworkAction, TypeKeys } from 'actions/config'; -import { CustomNetworkConfig } from 'types/network'; - -// TODO: this doesn't accurately represent state, as -export interface State { - [customNetworkId: string]: CustomNetworkConfig; -} +import { CustomNetworksState as State } from './types'; const addCustomNetwork = (state: State, { payload }: AddCustomNetworkAction): State => ({ ...state, diff --git a/common/reducers/config/networks/index.ts b/common/reducers/config/networks/index.ts index 9c0a2760..d5d601a5 100644 --- a/common/reducers/config/networks/index.ts +++ b/common/reducers/config/networks/index.ts @@ -1,6 +1,7 @@ -import { customNetworks, State as CustomNetworksState } from './customNetworks'; -import { staticNetworks, State as StaticNetworksState } from './staticNetworks'; import { combineReducers } from 'redux'; +import { customNetworks } from './customNetworks'; +import { staticNetworks } from './staticNetworks'; +import { StaticNetworksState, CustomNetworksState } from './types'; interface State { customNetworks: CustomNetworksState; diff --git a/common/reducers/config/networks/staticNetworks.ts b/common/reducers/config/networks/staticNetworks.ts index 7843c327..f047ee24 100644 --- a/common/reducers/config/networks/staticNetworks.ts +++ b/common/reducers/config/networks/staticNetworks.ts @@ -16,9 +16,8 @@ import { UBQ_DEFAULT } from 'config/dpaths'; import { ConfigAction } from 'actions/config'; -import { StaticNetworkIds, StaticNetworkConfig, BlockExplorerConfig } from 'types/network'; - -export type State = { [key in StaticNetworkIds]: StaticNetworkConfig }; +import { BlockExplorerConfig } from 'types/network'; +import { StaticNetworksState as State } from './types'; // Must be a website that follows the ethplorer convention of /tx/[hash] and // address/[address] to generate the correct functions. diff --git a/common/reducers/config/networks/types.ts b/common/reducers/config/networks/types.ts new file mode 100644 index 00000000..801485f1 --- /dev/null +++ b/common/reducers/config/networks/types.ts @@ -0,0 +1,10 @@ +// Moving state types into their own file resolves an annoying webpack bug +// https://github.com/angular/angular-cli/issues/2034 +import { StaticNetworkIds, StaticNetworkConfig, CustomNetworkConfig } from 'types/network'; + +export type StaticNetworksState = { [key in StaticNetworkIds]: StaticNetworkConfig }; + +// TODO: this doesn't accurately represent custom networks state +export interface CustomNetworksState { + [customNetworkId: string]: CustomNetworkConfig; +} diff --git a/common/reducers/config/nodes/customNodes.ts b/common/reducers/config/nodes/customNodes.ts index f424af1b..12a1e176 100644 --- a/common/reducers/config/nodes/customNodes.ts +++ b/common/reducers/config/nodes/customNodes.ts @@ -4,11 +4,7 @@ import { AddCustomNodeAction, RemoveCustomNodeAction } from 'actions/config'; -import { CustomNodeConfig } from 'types/node'; - -export interface State { - [customNodeId: string]: CustomNodeConfig; -} +import { CustomNodesState as State } from './types'; const addCustomNode = (state: State, { payload }: AddCustomNodeAction): State => ({ ...state, diff --git a/common/reducers/config/nodes/index.ts b/common/reducers/config/nodes/index.ts index 07fdebea..2c5ab672 100644 --- a/common/reducers/config/nodes/index.ts +++ b/common/reducers/config/nodes/index.ts @@ -1,7 +1,8 @@ -import { customNodes, State as CustomNodesState } from './customNodes'; -import { staticNodes, State as StaticNodesState } from './staticNodes'; -import { selectedNode, State as SelectedNodeState } from './selectedNode'; import { combineReducers } from 'redux'; +import { customNodes } from './customNodes'; +import { staticNodes } from './staticNodes'; +import { selectedNode } from './selectedNode'; +import { CustomNodesState, StaticNodesState, SelectedNodeState } from './types'; interface State { customNodes: CustomNodesState; diff --git a/common/reducers/config/nodes/selectedNode.ts b/common/reducers/config/nodes/selectedNode.ts index 6d69e6e7..9b468c19 100644 --- a/common/reducers/config/nodes/selectedNode.ts +++ b/common/reducers/config/nodes/selectedNode.ts @@ -6,20 +6,9 @@ import { RemoveCustomNodeAction, CustomNodeAction } from 'actions/config'; +import { SelectedNodeState as State } from './types'; -interface NodeLoaded { - pending: false; - nodeId: string; -} - -interface NodeChangePending { - pending: true; - nodeId: string; -} - -export type State = NodeLoaded | NodeChangePending; - -export const INITIAL_STATE: NodeLoaded = { +export const INITIAL_STATE: State = { nodeId: 'eth_mycrypto', pending: false }; diff --git a/common/reducers/config/nodes/staticNodes.ts b/common/reducers/config/nodes/staticNodes.ts index 3787a8f4..63bb6cac 100644 --- a/common/reducers/config/nodes/staticNodes.ts +++ b/common/reducers/config/nodes/staticNodes.ts @@ -1,8 +1,6 @@ import { EtherscanNode, InfuraNode, RPCNode } from 'libs/nodes'; import { TypeKeys, NodeAction } from 'actions/config'; -import { NonWeb3NodeConfigs, Web3NodeConfigs } from 'types/node'; - -export type State = NonWeb3NodeConfigs & Web3NodeConfigs; +import { StaticNodesState as State } from './types'; export const INITIAL_STATE: State = { eth_mycrypto: { diff --git a/common/reducers/config/nodes/types.ts b/common/reducers/config/nodes/types.ts new file mode 100644 index 00000000..fa2afa71 --- /dev/null +++ b/common/reducers/config/nodes/types.ts @@ -0,0 +1,21 @@ +// Moving state types into their own file resolves an annoying webpack bug +// https://github.com/angular/angular-cli/issues/2034 +import { NonWeb3NodeConfigs, Web3NodeConfigs, CustomNodeConfig } from 'types/node'; + +export interface CustomNodesState { + [customNodeId: string]: CustomNodeConfig; +} + +interface NodeLoaded { + pending: false; + nodeId: string; +} + +interface NodeChangePending { + pending: true; + nodeId: string; +} + +export type SelectedNodeState = NodeLoaded | NodeChangePending; + +export type StaticNodesState = NonWeb3NodeConfigs & Web3NodeConfigs;