mirror of
https://github.com/status-im/MyCrypto.git
synced 2025-01-11 19:44:21 +00:00
ab5fa1a799
* Make UnlockHeader a PureComponent * MVP * actually disable wallet format if not determined to be valid format for wallet * default to correct derivation in mnemonic modal * cleanup * fix tslint * use enums for HD wallet getPath * Add stricter typing * Fix labels not updating on selector * Ban hardware wallet support for custom network unsupported chainIds * Fix type error * Fix custom node dPath not being saved * Fix mnemonic modal * default path bugfixes * add react-select * misc fixes; rabbit holing hard. * fix tslint * revert identicon changes * reload on network change :/ * actually reload on network change * really really reload on network change * tslint fixes * Update styles * set table width * fix package versioning * push broken sagas * Fix saga test * fix tslint * address round of review * move non-selectors out to utilty; adjust reload timer * cleanup network util comments * manage wallet disable at WalletDecrypt instead of in both WalletDecrypt and WalletButton * Separate WalletDecrypt props into ownProps / StateProps * disable payment requests on non-eth networks * specialize connect; separate props * remove unused state prop * remove bad import * create tests for networks * Clarify Lite-Send error on non-ethereum networkS * remove string option for network config name * Create concept of always-on 'EXTRA_PATHS'; include SINGULAR_DTV legacy dPath in 'EXTRA_PATHS' * fix multiple imports * address PR comments
160 lines
4.0 KiB
TypeScript
160 lines
4.0 KiB
TypeScript
import {
|
|
ChangeLanguageAction,
|
|
ChangeNodeAction,
|
|
AddCustomNodeAction,
|
|
RemoveCustomNodeAction,
|
|
AddCustomNetworkAction,
|
|
RemoveCustomNetworkAction,
|
|
SetLatestBlockAction,
|
|
ConfigAction
|
|
} from 'actions/config';
|
|
import { TypeKeys } from 'actions/config/constants';
|
|
import {
|
|
NODES,
|
|
NETWORKS,
|
|
NodeConfig,
|
|
CustomNodeConfig,
|
|
NetworkConfig,
|
|
CustomNetworkConfig
|
|
} from 'config';
|
|
import { makeCustomNodeId } from 'utils/node';
|
|
import { makeCustomNetworkId } from 'utils/network';
|
|
|
|
export interface State {
|
|
// FIXME
|
|
languageSelection: string;
|
|
nodeSelection: string;
|
|
node: NodeConfig;
|
|
network: NetworkConfig;
|
|
isChangingNode: boolean;
|
|
offline: boolean;
|
|
autoGasLimit: boolean;
|
|
customNodes: CustomNodeConfig[];
|
|
customNetworks: CustomNetworkConfig[];
|
|
latestBlock: string;
|
|
}
|
|
|
|
const defaultNode = 'eth_mew';
|
|
export const INITIAL_STATE: State = {
|
|
languageSelection: 'en',
|
|
nodeSelection: defaultNode,
|
|
node: NODES[defaultNode],
|
|
network: NETWORKS[NODES[defaultNode].network],
|
|
isChangingNode: false,
|
|
offline: false,
|
|
autoGasLimit: true,
|
|
customNodes: [],
|
|
customNetworks: [],
|
|
latestBlock: '???'
|
|
};
|
|
|
|
function changeLanguage(state: State, action: ChangeLanguageAction): State {
|
|
return {
|
|
...state,
|
|
languageSelection: action.payload
|
|
};
|
|
}
|
|
|
|
function changeNode(state: State, action: ChangeNodeAction): State {
|
|
return {
|
|
...state,
|
|
nodeSelection: action.payload.nodeSelection,
|
|
node: action.payload.node,
|
|
network: action.payload.network,
|
|
isChangingNode: false
|
|
};
|
|
}
|
|
|
|
function changeNodeIntent(state: State): State {
|
|
return {
|
|
...state,
|
|
isChangingNode: true
|
|
};
|
|
}
|
|
|
|
function toggleOffline(state: State): State {
|
|
return {
|
|
...state,
|
|
offline: !state.offline
|
|
};
|
|
}
|
|
|
|
function toggleAutoGasLimitEstimation(state: State): State {
|
|
return {
|
|
...state,
|
|
autoGasLimit: !state.autoGasLimit
|
|
};
|
|
}
|
|
|
|
function addCustomNode(state: State, action: AddCustomNodeAction): State {
|
|
const newId = makeCustomNodeId(action.payload);
|
|
return {
|
|
...state,
|
|
customNodes: [
|
|
...state.customNodes.filter(node => makeCustomNodeId(node) !== newId),
|
|
action.payload
|
|
]
|
|
};
|
|
}
|
|
|
|
function removeCustomNode(state: State, action: RemoveCustomNodeAction): State {
|
|
const id = makeCustomNodeId(action.payload);
|
|
return {
|
|
...state,
|
|
customNodes: state.customNodes.filter(cn => cn !== action.payload),
|
|
nodeSelection: id === state.nodeSelection ? defaultNode : state.nodeSelection
|
|
};
|
|
}
|
|
|
|
function addCustomNetwork(state: State, action: AddCustomNetworkAction): State {
|
|
const newId = makeCustomNetworkId(action.payload);
|
|
return {
|
|
...state,
|
|
customNetworks: [
|
|
...state.customNetworks.filter(node => makeCustomNetworkId(node) !== newId),
|
|
action.payload
|
|
]
|
|
};
|
|
}
|
|
|
|
function removeCustomNetwork(state: State, action: RemoveCustomNetworkAction): State {
|
|
return {
|
|
...state,
|
|
customNetworks: state.customNetworks.filter(cn => cn !== action.payload)
|
|
};
|
|
}
|
|
|
|
function setLatestBlock(state: State, action: SetLatestBlockAction): State {
|
|
return {
|
|
...state,
|
|
latestBlock: action.payload
|
|
};
|
|
}
|
|
|
|
export function config(state: State = INITIAL_STATE, action: ConfigAction): State {
|
|
switch (action.type) {
|
|
case TypeKeys.CONFIG_LANGUAGE_CHANGE:
|
|
return changeLanguage(state, action);
|
|
case TypeKeys.CONFIG_NODE_CHANGE:
|
|
return changeNode(state, action);
|
|
case TypeKeys.CONFIG_NODE_CHANGE_INTENT:
|
|
return changeNodeIntent(state);
|
|
case TypeKeys.CONFIG_TOGGLE_OFFLINE:
|
|
return toggleOffline(state);
|
|
case TypeKeys.CONFIG_TOGGLE_AUTO_GAS_LIMIT:
|
|
return toggleAutoGasLimitEstimation(state);
|
|
case TypeKeys.CONFIG_ADD_CUSTOM_NODE:
|
|
return addCustomNode(state, action);
|
|
case TypeKeys.CONFIG_REMOVE_CUSTOM_NODE:
|
|
return removeCustomNode(state, action);
|
|
case TypeKeys.CONFIG_ADD_CUSTOM_NETWORK:
|
|
return addCustomNetwork(state, action);
|
|
case TypeKeys.CONFIG_REMOVE_CUSTOM_NETWORK:
|
|
return removeCustomNetwork(state, action);
|
|
case TypeKeys.CONFIG_SET_LATEST_BLOCK:
|
|
return setLatestBlock(state, action);
|
|
default:
|
|
return state;
|
|
}
|
|
}
|