summaryrefslogtreecommitdiffhomepage
path: root/app
diff options
context:
space:
mode:
authorErik Larkö <erik@mullvad.net>2017-07-25 14:02:33 +0200
committerErik Larkö <erik@mullvad.net>2017-07-28 11:25:16 +0200
commite2bf350e0742724f86a131c7421fea50c839f378 (patch)
tree983f2f903afb67298f0c5e6a1ec1fe69264879eb /app
parenta196629083e1fb634a1d65e816a1b4bdfbdeb072 (diff)
downloadmullvadvpn-e2bf350e0742724f86a131c7421fea50c839f378.tar.xz
mullvadvpn-e2bf350e0742724f86a131c7421fea50c839f378.zip
Added START_LOGIN action
Diffstat (limited to 'app')
-rw-r--r--app/lib/backend.js11
-rw-r--r--app/redux/account/actions.js18
-rw-r--r--app/redux/account/reducers.js9
-rw-r--r--app/redux/store.js4
4 files changed, 30 insertions, 12 deletions
diff --git a/app/lib/backend.js b/app/lib/backend.js
index 3c322afa6d..53e724fcfc 100644
--- a/app/lib/backend.js
+++ b/app/lib/backend.js
@@ -148,16 +148,12 @@ export class Backend {
}
- login(accountNumber: string) {
+ login(accountNumber: string): Promise<void> {
log.info('Attempting to login with account number', accountNumber);
- this._store.dispatch(accountActions.loginChange({
- accountNumber: accountNumber,
- status: 'logging in',
- error: null,
- }));
+ this._store.dispatch(accountActions.startLogin(accountNumber));
- this._ipc.getAccountData(accountNumber)
+ return this._ipc.getAccountData(accountNumber)
.then( response => {
log.info('Account exists', response);
@@ -169,6 +165,7 @@ export class Backend {
this._store.dispatch(accountActions.loginChange({
status: 'ok',
+ accountNumber: accountNumber,
paidUntil: accountData.paid_until,
error: null,
}));
diff --git a/app/redux/account/actions.js b/app/redux/account/actions.js
index 0b828c678a..5e423f3aa8 100644
--- a/app/redux/account/actions.js
+++ b/app/redux/account/actions.js
@@ -3,11 +3,25 @@
import type { Backend } from '../../lib/backend';
import type { AccountReduxState } from './reducers.js';
-export type LoginChangeAction = {
+type StartLoginAction = {
+ type: 'START_LOGIN',
+ accountNumber: string,
+};
+
+type LoginChangeAction = {
type:'LOGIN_CHANGE',
newData: $Shape<AccountReduxState>,
};
+export type AccountAction = StartLoginAction | LoginChangeAction;
+
+function startLogin(accountNumber: string): StartLoginAction {
+ return {
+ type: 'START_LOGIN',
+ accountNumber: accountNumber,
+ };
+}
+
function loginChange(data: $Shape<AccountReduxState>): LoginChangeAction {
return {
type: 'LOGIN_CHANGE',
@@ -18,4 +32,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 };
+export default { login, logout, loginChange, startLogin };
diff --git a/app/redux/account/reducers.js b/app/redux/account/reducers.js
index d1fd284ee5..2ac8595d90 100644
--- a/app/redux/account/reducers.js
+++ b/app/redux/account/reducers.js
@@ -20,8 +20,15 @@ const initialState: AccountReduxState = {
export default function(state: AccountReduxState = initialState, action: ReduxAction): AccountReduxState {
- if (action.type === 'LOGIN_CHANGE') {
+ switch (action.type) {
+ case 'LOGIN_CHANGE':
return { ...state, ...action.newData };
+ case 'START_LOGIN':
+ return { ...state, ...{
+ status: 'logging in',
+ accountNumber: action.accountNumber,
+ error: null,
+ }};
}
return state;
diff --git a/app/redux/store.js b/app/redux/store.js
index 0a72a1869a..b4aa0375e1 100644
--- a/app/redux/store.js
+++ b/app/redux/store.js
@@ -17,7 +17,7 @@ import type { ConnectionReduxState } from './connection/reducers.js';
import type { SettingsReduxState } from './settings/reducers.js';
import type { ConnectionAction } from './connection/actions.js';
-import type { LoginChangeAction } from './account/actions.js';
+import type { AccountAction } from './account/actions.js';
import type { UpdateSettingsAction } from './settings/actions.js';
export type ReduxState = {
@@ -26,7 +26,7 @@ export type ReduxState = {
settings: SettingsReduxState
};
-export type ReduxAction = LoginChangeAction
+export type ReduxAction = AccountAction
| UpdateSettingsAction
| ConnectionAction;