diff --git a/common/components/Header/index.tsx b/common/components/Header/index.tsx index 43addd31..c99e1605 100644 --- a/common/components/Header/index.tsx +++ b/common/components/Header/index.tsx @@ -195,7 +195,7 @@ class Header extends Component { } disabled={nodeSelection === 'web3'} - onChange={changeNodeIntent} + onChange={this.props.changeNodeIntent} size="smr" color="white" menuAlign="right" diff --git a/common/components/WalletDecrypt/WalletDecrypt.tsx b/common/components/WalletDecrypt/WalletDecrypt.tsx index 81de503b..82299524 100644 --- a/common/components/WalletDecrypt/WalletDecrypt.tsx +++ b/common/components/WalletDecrypt/WalletDecrypt.tsx @@ -47,9 +47,9 @@ import { WalletName, knowledgeBaseURL } from 'config'; -import { unSupportedWalletFormatsOnNetwork } from 'utils/network'; -import { getNetworkConfig, getOffline } from '../../selectors/config'; +import { getOffline } from '../../selectors/config'; import { isWeb3NodeAvailable } from 'libs/nodes/web3'; +import { unSupportedWalletFormatsOnNetwork } from 'selectors/config/wallet'; interface OwnProps { hidden?: boolean; @@ -436,8 +436,7 @@ export class WalletDecrypt extends Component { function mapStateToProps(state: AppState, ownProps: Props) { const { disabledWallets } = ownProps; - const network = getNetworkConfig(state); - const networkDisabledFormats = unSupportedWalletFormatsOnNetwork(network); + const networkDisabledFormats = unSupportedWalletFormatsOnNetwork(state); const computedDisabledWallets = disabledWallets ? disabledWallets.concat(networkDisabledFormats) : networkDisabledFormats; diff --git a/common/components/WalletDecrypt/components/LedgerNano.tsx b/common/components/WalletDecrypt/components/LedgerNano.tsx index 95a19396..1cbcaa3d 100644 --- a/common/components/WalletDecrypt/components/LedgerNano.tsx +++ b/common/components/WalletDecrypt/components/LedgerNano.tsx @@ -7,9 +7,8 @@ import ledger from 'ledgerco'; import { Spinner } from 'components/ui'; import { connect } from 'react-redux'; import { AppState } from 'reducers'; -import { getNetworkConfig } from 'selectors/config'; import { SecureWalletName } from 'config'; -import { getPaths, getSingleDPath } from 'utils/network'; +import { getPaths, getSingleDPath } from 'selectors/config/wallet'; interface OwnProps { onUnlock(param: any): void; @@ -17,6 +16,7 @@ interface OwnProps { interface StateProps { dPath: DPath; + dPaths: DPath[]; } interface State { @@ -122,7 +122,7 @@ class LedgerNanoSDecryptClass extends Component { publicKey={publicKey} chainCode={chainCode} dPath={dPath} - dPaths={getPaths(SecureWalletName.LEDGER_NANO_S)} + dPaths={this.props.dPaths} onCancel={this.handleCancel} onConfirmAddress={this.handleUnlock} onPathChange={this.handlePathChange} @@ -188,9 +188,9 @@ class LedgerNanoSDecryptClass extends Component { } function mapStateToProps(state: AppState): StateProps { - const network = getNetworkConfig(state); return { - dPath: getSingleDPath(SecureWalletName.LEDGER_NANO_S, network) + dPath: getSingleDPath(state, SecureWalletName.LEDGER_NANO_S), + dPaths: getPaths(state, SecureWalletName.LEDGER_NANO_S) }; } diff --git a/common/components/WalletDecrypt/components/Mnemonic.tsx b/common/components/WalletDecrypt/components/Mnemonic.tsx index fc658481..a4e17614 100644 --- a/common/components/WalletDecrypt/components/Mnemonic.tsx +++ b/common/components/WalletDecrypt/components/Mnemonic.tsx @@ -5,9 +5,8 @@ import DeterministicWalletsModal from './DeterministicWalletsModal'; import { formatMnemonic } from 'utils/formatters'; import { InsecureWalletName } from 'config'; import { AppState } from 'reducers'; -import { getNetworkConfig } from 'selectors/config'; import { connect } from 'react-redux'; -import { getPaths, getSingleDPath } from 'utils/network'; +import { getSingleDPath, getPaths } from 'selectors/config/wallet'; interface Props { onUnlock(param: any): void; @@ -15,6 +14,7 @@ interface Props { interface StateProps { dPath: DPath; + dPaths: DPath[]; } interface State { @@ -77,7 +77,7 @@ class MnemonicDecryptClass extends Component { isOpen={!!seed} seed={seed} dPath={dPath} - dPaths={getPaths(InsecureWalletName.MNEMONIC_PHRASE)} + dPaths={this.props.dPaths} onCancel={this.handleCancel} onConfirmAddress={this.handleUnlock} onPathChange={this.handlePathChange} @@ -144,9 +144,9 @@ class MnemonicDecryptClass extends Component { } function mapStateToProps(state: AppState): StateProps { - const network = getNetworkConfig(state); return { - dPath: getSingleDPath(InsecureWalletName.MNEMONIC_PHRASE, network) + dPath: getSingleDPath(state, InsecureWalletName.MNEMONIC_PHRASE), + dPaths: getPaths(state, InsecureWalletName.MNEMONIC_PHRASE) }; } diff --git a/common/components/WalletDecrypt/components/Trezor.tsx b/common/components/WalletDecrypt/components/Trezor.tsx index 371fc700..aeaf51eb 100644 --- a/common/components/WalletDecrypt/components/Trezor.tsx +++ b/common/components/WalletDecrypt/components/Trezor.tsx @@ -5,11 +5,10 @@ import TrezorConnect from 'vendor/trezor-connect'; import DeterministicWalletsModal from './DeterministicWalletsModal'; import './Trezor.scss'; import { Spinner } from 'components/ui'; -import { getNetworkConfig } from 'selectors/config'; import { AppState } from 'reducers'; import { connect } from 'react-redux'; import { SecureWalletName } from 'config'; -import { getPaths, getSingleDPath } from 'utils/network'; +import { getSingleDPath, getPaths } from 'selectors/config/wallet'; //todo: conflicts with comment in walletDecrypt -> onUnlock method interface OwnProps { @@ -18,6 +17,7 @@ interface OwnProps { interface StateProps { dPath: DPath; + dPaths: DPath[]; } // todo: nearly duplicates ledger component props @@ -88,7 +88,7 @@ class TrezorDecryptClass extends Component { publicKey={publicKey} chainCode={chainCode} dPath={dPath} - dPaths={getPaths(SecureWalletName.TREZOR)} + dPaths={this.props.dPaths} onCancel={this.handleCancel} onConfirmAddress={this.handleUnlock} onPathChange={this.handlePathChange} @@ -151,9 +151,9 @@ class TrezorDecryptClass extends Component { } function mapStateToProps(state: AppState): StateProps { - const network = getNetworkConfig(state); return { - dPath: getSingleDPath(SecureWalletName.TREZOR, network) + dPath: getSingleDPath(state, SecureWalletName.TREZOR), + dPaths: getPaths(state, SecureWalletName.TREZOR) }; } diff --git a/common/containers/Tabs/SendTransaction/index.tsx b/common/containers/Tabs/SendTransaction/index.tsx index a32b8afc..3c3568a0 100644 --- a/common/containers/Tabs/SendTransaction/index.tsx +++ b/common/containers/Tabs/SendTransaction/index.tsx @@ -14,10 +14,8 @@ import { UnavailableWallets } from 'containers/Tabs/SendTransaction/components'; import SubTabs, { Tab } from 'components/SubTabs'; -import { getNetworkConfig } from 'selectors/config'; -import { isNetworkUnit } from 'utils/network'; import { RouteNotFound } from 'components/RouteNotFound'; -import { NetworkConfig } from 'types/network'; +import { isNetworkUnit } from 'selectors/config/wallet'; const Send = () => ( @@ -28,7 +26,7 @@ const Send = () => ( interface StateProps { wallet: AppState['wallet']['inst']; - network: NetworkConfig; + requestDisabled: boolean; } type Props = StateProps & RouteComponentProps<{}>; @@ -46,7 +44,7 @@ class SendTransaction extends React.Component { { path: 'request', name: translate('Request Payment'), - disabled: !isNetworkUnit(this.props.network, 'ETH') + disabled: this.props.requestDisabled }, { path: 'info', @@ -100,5 +98,5 @@ class SendTransaction extends React.Component { export default connect((state: AppState) => ({ wallet: getWalletInst(state), - network: getNetworkConfig(state) + requestDisabled: !isNetworkUnit(state, 'ETH') }))(SendTransaction); diff --git a/common/reducers/config/networks/selectedNetwork.ts b/common/reducers/config/networks/selectedNetwork.ts index 7240c189..87c8e0b5 100644 --- a/common/reducers/config/networks/selectedNetwork.ts +++ b/common/reducers/config/networks/selectedNetwork.ts @@ -8,6 +8,7 @@ const initalNode = INITIAL_DEFAULT_NODE_STATE[INITIAL_NODE_STATE.nodeId as keyof NonWeb3NodeConfigs]; export type State = string | StaticNetworkIds; + const INITIAL_STATE: State = initalNode.network; const handleNodeChange = (_: State, { payload }: ChangeNodeAction) => payload.networkId; @@ -17,6 +18,6 @@ export const selectedNetwork = (state: State = INITIAL_STATE, action: NodeAction case TypeKeys.CONFIG_NODE_CHANGE: return handleNodeChange(state, action); default: - break; + return state; } }; diff --git a/common/reducers/config/networks/staticNetworks.ts b/common/reducers/config/networks/staticNetworks.ts index c3a63064..48e12154 100644 --- a/common/reducers/config/networks/staticNetworks.ts +++ b/common/reducers/config/networks/staticNetworks.ts @@ -37,8 +37,8 @@ const INITIAL_STATE: State = { name: ethPlorer, address: ETHTokenExplorer }, - tokens: require('./tokens/eth.json'), - contracts: require('./contracts/eth.json'), + tokens: require('config/tokens/eth.json'), + contracts: require('config/contracts/eth.json'), dPathFormats: { [SecureWalletName.TREZOR]: ETH_TREZOR, [SecureWalletName.LEDGER_NANO_S]: ETH_LEDGER, @@ -52,8 +52,8 @@ const INITIAL_STATE: State = { isCustom: false, color: '#adc101', blockExplorer: makeExplorer('https://ropsten.etherscan.io'), - tokens: require('./tokens/ropsten.json'), - contracts: require('./contracts/ropsten.json'), + tokens: require('config/tokens/ropsten.json'), + contracts: require('config/contracts/ropsten.json'), isTestnet: true, dPathFormats: { [SecureWalletName.TREZOR]: ETH_TESTNET, @@ -68,8 +68,8 @@ const INITIAL_STATE: State = { isCustom: false, color: '#adc101', blockExplorer: makeExplorer('https://kovan.etherscan.io'), - tokens: require('./tokens/ropsten.json'), - contracts: require('./contracts/ropsten.json'), + tokens: require('config/tokens/ropsten.json'), + contracts: require('config/contracts/ropsten.json'), isTestnet: true, dPathFormats: { [SecureWalletName.TREZOR]: ETH_TESTNET, @@ -84,8 +84,8 @@ const INITIAL_STATE: State = { isCustom: false, color: '#adc101', blockExplorer: makeExplorer('https://rinkeby.etherscan.io'), - tokens: require('./tokens/rinkeby.json'), - contracts: require('./contracts/rinkeby.json'), + tokens: require('config/tokens/rinkeby.json'), + contracts: require('config/contracts/rinkeby.json'), isTestnet: true, dPathFormats: { [SecureWalletName.TREZOR]: ETH_TESTNET, @@ -100,8 +100,8 @@ const INITIAL_STATE: State = { isCustom: false, color: '#669073', blockExplorer: makeExplorer('https://gastracker.io'), - tokens: require('./tokens/etc.json'), - contracts: require('./contracts/etc.json'), + tokens: require('config/tokens/etc.json'), + contracts: require('config/contracts/etc.json'), dPathFormats: { [SecureWalletName.TREZOR]: ETC_TREZOR, [SecureWalletName.LEDGER_NANO_S]: ETC_LEDGER, @@ -115,8 +115,8 @@ const INITIAL_STATE: State = { isCustom: false, color: '#b37aff', blockExplorer: makeExplorer('https://ubiqscan.io/en'), - tokens: require('./tokens/ubq.json'), - contracts: require('./contracts/ubq.json'), + tokens: require('config/tokens/ubq.json'), + contracts: require('config/contracts/ubq.json'), dPathFormats: { [SecureWalletName.TREZOR]: UBQ_DEFAULT, [SecureWalletName.LEDGER_NANO_S]: UBQ_DEFAULT, @@ -130,8 +130,8 @@ const INITIAL_STATE: State = { isCustom: false, color: '#673ab7', blockExplorer: makeExplorer('http://www.gander.tech'), - tokens: require('./tokens/exp.json'), - contracts: require('./contracts/exp.json'), + tokens: require('config/tokens/exp.json'), + contracts: require('config/contracts/exp.json'), dPathFormats: { [SecureWalletName.TREZOR]: EXP_DEFAULT, [SecureWalletName.LEDGER_NANO_S]: EXP_DEFAULT, diff --git a/common/reducers/config/nodes/selectedNode.ts b/common/reducers/config/nodes/selectedNode.ts index 3d69fd3a..feb5aff0 100644 --- a/common/reducers/config/nodes/selectedNode.ts +++ b/common/reducers/config/nodes/selectedNode.ts @@ -18,7 +18,7 @@ export const INITIAL_STATE: NodeLoaded = { }; const changeNode = (_: State, { payload }: ChangeNodeAction): State => ({ - nodeId: payload.networkId, + nodeId: payload.nodeId, pending: false }); diff --git a/common/sagas/config.ts b/common/sagas/config.ts index f3fc9afc..cc7f3c5c 100644 --- a/common/sagas/config.ts +++ b/common/sagas/config.ts @@ -143,7 +143,7 @@ export function* handleNodeChangeIntent({ let timeout; try { const { lb, to } = yield race({ - lb: apply(nextNodeConfig, nextNodeConfig.lib.getCurrentBlock), + lb: apply(nextNodeConfig.lib, nextNodeConfig.lib.getCurrentBlock), to: call(delay, 5000) }); currentBlock = lb; diff --git a/common/sagas/wallet/wallet.ts b/common/sagas/wallet/wallet.ts index 2701b0a4..c86daf84 100644 --- a/common/sagas/wallet/wallet.ts +++ b/common/sagas/wallet/wallet.ts @@ -52,6 +52,7 @@ import { loadWalletConfig, saveWalletConfig } from 'utils/localStorage'; import { getTokenBalances, filterScannedTokenBalances } from './helpers'; import { Token } from 'types/network'; import { Web3NodeConfig } from '../../../shared/types/node'; +import { initWeb3Node } from 'sagas/web3'; export interface TokenBalanceLookup { [symbol: string]: TokenBalance; diff --git a/common/selectors/config/index.ts b/common/selectors/config/index.ts index a413631a..0eafedc9 100644 --- a/common/selectors/config/index.ts +++ b/common/selectors/config/index.ts @@ -1,7 +1,6 @@ import { AppState } from 'reducers'; + export * from './meta'; export * from './networks'; export * from './nodes'; export * from './tokens'; - -export const getConfig = (state: AppState) => state.config; diff --git a/common/selectors/config/meta.ts b/common/selectors/config/meta.ts index 48b1ddbe..17f54908 100644 --- a/common/selectors/config/meta.ts +++ b/common/selectors/config/meta.ts @@ -1,5 +1,5 @@ import { AppState } from 'reducers'; -import { getConfig } from 'sagas/config'; +const getConfig = (state: AppState) => state.config; export const getMeta = (state: AppState) => getConfig(state).meta; @@ -8,7 +8,8 @@ export function getOffline(state: AppState): boolean { } export function getAutoGasLimitEnabled(state: AppState): boolean { - return getMeta(state).autoGasLimit; + const meta = getMeta(state); + return meta.autoGasLimit; } export function getLanguageSelection(state: AppState): string { diff --git a/common/selectors/config/networks.ts b/common/selectors/config/networks.ts index d2a8929f..bfa1acea 100644 --- a/common/selectors/config/networks.ts +++ b/common/selectors/config/networks.ts @@ -1,11 +1,11 @@ import { AppState } from 'reducers'; -import { getConfig } from 'selectors/config'; import { CustomNetworkConfig, StaticNetworkConfig, StaticNetworkIds, NetworkContract } from 'types/network'; +const getConfig = (state: AppState) => state.config; export const getNetworks = (state: AppState) => getConfig(state).networks; diff --git a/common/selectors/config/nodes.ts b/common/selectors/config/nodes.ts index 44d1096b..c017e35f 100644 --- a/common/selectors/config/nodes.ts +++ b/common/selectors/config/nodes.ts @@ -1,11 +1,19 @@ import { AppState } from 'reducers'; import { - getConfig, getStaticNetworkConfigs, getCustomNetworkConfigs, isStaticNetworkId } from 'selectors/config'; -import { CustomNodeConfig, StaticNodeConfig, StaticNodeId, Web3NodeConfig } from 'types/node'; +import { + CustomNodeConfig, + StaticNodeConfig, + StaticNodeId, + Web3NodeConfig, + StaticNodeWithWeb3Id +} from 'types/node'; + +const getConfig = (state: AppState) => state.config; + import { INITIAL_STATE as SELECTED_NODE_INITIAL_STATE } from 'reducers/config/nodes/selectedNode'; export const getNodes = (state: AppState) => getConfig(state).nodes; @@ -36,12 +44,12 @@ export const getStaticAltNodeToWeb3 = (state: AppState) => { export const getStaticNodeFromId = (state: AppState, nodeId: StaticNodeId) => getStaticNodeConfigs(state)[nodeId]; -export const isStaticNodeId = (state: AppState, nodeId: string): nodeId is StaticNodeId => +export const isStaticNodeId = (state: AppState, nodeId: string): nodeId is StaticNodeWithWeb3Id => Object.keys(getStaticNodeConfigs(state)).includes(nodeId); const getStaticNodeConfigs = (state: AppState) => getNodes(state).staticNodes; -export const getStaticNodeConfig = (state: AppState): StaticNodeConfig | undefined => { +export const getStaticNodeConfig = (state: AppState) => { const { staticNodes, selectedNode: { nodeId } } = getNodes(state); const defaultNetwork = isStaticNodeId(state, nodeId) ? staticNodes[nodeId] : undefined; @@ -49,9 +57,11 @@ export const getStaticNodeConfig = (state: AppState): StaticNodeConfig | undefin }; export const getWeb3Node = (state: AppState): Web3NodeConfig | null => { + const isWeb3Node = (nodeId: string, _: StaticNodeConfig | Web3NodeConfig): _ is Web3NodeConfig => + nodeId === 'web3'; const currNode = getStaticNodeConfig(state); const currNodeId = getNodeId(state); - if (currNode && currNodeId && isStaticNodeId(state, currNodeId) && currNodeId === 'web3') { + if (currNode && currNodeId && isWeb3Node(currNodeId, currNode)) { return currNode; } return null; diff --git a/common/selectors/config/tokens.ts b/common/selectors/config/tokens.ts index a26fd2eb..16946f19 100644 --- a/common/selectors/config/tokens.ts +++ b/common/selectors/config/tokens.ts @@ -5,6 +5,8 @@ import { SHAPESHIFT_TOKEN_WHITELIST } from 'api/shapeshift'; import { getStaticNetworkConfig } from 'selectors/config'; import { Token } from 'types/network'; +const getConfig = (state: AppState) => state.config; + export function getNetworkTokens(state: AppState): Token[] { const network = getStaticNetworkConfig(state); return network ? network.tokens : []; diff --git a/common/selectors/config/wallet.ts b/common/selectors/config/wallet.ts index 9c106ee6..1974308a 100644 --- a/common/selectors/config/wallet.ts +++ b/common/selectors/config/wallet.ts @@ -2,14 +2,11 @@ import { InsecureWalletName, SecureWalletName, WalletName, walletNames } from 'c import { EXTRA_PATHS } from 'config/dpaths'; import sortedUniq from 'lodash/sortedUniq'; import difference from 'lodash/difference'; -import { - CustomNetworkConfig, - StaticNetworkConfig, - NetworkConfig, - DPathFormats -} from 'types/network'; +import { StaticNetworkConfig, DPathFormats } from 'types/network'; import { AppState } from 'reducers'; import { getStaticNetworkConfigs, getStaticNetworkConfig } from 'selectors/config'; +const getConfig = (state: AppState) => state.config; + type PathType = keyof DPathFormats; type DPathFormat = diff --git a/common/store.ts b/common/store.ts index abba14a2..980f7274 100644 --- a/common/store.ts +++ b/common/store.ts @@ -1,6 +1,9 @@ import throttle from 'lodash/throttle'; import { routerMiddleware } from 'react-router-redux'; + +/* import { State as ConfigState, INITIAL_STATE as configInitialState } from 'reducers/config'; +*/ import { State as CustomTokenState, INITIAL_STATE as customTokensInitialState @@ -88,10 +91,11 @@ const configureStore = () => { const customTokens = dedupeCustomTokens(initialNetwork.tokens, savedCustomTokensState); */ const persistedInitialState = { + /* config: { ...configInitialState, ...savedConfigState - }, + },*/ transaction: { ...transactionInitialState, fields: { @@ -112,10 +116,11 @@ const configureStore = () => { // if 'web3' has persisted as node selection, reset to app default // necessary because web3 is only initialized as a node upon MetaMask / Mist unlock + /* if (persistedInitialState.config.nodeSelection === 'web3') { persistedInitialState.config.nodeSelection = configInitialState.nodeSelection; } - +*/ store = createStore(RootReducer, persistedInitialState, middleware); // Add all of the sagas to the middleware diff --git a/common/utils/network.ts b/common/utils/network.ts index 81669db7..f38ffb6d 100644 --- a/common/utils/network.ts +++ b/common/utils/network.ts @@ -1,7 +1,3 @@ -import { InsecureWalletName, SecureWalletName, WalletName, walletNames } from 'config'; -import { EXTRA_PATHS } from 'config/dpaths'; -import sortedUniq from 'lodash/sortedUniq'; -import difference from 'lodash/difference'; import { CustomNetworkConfig } from 'types/network'; export function makeCustomNetworkId(config: CustomNetworkConfig): string { diff --git a/shared/types/node.d.ts b/shared/types/node.d.ts index 91213a2e..7b0c15b1 100644 --- a/shared/types/node.d.ts +++ b/shared/types/node.d.ts @@ -46,6 +46,8 @@ declare enum StaticNodeId { EXP_TECH = 'exp_tech' } +type StaticNodeWithWeb3Id = StaticNodeId | 'web3'; + type NonWeb3NodeConfigs = { [key in StaticNodeId]: StaticNodeConfig }; interface Web3NodeConfigs {