Skip to content
This repository has been archived by the owner on Apr 15, 2019. It is now read-only.

Commit

Permalink
Add accountSwitched action
Browse files Browse the repository at this point in the history
  • Loading branch information
slaweet committed Nov 8, 2017
1 parent b03e510 commit 4093148
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/actions/savedAccounts.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,17 @@ export const accountRemoved = (publicKey) => {
};
};

/**
* An action to dispatch accountSwitched
*/
export const accountSwitched = (account) => {
setLastActiveAccount(account);
return {
data: account,
type: actionTypes.accountSwitched,
};
};

/**
* The action to initiate savedAccounts store with the retrieved accounts
*
Expand Down
1 change: 1 addition & 0 deletions src/constants/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const actionTypes = {
accountsRetrieved: 'ACCOUNTS_RETRIEVED',
accountSaved: 'ACCOUNT_SAVED',
accountRemoved: 'ACCOUNT_REMOVED',
accountSwitched: 'ACCOUNT_SWITCHED',
};

export default actionTypes;
10 changes: 10 additions & 0 deletions src/store/middlewares/savedAccounts.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import i18next from 'i18next';
import actionTypes from '../../constants/actions';
import { successToastDisplayed } from '../../actions/toaster';
import { accountLoggedOut } from '../../actions/account';
import { activePeerSet } from '../../actions/peers';
import getNetwork from '../../utils/getNetwork';

const savedAccountsMiddleware = store => next => (action) => {
next(action);
Expand All @@ -11,6 +14,13 @@ const savedAccountsMiddleware = store => next => (action) => {
case actionTypes.accountRemoved:
store.dispatch(successToastDisplayed({ label: i18next.t('Account was successfully forgotten.') }));
break;
case actionTypes.accountSwitched:
store.dispatch(accountLoggedOut());
store.dispatch(activePeerSet({
publicKey: action.data.publicKey,
network: getNetwork(action.data.network),
}));
break;
default:
break;
}
Expand Down

0 comments on commit 4093148

Please sign in to comment.