Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(improvement) Refactor reboot dialog #711

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions public/locales/en-US/translations.json
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,7 @@
"requestedAlgoOrderNotRunningCannotStop": "Requested algo order not running, cannot stop",
"favouriteTradingPairsSuccessfullySaved": "Favourite trading pairs successfully saved",
"settingsSuccessfullyUpdated": "Settings successfully updated",
"settingsUpdateFailed": "Failed to update settings",
"reconnectingWithNewDmsSetting": "Reconnecting with new DMS setting...",
"connectingTo": "Connecting to {{target}}...",
"connectedTo": "Connected to {{target}}",
Expand Down
8 changes: 4 additions & 4 deletions src/modals/BadConnectionModal/BadConnectionModal.container.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { connect } from 'react-redux'
import UIActions from '../../redux/actions/ui'
import { UI_KEYS } from '../../redux/constants/ui_keys'
import { getUIState } from '../../redux/selectors/ui'
import { getUIModalStateForKey } from '../../redux/selectors/ui'

import BadConnectionModal from './BadConnectionModal'
import { UI_MODAL_KEYS } from '../../redux/constants/modals'

const mapStateToProps = (state = {}) => ({
visible: getUIState(state, UI_KEYS.isBadInternetConnection, false),
visible: getUIModalStateForKey(state, UI_MODAL_KEYS.BAD_INTERNET_CONNECTION_MODAL),
})

const mapDispatchToProps = dispatch => ({
changeBadInternetConnectionState: (visible) => dispatch(UIActions.setUIValue(UI_KEYS.isBadInternetConnection, visible)),
onClose: () => dispatch(UIActions.changeUIModalState(UI_MODAL_KEYS.BAD_INTERNET_CONNECTION_MODAL, false)),
})

export default connect(mapStateToProps, mapDispatchToProps)(BadConnectionModal)
10 changes: 3 additions & 7 deletions src/modals/BadConnectionModal/BadConnectionModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,10 @@ import { isElectronApp } from '../../redux/config'
import './style.css'

const BadConnection = ({
changeBadInternetConnectionState, visible,
onClose, visible,
}) => {
const { t } = useTranslation()

const onClose = () => {
changeBadInternetConnectionState(false)
}

const onRestart = () => {
const path = isElectronApp ? '/index.html' : ''
location.replace(path) // eslint-disable-line
Expand All @@ -37,15 +33,15 @@ const BadConnection = ({
{action}
</Modal.Button>
<Modal.Button onClick={onClose} primary>
{t('ui.ok')}
{t('ui.proceed')}
</Modal.Button>
</Modal.Footer>
</Modal>
)
}

BadConnection.propTypes = {
changeBadInternetConnectionState: PropTypes.func.isRequired,
onClose: PropTypes.func.isRequired,
visible: PropTypes.bool.isRequired,
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const mapStateToProps = (state = {}) => ({
})

const mapDispatchToProps = dispatch => ({
changeIsNoConnectionModalState: (isOpen) => dispatch(UIActions.changeUIModalState(UI_MODAL_KEYS.NO_CONNECTION_MODAL, isOpen)),
onClose: () => dispatch(UIActions.changeUIModalState(UI_MODAL_KEYS.NO_CONNECTION_MODAL, false)),
})

export default connect(mapStateToProps, mapDispatchToProps)(NoConnectionActionModal)
8 changes: 2 additions & 6 deletions src/modals/NoConnectionActionModal/NoConnectionActionModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,10 @@ import Modal from '../../ui/Modal'
import './style.css'

const NoConnectionActionModal = ({
changeIsNoConnectionModalState, visible,
onClose, visible,
}) => {
const { t } = useTranslation()

const onClose = () => {
changeIsNoConnectionModalState(false)
}

return (
<Modal
label={t('noConnectionActionModal.title')}
Expand All @@ -34,7 +30,7 @@ const NoConnectionActionModal = ({
}

NoConnectionActionModal.propTypes = {
changeIsNoConnectionModalState: PropTypes.func.isRequired,
onClose: PropTypes.func.isRequired,
visible: PropTypes.bool.isRequired,
}

Expand Down
6 changes: 6 additions & 0 deletions src/redux/actions/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,11 @@ export const setBacktestActiveSection = (section) => ({
payload: { section },
})

export const setBadInternetConnection = (isBadConnection) => ({
type: types.SET_BAD_INTERNET_CONNECTION,
payload: { isBadConnection },
})

export default {
setUIValue,
updateUIValue,
Expand Down Expand Up @@ -207,4 +212,5 @@ export default {
logInformation,
setBacktestActiveSection,
setNotifications,
setBadInternetConnection,
}
1 change: 1 addition & 0 deletions src/redux/constants/modals.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ export const UI_MODAL_KEYS = {
RESET_LIVE_API_KEY_MODAL: 'ResetLiveApiKeyModal',
RESET_PAPER_API_KEY_MODAL: 'ResetPaperApiKeyModal',
HELP_US_IMPROVE_HONEY_MODAL: 'HelpUsImproveHoneyModal',
BAD_INTERNET_CONNECTION_MODAL: 'BadInternetConnectionModal',
}
2 changes: 2 additions & 0 deletions src/redux/constants/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,6 @@ module.exports = {
LOG: 'UI_LOG',

SET_BACKTEST_ACTIVE_SECTION: 'UI_SET_BACKTEST_ACTIVE_SECTION',

SET_BAD_INTERNET_CONNECTION: 'UI_SET_BAD_INTERNET_CONNECTION',
}
3 changes: 1 addition & 2 deletions src/redux/middleware/ws/on_close.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import WSActions from '../../actions/ws'
import UIActions from '../../actions/ui'
import { getAuthToken, getSocket } from '../../selectors/ws'
import { isElectronApp, env } from '../../config'
import { UI_KEYS } from '../../constants/ui_keys'
import { LOG_LEVELS } from '../../../constants/logging'

export default (alias, store) => () => {
Expand All @@ -15,7 +14,7 @@ export default (alias, store) => () => {
// do not show in hosted mode since it re-attepmpts new connection
// do not mark bad connection if user is still on login screen and ws onClose is triggered
if (!_isNil(socket?.lastActivity) && isElectronApp && isLoggedIn) {
store.dispatch(UIActions.setUIValue(UI_KEYS.isBadInternetConnection, true))
store.dispatch(UIActions.setBadInternetConnection(true))
}

if (env === 'electron') {
Expand Down
4 changes: 2 additions & 2 deletions src/redux/middleware/ws/on_message.js
Original file line number Diff line number Diff line change
Expand Up @@ -324,11 +324,11 @@ export default (alias, store) => (e = {}) => {
store.dispatch(WSActions.recvClientStatusUpdate({ status, mode }))

if (status === WS_CONNECTION.CLOSED) {
store.dispatch(UIActions.setUIValue(UI_KEYS.isBadInternetConnection, true))
store.dispatch(UIActions.setBadInternetConnection(true))
}

if (status === WS_CONNECTION.OPENED) {
store.dispatch(UIActions.setUIValue(UI_KEYS.isBadInternetConnection, false))
store.dispatch(UIActions.setBadInternetConnection(false))
}

break
Expand Down
1 change: 0 additions & 1 deletion src/redux/reducers/ui/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ function getInitialState() {
modals: {},
orderToEdit: {},
isBadInternetConnection: false,
isNoConnectionModalVisible: false,
closePositionModalData: {},
isOrderExecuting: false,
strategyEditor: {
Expand Down
2 changes: 2 additions & 0 deletions src/redux/sagas/ui/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import removeComponent from './on_remove_component'
import createLayout from './on_create_layout'
import deleteLayout from './on_delete_layout'
import onLog from './on_log'
import onBadInternetConnection from './on_bad_internet_connection'
import { isElectronApp } from '../../config'

export default function* () {
Expand All @@ -27,6 +28,7 @@ export default function* () {
yield takeEvery(UITypes.REMOVE_COMPONENT, removeComponent)
yield takeEvery(UITypes.CREATE_LAYOUT, createLayout)
yield takeEvery(UITypes.DELETE_LAYOUT, deleteLayout)
yield takeEvery(UITypes.SET_BAD_INTERNET_CONNECTION, onBadInternetConnection)

if (isElectronApp) {
yield takeEvery(UITypes.DATA_NOTIFICATION, onShowNotification)
Expand Down
16 changes: 16 additions & 0 deletions src/redux/sagas/ui/on_bad_internet_connection.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { put, select } from 'redux-saga/effects'
import UIActions from '../../actions/ui'
import { UI_KEYS } from '../../constants/ui_keys'
import { UI_MODAL_KEYS } from '../../constants/modals'
import { getDMSSetting } from '../../selectors/ui'

function* onBadInternetConnection({ payload: { isBadConnection } }) {
yield put(UIActions.setUIValue(UI_KEYS.isBadInternetConnection, isBadConnection))
const dms = yield select(getDMSSetting)

if (dms) {
yield put(UIActions.changeUIModalState(UI_MODAL_KEYS.BAD_INTERNET_CONNECTION_MODAL, isBadConnection))
}
}

export default onBadInternetConnection
Loading