Skip to content

Commit

Permalink
Logout when the last saved account is removed - Closes #281
Browse files Browse the repository at this point in the history
  • Loading branch information
slaweet committed Feb 11, 2018
1 parent a91ee84 commit db932b3
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 22 deletions.
2 changes: 2 additions & 0 deletions src/components/savedAccounts/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { connect } from 'react-redux';
import { withRouter } from 'react-router';
import { translate } from 'react-i18next';
import { accountRemoved, accountSwitched } from '../../actions/savedAccounts';
import { accountLoggedOut } from '../../actions/account';
import SavedAccounts from './savedAccounts';

const mapStateToProps = state => ({
Expand All @@ -12,6 +13,7 @@ const mapStateToProps = state => ({
const mapDispatchToProps = dispatch => ({
accountRemoved: data => dispatch(accountRemoved(data)),
accountSwitched: data => dispatch(accountSwitched(data)),
accountLoggedOut: () => dispatch(accountLoggedOut()),
});

export default connect(
Expand Down
4 changes: 4 additions & 0 deletions src/components/savedAccounts/savedAccounts.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ class SavedAccounts extends React.Component {
}

toggleEdit() {
if (this.props.savedAccounts.length === 0) {
this.props.accountLoggedOut();
}

this.setState({
editing: !this.state.editing,
accountSelectedForRemove: null,
Expand Down
2 changes: 0 additions & 2 deletions src/store/reducers/peers.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ const peers = (state = { status: {}, options: {} }, action) => {
});
case actionTypes.activePeerUpdate:
return Object.assign({}, state, { status: action.data });
case actionTypes.accountLoggedOut:
return Object.assign({}, state, { data: {}, status: {}, options: {} });
default:
return state;
}
Expand Down
20 changes: 0 additions & 20 deletions src/store/reducers/peers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,25 +33,5 @@ describe('Reducer: peers(state, action)', () => {
const changedState = peers(state, action);
expect(changedState).to.deep.equal(newState);
});

it('should return and empty state object if action is accountLoggedOut', () => {
const state = {
data: {
currentPeer: 'localhost',
port: 4000,
options: {
name: 'Custom Node',
},
},
status: { online: true },
};
const action = {
type: actionTypes.accountLoggedOut,
};

const newState = { status: {}, data: {}, options: {} };
const changedState = peers(state, action);
expect(changedState).to.deep.equal(newState);
});
});

0 comments on commit db932b3

Please sign in to comment.