signal-desktop/ts/state/selectors/network.ts

32 lines
971 B
TypeScript
Raw Normal View History

2020-10-30 20:34:04 +00:00
// Copyright 2020 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import { createSelector } from 'reselect';
import type { StateType } from '../reducer';
import type { NetworkStateType } from '../ducks/network';
import { isDone } from '../../util/registration';
2021-06-09 22:28:54 +00:00
import { SocketStatus } from '../../types/SocketStatus';
const getNetwork = (state: StateType): NetworkStateType => state.network;
export const hasNetworkDialog = createSelector(
getNetwork,
isDone,
(
{ isOnline, socketStatus, withinConnectingGracePeriod }: NetworkStateType,
isRegistrationDone: boolean
): boolean =>
isRegistrationDone &&
(!isOnline ||
2021-06-09 22:28:54 +00:00
(socketStatus === SocketStatus.CONNECTING &&
!withinConnectingGracePeriod) ||
socketStatus === SocketStatus.CLOSED ||
socketStatus === SocketStatus.CLOSING)
);
export const isChallengePending = createSelector(
getNetwork,
({ challengeStatus }) => challengeStatus === 'pending'
);