Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
handleAppStateChange = (nextAppState: string) => {
const {
stopListeningNotifications,
stopListeningIntercomNotifications,
startListeningChatWebSocket,
stopListeningChatWebSocket,
updateSignalInitiatedState,
navigation,
isPickingImage,
isBrowsingWebView,
stopListeningForBalanceChange,
endWalkthrough,
} = this.props;
const { lastAppState } = this.state;
BackgroundTimer.clearTimeout(lockTimer);
if (isPickingImage || isBrowsingWebView) return;
// only checking if background state for logout or websocket channel close
if (APP_LOGOUT_STATES.includes(nextAppState)) {
// close websocket channel instantly to receive PN while in background
stopListeningChatWebSocket();
// close walkthrough shade or tooltips
endWalkthrough();
lockTimer = BackgroundTimer.setTimeout(() => {
const pathAndParams = navigation.router.getPathAndParamsForState(navigation.state);
const lastActiveScreen = pathAndParams.path.split('/').slice(-1)[0];
const lastActiveScreenParams = pathAndParams.params;
updateNavigationLastScreenState({ lastActiveScreen, lastActiveScreenParams });
navigation.navigate(AUTH_FLOW);
stopListeningNotifications();
stopListeningIntercomNotifications();
updateSignalInitiatedState(false);
export const startEndSetTimer = () => (dispatch, getState) => {
BackgroundTimer.clearTimeout(timer);
timer = null;
timeRemaining = null;
startTime = null;
isPaused = false;
let state = getState();
let durationInSeconds = state.settings.endSetTimerDuration;
let isEditing = WorkoutSelectors.getIsEditing(state);
if (durationInSeconds == null || durationInSeconds == 0) {
timer = null;
} else if (isEditing) {
timeRemaining = durationInSeconds * 1000;
isPaused = true;
startTime = Date.now();
// start it paused
lockApp() {
if (!SecureKeychain.getInstance().isAuthenticating) {
this.navigation.navigate('LockScreen', { backgroundMode: true });
this.locked = true;
} else if (this.lockTimer) {
BackgroundTimer.clearTimeout(this.lockTimer);
this.lockTimer = null;
}
}
const clearTimers = () => {
BackgroundTimer.clearTimeout(connectTimeoutTimer);
BackgroundTimer.clearTimeout(reconnectTimeoutTimer);
BackgroundTimer.clearTimeout(reconnectTimer);
connectTimeoutTimer = null;
reconnectTimeoutTimer = null;
reconnectTimer = null;
};
const clearTimers = () => {
BackgroundTimer.clearTimeout(connectTimeoutTimer);
BackgroundTimer.clearTimeout(reconnectTimeoutTimer);
BackgroundTimer.clearTimeout(reconnectTimer);
connectTimeoutTimer = null;
reconnectTimeoutTimer = null;
reconnectTimer = null;
};
handleCancelLookingForNewOrderBtn() {
this.setState({receivedNewOrder: false});
BackgroundTimer.clearTimeout(this.intervalId);
this.props.setWaitingNewOrder(false);
}
export const backgroundLockListener = (action: () => void) => {
if (AppState.currentState === 'background') {
timeout = BackgroundTimer.setTimeout(action, CONFIG.APP_LOCK_TIMEOUT)
} else if (AppState.currentState === 'active') {
BackgroundTimer.clearTimeout(timeout)
}
}
const clearTimers = () => {
BackgroundTimer.clearTimeout(connectTimeoutTimer);
BackgroundTimer.clearTimeout(reconnectTimeoutTimer);
BackgroundTimer.clearTimeout(reconnectTimer);
connectTimeoutTimer = null;
reconnectTimeoutTimer = null;
reconnectTimer = null;
};
const clearTimers = () => {
BackgroundTimer.clearTimeout(connectTimeoutTimer);
BackgroundTimer.clearTimeout(reconnectTimeoutTimer);
BackgroundTimer.clearTimeout(reconnectTimer);
connectTimeoutTimer = null;
reconnectTimeoutTimer = null;
reconnectTimer = null;
};