diff --git a/src/components/AccountSummary/AccountSummary.container.js b/src/components/AccountSummary/AccountSummary.container.js index c729f4c2d..f0e3b1fed 100644 --- a/src/components/AccountSummary/AccountSummary.container.js +++ b/src/components/AccountSummary/AccountSummary.container.js @@ -12,6 +12,7 @@ import { getPageLoading, getDataReceived, } from 'state/accountSummary/selectors' +import { getIsTurkishSite } from 'state/base/selectors' import AccountSummary from './AccountSummary' @@ -19,6 +20,7 @@ const mapStateToProps = state => ({ data: getData(state), pageLoading: getPageLoading(state), dataReceived: getDataReceived(state), + isTurkishSite: getIsTurkishSite(state), }) const mapDispatchToProps = { diff --git a/src/components/AccountSummary/AccountSummary.js b/src/components/AccountSummary/AccountSummary.js index b46d1648a..96410bc0f 100644 --- a/src/components/AccountSummary/AccountSummary.js +++ b/src/components/AccountSummary/AccountSummary.js @@ -40,6 +40,7 @@ class AccountSummary extends PureComponent { }), dataReceived: PropTypes.bool.isRequired, fetchData: PropTypes.func.isRequired, + isTurkishSite: PropTypes.bool.isRequired, pageLoading: PropTypes.bool.isRequired, refresh: PropTypes.func.isRequired, t: PropTypes.func.isRequired, @@ -65,6 +66,7 @@ class AccountSummary extends PureComponent { refresh, pageLoading, dataReceived, + isTurkishSite, } = this.props let showContent @@ -84,19 +86,23 @@ class AccountSummary extends PureComponent { data={data} title='accountsummary.fees' /> - + {!isTurkishSite && ( + <> + + + + )}
- ({ authIsShown: getIsShown(state), authStatus: getAuthStatus(state), + isTurkishSite: getIsTurkishSite(state), errorDialogDisabled: getIsErrorDialogDisabled(state), }) diff --git a/src/components/Main/Main.js b/src/components/Main/Main.js index ee0b2685a..a17787bba 100644 --- a/src/components/Main/Main.js +++ b/src/components/Main/Main.js @@ -1,4 +1,5 @@ -import React, { Fragment, PureComponent } from 'react' +import React, { PureComponent } from 'react' +import PropTypes from 'prop-types' import { Route, Switch } from 'react-router-dom' import AccountBalance from 'components/AccountBalance' @@ -47,8 +48,6 @@ import { getPath } from 'state/query/utils' import NavMenu from 'ui/NavMenu' import config from 'config' -import { propTypes, defaultProps } from './Main.props' - const { MENU_ACCOUNT_BALANCE, MENU_ACCOUNT_SUMMARY, @@ -118,15 +117,27 @@ const PATHS = { } class Main extends PureComponent { + static propTypes = { + authIsShown: PropTypes.bool, + authStatus: PropTypes.bool.isRequired, + isTurkishSite: PropTypes.bool.isRequired, + errorDialogDisabled: PropTypes.bool.isRequired, + } + + static defaultProps = { + authIsShown: false, + } + render() { const { authStatus, authIsShown, + isTurkishSite, errorDialogDisabled, } = this.props return authStatus && !authIsShown ? ( - + <>
@@ -135,11 +146,13 @@ class Main extends PureComponent { path={PATHS.MENU_LEDGERS} component={Ledgers} /> - + {!isTurkishSite && ( + + )} - - - - - + {!isTurkishSite && ( + [ + , + , + , + , + , + ] + )} - + {!isTurkishSite && ( + + )} - + {!isTurkishSite && ( + + )} - + ) : '' } } -Main.propTypes = propTypes -Main.defaultProps = defaultProps - export default Main diff --git a/src/components/Main/Main.props.js b/src/components/Main/Main.props.js deleted file mode 100644 index 1f04da574..000000000 --- a/src/components/Main/Main.props.js +++ /dev/null @@ -1,11 +0,0 @@ -import PropTypes from 'prop-types' - -export const propTypes = { - authIsShown: PropTypes.bool.isRequired, - authStatus: PropTypes.bool.isRequired, - errorDialogDisabled: PropTypes.bool.isRequired, -} - -export const defaultProps = { - authIsShown: false, -} diff --git a/src/components/Main/index.js b/src/components/Main/index.js index 062a1615e..eb3b39f1c 100644 --- a/src/components/Main/index.js +++ b/src/components/Main/index.js @@ -1,3 +1 @@ -import Main from './Main.container' - -export default Main +export { default } from './Main.container' diff --git a/src/state/base/actions.js b/src/state/base/actions.js index 2f2b786d2..f9bfc1896 100644 --- a/src/state/base/actions.js +++ b/src/state/base/actions.js @@ -73,9 +73,17 @@ export function toggleTableScroll() { } } +export function setSrc(src) { + return { + type: types.SET_SRC, + payload: src, + } +} + export default { setDateFormat, setLang, + setSrc, setTheme, setTimezone, showMilliseconds, diff --git a/src/state/base/constants.js b/src/state/base/constants.js index ff03e3ed3..650ff542d 100644 --- a/src/state/base/constants.js +++ b/src/state/base/constants.js @@ -9,10 +9,13 @@ export default { 'YY-MM-DD', 'YYYY-MM-DD', ], + DEFAULT_SRC: 'bfx', + TR_SRC: 'bfx-tr', DEFAULT_TIMEZONE: 'Etc/UTC', SET_SYNC_STATE: 'BITFINEX/SYNC/SET_STATE', SET_DATE_FORMAT: 'BITFINEX/DATEFORMAT/SET', SET_LANG: 'BITFINEX/LANG/SET', + SET_SRC: 'BITFINEX/SRC/SET', SET_THEME: 'BITFINEX/THEME/SET', SET_TIMEZONE: 'BITFINEX/TIMEZONE/SET', UPDATE_THEME: 'BITFINEX/THEME/UPDATE', diff --git a/src/state/base/reducer.js b/src/state/base/reducer.js index 52b88f706..c240c3c79 100644 --- a/src/state/base/reducer.js +++ b/src/state/base/reducer.js @@ -8,6 +8,7 @@ const initialState = { theme: types.DEFAULT_THEME, timezone: types.DEFAULT_TIMEZONE, milliseconds: false, + src: types.DEFAULT_SRC, tableScroll: getDefaultTableScrollSetting(), } @@ -34,6 +35,11 @@ export function baseReducer(state = initialState, action) { ...state, dateFormat: payload, } + case types.SET_SRC: + return { + ...state, + src: payload, + } case types.SHOW_MILLISECONDS: return { ...state, diff --git a/src/state/base/selectors.js b/src/state/base/selectors.js index a1214dcdf..c83356572 100644 --- a/src/state/base/selectors.js +++ b/src/state/base/selectors.js @@ -1,4 +1,5 @@ import memoizeOne from 'memoize-one' +import _isEqual from 'lodash/isEqual' import { formatTime, timeOffset } from 'state/utils' @@ -12,6 +13,8 @@ export const getTimezone = state => getBase(state).timezone export const getDateFormat = state => getBase(state).dateFormat || types.DATE_FORMATS[0] export const getShowMilliseconds = state => getBase(state).milliseconds || false export const getTableScroll = state => getBase(state).tableScroll || false +export const getSrc = state => getBase(state)?.src ?? types.DEFAULT_SRC +export const getIsTurkishSite = state => _isEqual(getSrc(state), types.TR_SRC) export const getTimeOffset = state => timeOffset(getTimezone(state)) @@ -43,8 +46,10 @@ export default { getBase, getDateFormat, getFullTime, + getIsTurkishSite, getLocale, getShowMilliseconds, + getSrc, getTheme, getTimeOffset, getTimezone, diff --git a/src/state/ui/saga.js b/src/state/ui/saga.js index faf58d1bd..e2097bd60 100644 --- a/src/state/ui/saga.js +++ b/src/state/ui/saga.js @@ -3,20 +3,23 @@ import { } from 'redux-saga/effects' import { REHYDRATE } from 'redux-persist' -import { setTimezone, setTheme, setLang } from 'state/base/actions' -import { checkAuth, updateAuth } from 'state/auth/actions' -import { setTimeRange } from 'state/timeRange/actions' -import { getParsedUrlParams, isValidTimezone, removeUrlParams } from 'state/utils' -import { getNewTheme, getThemeClass, verifyTheme } from 'utils/themes' import config from 'config' -import timeRangeTypes from 'state/timeRange/constants' -import { getTheme } from 'state/base/selectors' import { LANGUAGES } from 'locales/i18n' +import { + setTimezone, setTheme, setLang, setSrc, +} from 'state/base/actions' +import { getTheme } from 'state/base/selectors' +import { setTimeRange } from 'state/timeRange/actions' +import timeRangeTypes from 'state/timeRange/constants' import handleElectronLoad from 'utils/handleElectronLoad' +import { checkAuth, updateAuth } from 'state/auth/actions' +import { getNewTheme, getThemeClass, verifyTheme } from 'utils/themes' +import { getParsedUrlParams, isValidTimezone, removeUrlParams } from 'state/utils' import types from './constants' -import { togglePaginationDialog } from './actions' import selectors from './selectors' +import { togglePaginationDialog } from './actions' + function* uiLoaded() { if (config.isElectronApp) { @@ -25,9 +28,13 @@ function* uiLoaded() { const parsed = getParsedUrlParams(window.location.search) const { - authToken, apiKey, apiSecret, timezone, theme, locale, range, + authToken, apiKey, apiSecret, timezone, theme, locale, range, src, } = parsed + if (src) { + yield put(setSrc(src)) + } + removeUrlParams(['timezone', 'theme', 'locale', 'authToken', 'apiKey', 'apiSecret']) // handle custom timezone diff --git a/src/ui/NavMenu/NavMenu.container.js b/src/ui/NavMenu/NavMenu.container.js index 201c6e715..1b267e8d9 100644 --- a/src/ui/NavMenu/NavMenu.container.js +++ b/src/ui/NavMenu/NavMenu.container.js @@ -1,15 +1,20 @@ +import { compose } from 'redux' import { connect } from 'react-redux' import { withRouter } from 'react-router-dom' +import { withTranslation } from 'react-i18next' import { getWindowWidth } from 'state/ui/selectors' +import { getIsTurkishSite } from 'state/base/selectors' import NavMenu from './NavMenu' const mapStateToProps = state => ({ windowWidth: getWindowWidth(state), + isTurkishSite: getIsTurkishSite(state), }) - -const NavMenuContainer = connect(mapStateToProps)(withRouter(NavMenu)) - -export default NavMenuContainer +export default compose( + withTranslation('translations'), + connect(mapStateToProps), + withRouter, +)(NavMenu) diff --git a/src/ui/NavMenu/NavMenu.js b/src/ui/NavMenu/NavMenu.js index f20839d08..7edb8a029 100644 --- a/src/ui/NavMenu/NavMenu.js +++ b/src/ui/NavMenu/NavMenu.js @@ -1,5 +1,5 @@ import React, { PureComponent } from 'react' -import { withTranslation } from 'react-i18next' +import PropTypes from 'prop-types' import classNames from 'classnames' import { Classes, @@ -7,15 +7,15 @@ import { MenuDivider, MenuItem, } from '@blueprintjs/core' -import _castArray from 'lodash/castArray' +import _map from 'lodash/map' import _includes from 'lodash/includes' +import _castArray from 'lodash/castArray' +import config from 'config' import queryType from 'state/query/constants' import { getIcon, getPath, getTarget } from 'state/query/utils' -import config from 'config' import NavMenuPopover from './NavMenuPopover' -import { propTypes, defaultProps } from './NavMenu.props' const { showFrameworkMode } = config @@ -56,30 +56,47 @@ const { } = queryType class NavMenu extends PureComponent { - static propTypes = propTypes + static propTypes = { + target: PropTypes.string, + className: PropTypes.string, + history: PropTypes.shape({ + location: PropTypes.shape({ + pathname: PropTypes.string.isRequired, + search: PropTypes.string.isRequired, + }).isRequired, + push: PropTypes.func.isRequired, + }).isRequired, + showMenuPopover: PropTypes.bool, + t: PropTypes.func.isRequired, + isTurkishSite: PropTypes.bool.isRequired, + } - static defaultProps = defaultProps + static defaultProps = { + className: '', + target: undefined, + showMenuPopover: true, + } - sections = [ + getSections = (isTurkishSite) => [ [MENU_LEDGERS, 'ledgers.title'], - [MENU_INVOICES, 'invoices.title'], + [MENU_INVOICES, 'invoices.title', isTurkishSite], [[MENU_TRADES, MENU_CANDLES], 'trades.title'], [[MENU_ORDERS, MENU_ORDER_TRADES], 'orders.title'], [MENU_MOVEMENTS, 'movements.title'], [[MENU_POSITIONS, MENU_POSITIONS_ACTIVE, MENU_POSITIONS_AUDIT], 'positions.title'], [MENU_WALLETS, 'wallets.title'], ['divider'], - [MENU_FOFFER, 'foffer.title'], - [MENU_FLOAN, 'floan.title'], - [MENU_FCREDIT, 'fcredit.title'], - [MENU_FPAYMENT, 'fpayment.title'], - [MENU_SPAYMENTS, 'spayments.title'], + [MENU_FOFFER, 'foffer.title', isTurkishSite], + [MENU_FLOAN, 'floan.title', isTurkishSite], + [MENU_FCREDIT, 'fcredit.title', isTurkishSite], + [MENU_FPAYMENT, 'fpayment.title', isTurkishSite], + [MENU_SPAYMENTS, 'spayments.title', isTurkishSite], [MENU_AFFILIATES_EARNINGS, 'affiliatesearnings.title'], - ['divider'], + ['divider', '', isTurkishSite], [MENU_PUBLIC_TRADES, 'publictrades.title'], - [MENU_PUBLIC_FUNDING, 'publicfunding.title'], + [MENU_PUBLIC_FUNDING, 'publicfunding.title', isTurkishSite], [MENU_TICKERS, 'tickers.title'], - [MENU_DERIVATIVES, 'derivatives.title'], + [MENU_DERIVATIVES, 'derivatives.title', isTurkishSite], ['divider', '', !showFrameworkMode], [MENU_ACCOUNT_BALANCE, 'accountbalance.title', !showFrameworkMode], [MENU_LOAN_REPORT, 'loanreport.title', !showFrameworkMode], @@ -122,10 +139,11 @@ class NavMenu extends PureComponent { render() { const { - className, + t, history, + className, + isTurkishSite, showMenuPopover, - t, } = this.props const target = getTarget(history.location.pathname, false) @@ -134,7 +152,7 @@ class NavMenu extends PureComponent { return ( {showMenuPopover && window.innerWidth > 390 && window.innerWidth <= 1024 && } - {this.sections.map((section, index) => { + {_map(this.getSections(isTurkishSite), (section, index) => { const [type, title, isSkipped] = section if (isSkipped) { @@ -146,7 +164,6 @@ class NavMenu extends PureComponent { return } - const types = _castArray(type) const mainType = types[0] @@ -155,12 +172,12 @@ class NavMenu extends PureComponent { return ( } + href={path} key={mainType} text={t(title)} - onClick={(e) => this.handleClick(e, mainType)} - href={path} + icon={} active={_includes(types, target)} + onClick={(e) => this.handleClick(e, mainType)} /> ) })} @@ -169,4 +186,4 @@ class NavMenu extends PureComponent { } } -export default withTranslation('translations')(NavMenu) +export default NavMenu diff --git a/src/ui/NavMenu/NavMenu.props.js b/src/ui/NavMenu/NavMenu.props.js deleted file mode 100644 index 1aaa6f67a..000000000 --- a/src/ui/NavMenu/NavMenu.props.js +++ /dev/null @@ -1,20 +0,0 @@ -import PropTypes from 'prop-types' - -export const propTypes = { - className: PropTypes.string, - history: PropTypes.shape({ - location: PropTypes.shape({ - pathname: PropTypes.string.isRequired, - search: PropTypes.string.isRequired, - }).isRequired, - push: PropTypes.func.isRequired, - }).isRequired, - showMenuPopover: PropTypes.bool, - t: PropTypes.func.isRequired, - windowWidth: PropTypes.number.isRequired, -} - -export const defaultProps = { - className: '', - showMenuPopover: true, -} diff --git a/src/ui/NavMenu/index.js b/src/ui/NavMenu/index.js index cadebf6d8..7d57b918c 100644 --- a/src/ui/NavMenu/index.js +++ b/src/ui/NavMenu/index.js @@ -1,3 +1 @@ -import NavMenu from './NavMenu.container' - -export default NavMenu +export { default } from './NavMenu.container'