-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
654b6c9
commit e589f0a
Showing
10 changed files
with
141 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
src/modals/LongTermClosedSessionModal/LongTermClosedSessionModal.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import React from 'react' | ||
import { useDispatch, useSelector } from 'react-redux' | ||
|
||
import { Trans, useTranslation } from 'react-i18next' | ||
import { getUIModalStateForKey } from '../../redux/selectors/ui' | ||
import { UI_MODAL_KEYS } from '../../redux/constants/modals' | ||
import UIActions from '../../redux/actions/ui' | ||
import Modal from '../../ui/Modal' | ||
|
||
const LongTermClosedSessionModal = () => { | ||
const isVisible = useSelector(state => getUIModalStateForKey( | ||
state, | ||
UI_MODAL_KEYS.LONG_TERM_CLOSED_SESSION_MODAL, | ||
)) | ||
|
||
const dispatch = useDispatch() | ||
const { t } = useTranslation() | ||
|
||
const onClose = () => dispatch(UIActions.changeUIModalState( | ||
UI_MODAL_KEYS.LONG_TERM_CLOSED_SESSION_MODAL, | ||
false, | ||
)) | ||
|
||
return ( | ||
<Modal | ||
label={t('longTermClosedSessionModal.title')} | ||
className='hfui-bad-conn-modal__wrapper' | ||
isOpen={isVisible} | ||
onClose={onClose} | ||
onSubmit={onClose} | ||
> | ||
<Trans | ||
t={t} | ||
i18nKey='longTermClosedSessionModal.description' | ||
components={{ | ||
bold: <b />, | ||
}} | ||
/> | ||
<Modal.Footer> | ||
<Modal.Button onClick={onClose} primary> | ||
{t('ui.continueToApp')} | ||
</Modal.Button> | ||
</Modal.Footer> | ||
</Modal> | ||
) | ||
} | ||
|
||
export default LongTermClosedSessionModal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import _isEmpty from 'lodash/isEmpty' | ||
import { put, select } from 'redux-saga/effects' | ||
|
||
import { WS_CONNECTION } from '../../constants/ws' | ||
import { UI_KEYS } from '../../constants/ui_keys' | ||
import UIActions from '../../actions/ui' | ||
import WSActions from '../../actions/ws' | ||
import { UI_MODAL_KEYS } from '../../constants/modals' | ||
import { | ||
getActiveStrategies, | ||
getFilteredLocalAlgoOrders, | ||
getSocket, | ||
} from '../../selectors/ws' | ||
import { getUIModalStateForKey } from '../../selectors/ui' | ||
import { getAPIClientState } from '../../selectors/ws/api_client_state' | ||
|
||
const LONG_TERM_CLOSED_SESSION_MODAL_DELAY = 30 * 60 * 1000 // 30m | ||
|
||
function* longTermModalStateSwitch(state) { | ||
yield put( | ||
UIActions.changeUIModalState( | ||
UI_MODAL_KEYS.LONG_TERM_CLOSED_SESSION_MODAL, | ||
state, | ||
), | ||
) | ||
yield put( | ||
UIActions.changeUIModalState( | ||
UI_MODAL_KEYS.LONG_TERM_CLOSED_SESSION_MODAL_ALREADY_SHOWN, | ||
state, | ||
), | ||
) | ||
} | ||
|
||
export default function* onClientStatusUpdate({ payload }) { | ||
const { status } = payload | ||
|
||
const lastStatus = yield select(getAPIClientState) | ||
const activeStrategies = yield select(getActiveStrategies) | ||
const algoOrders = yield select(getFilteredLocalAlgoOrders) | ||
|
||
const isStatusChanged = status !== lastStatus | ||
|
||
const isLongTermClosedSessionModalAlreadyShown = yield select((state) => getUIModalStateForKey( | ||
state, | ||
UI_MODAL_KEYS.LONG_TERM_CLOSED_SESSION_MODAL_ALREADY_SHOWN, | ||
), | ||
) | ||
|
||
if (status === WS_CONNECTION.CLOSED) { | ||
if (isStatusChanged) { | ||
yield put(UIActions.setUIValue(UI_KEYS.isBadInternetConnection, true)) | ||
} | ||
|
||
const socket = yield select(getSocket) | ||
if ( | ||
(!_isEmpty(activeStrategies) || !_isEmpty(algoOrders)) | ||
&& !isLongTermClosedSessionModalAlreadyShown | ||
&& socket?.lastActivity | ||
&& Date.now() - socket.lastActivity >= LONG_TERM_CLOSED_SESSION_MODAL_DELAY | ||
) { | ||
yield longTermModalStateSwitch(true) | ||
} | ||
} | ||
|
||
if (status === WS_CONNECTION.OPENED) { | ||
if (isStatusChanged) { | ||
yield put(UIActions.setUIValue(UI_KEYS.isBadInternetConnection, false)) | ||
} | ||
yield longTermModalStateSwitch(false) | ||
} | ||
|
||
yield put(WSActions.setAPIClientStatus(payload)) | ||
} |