diff options
| author | Erik Larkö <erik@mullvad.net> | 2017-07-27 11:12:44 +0200 |
|---|---|---|
| committer | Erik Larkö <erik@mullvad.net> | 2017-07-28 11:25:16 +0200 |
| commit | 5616dddc92d76a121d10cbbab5b6404c71ffc25b (patch) | |
| tree | c45c1e6ae79c1702c7285820e8823a9b94b2ebca | |
| parent | 98204a12250222cf5adfb51e9db42d8b28794335 (diff) | |
| download | mullvadvpn-5616dddc92d76a121d10cbbab5b6404c71ffc25b.tar.xz mullvadvpn-5616dddc92d76a121d10cbbab5b6404c71ffc25b.zip | |
Add LOGIN_FAILED action
| -rw-r--r-- | app/lib/backend.js | 5 | ||||
| -rw-r--r-- | app/redux/account/actions.js | 20 | ||||
| -rw-r--r-- | app/redux/account/reducers.js | 5 |
3 files changed, 23 insertions, 7 deletions
diff --git a/app/lib/backend.js b/app/lib/backend.js index 8ad3c2fe32..a58a12a0cd 100644 --- a/app/lib/backend.js +++ b/app/lib/backend.js @@ -175,10 +175,7 @@ export class Backend { // TODO: This is not true. If there is a communication link failure the promise will be rejected too const err = new BackendError('INVALID_ACCOUNT'); - this._store.dispatch(accountActions.loginChange({ - status: 'failed', - error: err, - })); + this._store.dispatch(accountActions.loginFailed(err)); }); } diff --git a/app/redux/account/actions.js b/app/redux/account/actions.js index d1e240f39e..1be1d4c10d 100644 --- a/app/redux/account/actions.js +++ b/app/redux/account/actions.js @@ -1,6 +1,6 @@ // @flow -import type { Backend } from '../../lib/backend'; +import type { Backend, BackendError } from '../../lib/backend'; import type { AccountReduxState } from './reducers.js'; type StartLoginAction = { @@ -11,13 +11,20 @@ type LoginSuccessfulAction = { type: 'LOGIN_SUCCESSFUL', paidUntil: string, }; +type LoginFailedAction = { + type: 'LOGIN_FAILED', + error: BackendError, +}; type LoginChangeAction = { type:'LOGIN_CHANGE', newData: $Shape<AccountReduxState>, }; -export type AccountAction = StartLoginAction | LoginSuccessfulAction | LoginChangeAction; +export type AccountAction = StartLoginAction + | LoginSuccessfulAction + | LoginFailedAction + | LoginChangeAction; function startLogin(accountNumber: string): StartLoginAction { return { @@ -33,6 +40,13 @@ function loginSuccessful(paidUntil: string): LoginSuccessfulAction { }; } +function loginFailed(error: BackendError): LoginFailedAction { + return { + type: 'LOGIN_FAILED', + error: error, + }; +} + function loginChange(data: $Shape<AccountReduxState>): LoginChangeAction { return { type: 'LOGIN_CHANGE', @@ -43,4 +57,4 @@ function loginChange(data: $Shape<AccountReduxState>): LoginChangeAction { const login = (backend: Backend, account: string) => () => backend.login(account); const logout = (backend: Backend) => () => backend.logout(); -export default { login, logout, loginChange, startLogin, loginSuccessful }; +export default { login, logout, loginChange, startLogin, loginSuccessful, loginFailed }; diff --git a/app/redux/account/reducers.js b/app/redux/account/reducers.js index 975c15e772..dedddd35b7 100644 --- a/app/redux/account/reducers.js +++ b/app/redux/account/reducers.js @@ -35,6 +35,11 @@ export default function(state: AccountReduxState = initialState, action: ReduxAc error: null, paidUntil: action.paidUntil, }}; + case 'LOGIN_FAILED': + return { ...state, ...{ + status: 'failed', + error: action.error, + }}; } return state; |
