diff --git a/src/components/setting/index.js b/src/components/setting/index.js index 5e1a95b461..316c8a6301 100644 --- a/src/components/setting/index.js +++ b/src/components/setting/index.js @@ -5,6 +5,7 @@ import Setting from './setting'; import { settingsUpdated } from '../../actions/settings'; import { toastDisplayed } from '../../actions/toaster'; import { accountUpdated } from '../../actions/account'; +import { networkSet } from '../../actions/network'; import { getActiveTokenAccount } from '../../utils/account'; const mapStateToProps = state => ({ @@ -17,6 +18,7 @@ const mapStateToProps = state => ({ const mapDispatchToProps = { accountUpdated, + networkSet, settingsUpdated, toastDisplayed, }; diff --git a/src/components/topBar/index.js b/src/components/topBar/index.js index 21ec58761b..65ba195086 100644 --- a/src/components/topBar/index.js +++ b/src/components/topBar/index.js @@ -4,6 +4,7 @@ import { withRouter } from 'react-router'; import { translate } from 'react-i18next'; import { accountLoggedOut, accountUpdated } from '../../actions/account'; import { settingsUpdated } from '../../actions/settings'; +import { networkSet } from '../../actions/network'; import accountConfig from '../../constants/account'; import TopBar from './topBar'; @@ -12,12 +13,14 @@ const mapStateToProps = state => ({ network: state.network, token: state.settings.token, autoLogout: state.settings.autoLog, + settings: state.settings, }); const mapDispatchToProps = { - settingsUpdated, logOut: accountLoggedOut, + networkSet, resetTimer: () => accountUpdated({ expireTime: Date.now() + accountConfig.lockDuration }), + settingsUpdated, }; export default withRouter(connect(mapStateToProps, mapDispatchToProps)(translate()(TopBar))); diff --git a/src/components/topBar/topBar.js b/src/components/topBar/topBar.js index b861339250..83b6a9a5c8 100644 --- a/src/components/topBar/topBar.js +++ b/src/components/topBar/topBar.js @@ -8,6 +8,7 @@ import menuLinks from './constants'; import Dropdown from '../toolbox/dropdown/dropdown'; import SearchBar from '../searchBar'; import Network from './network'; +import networks from '../../constants/networks'; import styles from './topBar.css'; import OutsideClickHandler from '../toolbox/outsideClickHandler'; @@ -31,9 +32,17 @@ class TopBar extends React.Component { } onLogout() { + const { + logOut, history, settings, networkSet, network, + } = this.props; + Piwik.trackingEvent('Header', 'button', 'Open logout dialog'); - this.props.logOut(); - this.props.history.replace(`${routes.dashboard.path}`); + logOut(); + history.replace(`${routes.dashboard.path}`); + + if (!settings.showNetwork && network.name !== networks.mainnet.name) { + networkSet(networks.mainnet); + } } onHandleClick(name) { diff --git a/src/components/topBar/topBar.test.js b/src/components/topBar/topBar.test.js index d2d556ec69..59e3b666e0 100644 --- a/src/components/topBar/topBar.test.js +++ b/src/components/topBar/topBar.test.js @@ -57,7 +57,11 @@ describe('TopBar', () => { }, }, }, + settings: { + network: { name: 'Custom Nodee', address: 'hhtp://localhost:4000' }, + }, settingsUpdated: jest.fn(), + networkSet: jest.fn(), }; const history = { diff --git a/src/store/middlewares/account.js b/src/store/middlewares/account.js index b7f704ac51..1e081cee80 100644 --- a/src/store/middlewares/account.js +++ b/src/store/middlewares/account.js @@ -102,6 +102,7 @@ const checkTransactionsAndUpdateAccount = (store, action) => { } }; +// istanbul ignore next const getNetworkFromLocalStorage = () => { const mySettings = localJSONStorage.get('settings', {}); if (!mySettings.network) return networks.mainnet; @@ -114,7 +115,7 @@ const getNetworkFromLocalStorage = () => { }; // eslint-disable-next-line max-statements -const checkNetworkToConnet = () => { +const checkNetworkToConnet = (storeSettings) => { const autologinData = getAutoLogInData(); let loginNetwork = findMatchingLoginNetwork(); @@ -140,14 +141,24 @@ const checkNetworkToConnet = () => { }; } + // istanbul ignore next if (!loginNetwork && !autologinData.liskCoreUrl) { - const currentNetwork = getNetworkFromLocalStorage(); - loginNetwork = { - name: currentNetwork.name, - network: { - ...currentNetwork, - }, - }; + if (storeSettings.showNetwork) { + const currentNetwork = getNetworkFromLocalStorage(); + loginNetwork = { + name: currentNetwork.name, + network: { + ...currentNetwork, + }, + }; + } else { + loginNetwork = { + name: networks.mainnet.name, + network: { + ...networks.mainnet, + }, + }; + } } return loginNetwork; @@ -155,6 +166,7 @@ const checkNetworkToConnet = () => { // eslint-disable-next-line max-statements const autoLogInIfNecessary = async (store) => { + const actualSettings = store && store.getState().settings; const autologinData = getAutoLogInData(); let loginNetwork; @@ -180,7 +192,7 @@ const autoLogInIfNecessary = async (store) => { }; } } else { - loginNetwork = checkNetworkToConnet(); + loginNetwork = checkNetworkToConnet(actualSettings); } store.dispatch(await networkSet(loginNetwork));