Show challenge when requested by server

This commit is contained in:
Fedor Indutny 2021-05-05 17:09:29 -07:00 committed by GitHub
parent 03c68da17d
commit 986d8a66bc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
42 changed files with 1986 additions and 128 deletions

View file

@ -11,6 +11,7 @@ export type NetworkStateType = {
isOnline: boolean;
socketStatus: SocketStatus;
withinConnectingGracePeriod: boolean;
challengeStatus: 'required' | 'pending' | 'idle';
};
// Actions
@ -18,6 +19,7 @@ export type NetworkStateType = {
const CHECK_NETWORK_STATUS = 'network/CHECK_NETWORK_STATUS';
const CLOSE_CONNECTING_GRACE_PERIOD = 'network/CLOSE_CONNECTING_GRACE_PERIOD';
const RELINK_DEVICE = 'network/RELINK_DEVICE';
const SET_CHALLENGE_STATUS = 'network/SET_CHALLENGE_STATUS';
export type CheckNetworkStatusPayloadType = {
isOnline: boolean;
@ -37,10 +39,18 @@ type RelinkDeviceActionType = {
type: 'network/RELINK_DEVICE';
};
type SetChallengeStatusActionType = {
type: 'network/SET_CHALLENGE_STATUS';
payload: {
challengeStatus: NetworkStateType['challengeStatus'];
};
};
export type NetworkActionType =
| CheckNetworkStatusAction
| CloseConnectingGracePeriodActionType
| RelinkDeviceActionType;
| RelinkDeviceActionType
| SetChallengeStatusActionType;
// Action Creators
@ -67,19 +77,30 @@ function relinkDevice(): RelinkDeviceActionType {
};
}
function setChallengeStatus(
challengeStatus: NetworkStateType['challengeStatus']
): SetChallengeStatusActionType {
return {
type: SET_CHALLENGE_STATUS,
payload: { challengeStatus },
};
}
export const actions = {
checkNetworkStatus,
closeConnectingGracePeriod,
relinkDevice,
setChallengeStatus,
};
// Reducer
function getEmptyState(): NetworkStateType {
export function getEmptyState(): NetworkStateType {
return {
isOnline: navigator.onLine,
socketStatus: WebSocket.OPEN,
withinConnectingGracePeriod: true,
challengeStatus: 'idle',
};
}
@ -105,5 +126,12 @@ export function reducer(
};
}
if (action.type === SET_CHALLENGE_STATUS) {
return {
...state,
challengeStatus: action.payload.challengeStatus,
};
}
return state;
}