diff --git a/common/components/Header/index.tsx b/common/components/Header/index.tsx index 4b26bf92..69d6b9e7 100644 --- a/common/components/Header/index.tsx +++ b/common/components/Header/index.tsx @@ -38,6 +38,7 @@ import { } from 'selectors/config'; import { NetworkConfig } from 'types/network'; import { connect } from 'react-redux'; +import { stripWeb3Network } from 'libs/nodes'; interface DispatchProps { changeLanguage: TChangeLanguage; @@ -119,7 +120,7 @@ class Header extends Component { ...rest, name: ( - {label.network} ({label.service}) + {stripWeb3Network(label.network)} ({label.service}) ) }; @@ -160,7 +161,7 @@ class Header extends Component { color="white" /> - + {console.log(nodeSelection)}
{ - // State - wallet: AppState['wallet']['inst']; - // Actions +interface DispatchProps { + web3UnsetNode: TWeb3UnsetNode; resetWallet: TResetWallet; } +interface StateProps { + wallet: AppState['wallet']['inst']; +} + +type Props = DispatchProps & StateProps & RouteComponentProps<{}>; + interface State { nextLocation: RouteComponentProps<{}>['location'] | null; openModal: boolean; @@ -65,6 +70,7 @@ class LogOutPromptClass extends React.Component { private onConfirm = () => { const { nextLocation: next } = this.state; this.props.resetWallet(); + this.props.web3UnsetNode(); this.setState( { openModal: false, @@ -84,5 +90,6 @@ function mapStateToProps(state: AppState) { } export default connect(mapStateToProps, { - resetWallet + resetWallet, + web3UnsetNode })(withRouter(LogOutPromptClass)); diff --git a/common/libs/nodes/index.ts b/common/libs/nodes/index.ts index 5e30908d..8f6abf5a 100644 --- a/common/libs/nodes/index.ts +++ b/common/libs/nodes/index.ts @@ -51,6 +51,8 @@ export const getShepherdManualMode = () => redux.store.getState().providerBalancer.balancerConfig.manual; export const getShepherdOffline = () => redux.store.getState().providerBalancer.balancerConfig.offline; +export const getShepherdNetwork = () => + redux.store.getState().providerBalancer.balancerConfig.network; export const makeWeb3Network = (network: string) => `WEB3_${network}`; export const stripWeb3Network = (network: string) => network.replace('WEB3_', ''); diff --git a/common/sagas/config/node.ts b/common/sagas/config/node.ts index 5f847553..9a8c3716 100644 --- a/common/sagas/config/node.ts +++ b/common/sagas/config/node.ts @@ -40,7 +40,8 @@ import { shepherd, shepherdProvider, stripWeb3Network, - makeProviderConfig + makeProviderConfig, + getShepherdNetwork } from 'libs/nodes'; export function* pollOfflineStatus(): SagaIterator { @@ -149,7 +150,7 @@ export function* handleNodeChangeIntent({ if (isAutoNode(nodeIdToSwitchTo)) { shepherd.auto(); - if (currentConfig.network !== nextNodeConfig.network) { + if (getShepherdNetwork() !== nextNodeConfig.network) { yield apply(shepherd, shepherd.switchNetworks, [nextNodeConfig.network]); } } else { diff --git a/common/sagas/config/web3.ts b/common/sagas/config/web3.ts index f18d804c..0f8bbdc4 100644 --- a/common/sagas/config/web3.ts +++ b/common/sagas/config/web3.ts @@ -13,7 +13,6 @@ import { getNodeId, getStaticAltNodeIdToWeb3, getNetworkNameByChainId, - getNetworkConfig, getWeb3Node } from 'selectors/config'; import { setupWeb3Node, Web3Service, isWeb3Node } from 'libs/nodes/web3'; @@ -26,7 +25,6 @@ import { stripWeb3Network, shepherdProvider } from 'libs/nodes'; -import { NetworkConfig } from 'shared/types/network'; import { StaticNodeConfig } from 'shared/types/node'; import { showNotification } from 'actions/notifications'; import translate from 'translations'; @@ -108,16 +106,10 @@ export function* unsetWeb3NodeOnWalletEvent(action: SetWalletAction): SagaIterat return; } - const network: NetworkConfig = yield select(getNetworkConfig); + const altNodeId: string = yield select(getStaticAltNodeIdToWeb3); - if (getShepherdManualMode()) { - yield apply(shepherd, shepherd.auto); - } - yield apply(shepherd, shepherd.switchNetworks, [stripWeb3Network(network.name)]); - - const altNode = yield select(getStaticAltNodeIdToWeb3); // forcefully switch back to a node with the same network as MetaMask/Mist - yield put(changeNodeForce(altNode)); + yield put(changeNodeForce(altNodeId)); } export function* unsetWeb3Node(): SagaIterator { @@ -127,16 +119,10 @@ export function* unsetWeb3Node(): SagaIterator { return; } - const network: NetworkConfig = yield select(getNetworkConfig); + const altNodeId: string = yield select(getStaticAltNodeIdToWeb3); - if (getShepherdManualMode()) { - yield apply(shepherd, shepherd.auto); - } - yield apply(shepherd, shepherd.switchNetworks, [stripWeb3Network(network.name)]); - - const altNode = yield select(getStaticAltNodeIdToWeb3); // forcefully switch back to a node with the same network as MetaMask/Mist - yield put(changeNodeForce(altNode)); + yield put(changeNodeForce(altNodeId)); } export const web3 = [ diff --git a/spec/reducers/config/config.spec.ts b/spec/reducers/config/config.spec.ts index 79c28f70..43db1533 100644 --- a/spec/reducers/config/config.spec.ts +++ b/spec/reducers/config/config.spec.ts @@ -22,8 +22,7 @@ import { isStaticNodeId, getStaticNodeFromId, getCustomNodeFromId, - getStaticAltNodeIdToWeb3, - getNetworkConfig + getStaticAltNodeIdToWeb3 } from 'selectors/config'; import { Web3Wallet } from 'libs/wallet'; import { showNotification } from 'actions/notifications'; @@ -270,25 +269,17 @@ describe('handleNodeChangeIntent*', () => { }); describe('unsetWeb3Node*', () => { - const node = 'web3'; const alternativeNodeId = 'eth_mycrypto'; + const mockNodeId = 'web3'; const gen = unsetWeb3Node(); it('should select getNode', () => { expect(gen.next().value).toEqual(select(getNodeId)); }); - it('should get the current network', () => { - expect(gen.next(node).value).toEqual(select(getNetworkConfig)); - }); - - it('should switch networks', () => { - expect(gen.next({ name: '' }).value).toEqual(apply(shepherd, shepherd.switchNetworks, [''])); - }); - it('should select an alternative node to web3', () => { // get a 'no visual difference' error here - expect(gen.next().value).toEqual(select(getStaticAltNodeIdToWeb3)); + expect(gen.next(mockNodeId).value).toEqual(select(getStaticAltNodeIdToWeb3)); }); it('should put changeNodeForce', () => { @@ -317,14 +308,6 @@ describe('unsetWeb3NodeOnWalletEvent*', () => { expect(gen.next().value).toEqual(select(getNodeId)); }); - it('should get the current network', () => { - expect(gen.next(mockNodeId).value).toEqual(select(getNetworkConfig)); - }); - - it('should switch networks', () => { - expect(gen.next({ name: '' }).value).toEqual(apply(shepherd, shepherd.switchNetworks, [''])); - }); - it('should select an alternative node to web3', () => { expect(gen.next(mockNodeId).value).toEqual(select(getStaticAltNodeIdToWeb3)); });