From 40b984c8808f00be2eafd449adc96fc4fd1be64e Mon Sep 17 00:00:00 2001 From: alexstotsky Date: Mon, 15 Apr 2024 12:20:52 +0300 Subject: [PATCH 01/16] Add ttl selector keys and descriptions --- public/locales/en/translations.json | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/public/locales/en/translations.json b/public/locales/en/translations.json index c5e64dcf4..5f2f58634 100644 --- a/public/locales/en/translations.json +++ b/public/locales/en/translations.json @@ -53,6 +53,16 @@ "invalidToken": "Invalid token, please try again", "loginSessionExpired": "Your login session has expired, please try again" }, + "ttlSelect": { + "title": "Auth Token TTL", + "1day": "1 Day", + "2days": "2 Days", + "3days": "3 Days", + "4days": "4 Days", + "5days": "5 Days", + "6days": "6 Days", + "7days": "7 Days" + }, "apiKey": "API Key", "apiSecret": "API Secret", "accWithApiKey": "Add account with API key", From 1df7598bce7b0e43e380e365ba0868eb98e0532e Mon Sep 17 00:00:00 2001 From: alexstotsky Date: Tue, 16 Apr 2024 13:38:03 +0300 Subject: [PATCH 02/16] Add ttl selector to the preferences --- src/components/Preferences/Preferences.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/components/Preferences/Preferences.js b/src/components/Preferences/Preferences.js index 40d33a562..5ac2f809f 100644 --- a/src/components/Preferences/Preferences.js +++ b/src/components/Preferences/Preferences.js @@ -15,6 +15,7 @@ import ThemeSwitcher from 'ui/ThemeSwitcher' import TimezonePicker from 'ui/TimezonePicker' import TableScrollPref from 'ui/TableScrollPref' import ShowMilliseconds from 'ui/ShowMilliseconds' +import TokenTTLSelector from 'ui/TokenTTLSelector' import DateFormatSelector from 'ui/DateFormatSelector' import SyncAfterUpdatePref from 'ui/SyncAfterUpdatePref' import TimeRangePreservePref from 'ui/TimeRangePreservePref' @@ -77,6 +78,10 @@ const Preferences = ({
{t('preferences.dateformat')}
+
+
{t('auth.ttlSelect.title')}
+ +
{t('preferences.milliseconds')} From a5775a2a570d9d347d1c75947051e15ce3c2afac Mon Sep 17 00:00:00 2001 From: alexstotsky Date: Tue, 16 Apr 2024 13:38:34 +0300 Subject: [PATCH 03/16] [wip]Auth token ttl selector --- src/ui/TokenTTLSelector/TokenTTLSelector.js | 32 +++++++++++++++++++++ src/ui/TokenTTLSelector/index.js | 1 + 2 files changed, 33 insertions(+) create mode 100644 src/ui/TokenTTLSelector/TokenTTLSelector.js create mode 100644 src/ui/TokenTTLSelector/index.js diff --git a/src/ui/TokenTTLSelector/TokenTTLSelector.js b/src/ui/TokenTTLSelector/TokenTTLSelector.js new file mode 100644 index 000000000..01808d5df --- /dev/null +++ b/src/ui/TokenTTLSelector/TokenTTLSelector.js @@ -0,0 +1,32 @@ +import React, { useCallback } from 'react' +import { useTranslation } from 'react-i18next' +import { useDispatch, useSelector } from 'react-redux' + +import { setIsPdfRequired } from 'state/query/actions' +import { getIsPdfExportRequired } from 'state/query/selectors' + +import Select from 'ui/Select' + +const ExportTypeSelector = () => { + const { t } = useTranslation() + const dispatch = useDispatch() + const isPdfExportRequired = useSelector(getIsPdfExportRequired) + const items = [ + { value: false, label: t('download.exportAsCsv') }, + { value: true, label: t('download.exportAsPdf') }, + ] + + const handleChange = useCallback((value) => { + dispatch(setIsPdfRequired(value)) + }, [dispatch]) + + return ( + ) } From 7b5db15d93d22b5355a357c7b6b439cb2e7f2b73 Mon Sep 17 00:00:00 2001 From: alexstotsky Date: Tue, 16 Apr 2024 14:44:58 +0300 Subject: [PATCH 11/16] Add default token ttl constant for better reusability --- src/state/auth/constants.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/state/auth/constants.js b/src/state/auth/constants.js index 286423c07..32625b3f3 100644 --- a/src/state/auth/constants.js +++ b/src/state/auth/constants.js @@ -29,4 +29,5 @@ export default { WS_SIGN_IN: 'ws_signIn', LOGIN_2FA_OTP: 'otp', + DEFAULT_TOKEN_TTL: 86400, // 24h } From 71757d0860f75e11f33f201848e4b221d787f74d Mon Sep 17 00:00:00 2001 From: alexstotsky Date: Tue, 16 Apr 2024 14:47:22 +0300 Subject: [PATCH 12/16] Update auth initial state --- src/state/auth/reducer.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/state/auth/reducer.js b/src/state/auth/reducer.js index 72cf1a804..bc34874bf 100644 --- a/src/state/auth/reducer.js +++ b/src/state/auth/reducer.js @@ -57,7 +57,7 @@ const initialState = { userShouldReLogin: '', shouldNotSyncOnStartupAfterUpdate: false, isAuthBtnDisabled: false, - authTokenTTLSec: 86400, + authTokenTTLSec: types.DEFAULT_TOKEN_TTL, } export function authReducer(state = initialState, action) { From b508f296b211bc1e2213d230bb131f2f3b0bb3fc Mon Sep 17 00:00:00 2001 From: alexstotsky Date: Tue, 16 Apr 2024 14:47:55 +0300 Subject: [PATCH 13/16] Unify ttl selector default value handling --- src/state/auth/selectors.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/state/auth/selectors.js b/src/state/auth/selectors.js index a43c22cdf..9a638978c 100644 --- a/src/state/auth/selectors.js +++ b/src/state/auth/selectors.js @@ -3,6 +3,8 @@ import _first from 'lodash/first' import _filter from 'lodash/filter' import { isEqual } from '@bitfinex/lib-js-util-base' +import types from './constants' + const getAuth = state => state.auth export const getAuthStatus = state => getAuth(state).authStatus @@ -23,7 +25,7 @@ export const getIsSubAccsAvailable = state => _first( )?.isApiKeysAuth ?? true export const getLocalUsername = state => getAuth(state)?.localUsername ?? null export const getIsAuthBtnDisabled = state => getAuth(state)?.isAuthBtnDisabled ?? false -export const getAuthTokenTTL = state => getAuth(state)?.authTokenTTLSec ?? 86400 +export const getAuthTokenTTL = state => getAuth(state)?.authTokenTTLSec ?? types.DEFAULT_TOKEN_TTL export const getAuthData = state => { const { From 01e054f09b1e88bd8857b0268a715c071357fec1 Mon Sep 17 00:00:00 2001 From: alexstotsky Date: Tue, 16 Apr 2024 15:03:33 +0300 Subject: [PATCH 14/16] Fix selects active item state handling --- src/ui/Select/Select.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ui/Select/Select.js b/src/ui/Select/Select.js index 8803a8ce1..ea506586a 100644 --- a/src/ui/Select/Select.js +++ b/src/ui/Select/Select.js @@ -59,7 +59,7 @@ class Select extends PureComponent { } itemRenderer = (item, { modifiers, handleClick }) => { - const { active, disabled } = modifiers + const { disabled } = modifiers const { value } = this.props let options = {} @@ -82,7 +82,7 @@ class Select extends PureComponent { return ( Date: Wed, 17 Apr 2024 14:07:45 +0300 Subject: [PATCH 15/16] Implement handleUpdateTokenTTL saga --- src/state/auth/saga.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/state/auth/saga.js b/src/state/auth/saga.js index b98c4ea05..a04aad811 100644 --- a/src/state/auth/saga.js +++ b/src/state/auth/saga.js @@ -513,6 +513,24 @@ function* handleSyncAfterUpdate({ payload }) { } } +function* handleUpdateTokenTTL({ payload }) { + try { + const auth = yield select(selectAuth) + const params = { authTokenTTLSec: payload } + const { error } = yield makeFetchCall('updateUser', params, auth) + + if (error) { + yield put(updateErrorStatus({ + id: 'status.fail', + topic: 'auth.updateUser', + detail: error?.message ?? JSON.stringify(error), + })) + } + } catch (fail) { + yield put(updateAuthErrorStatus(fail)) + } +} + export default function* authSaga() { yield takeLatest(types.CHECK_AUTH, checkAuth) yield takeLatest(types.FETCH_USERS, fetchUsers) @@ -528,5 +546,6 @@ export default function* authSaga() { yield takeLatest(types.REMOVE_USER, removeUser) yield takeLatest(types.AUTH_EXPIRED, handleExpiredAuth) yield takeLatest(types.SET_SYNC_AFTER_UPDATE, handleSyncAfterUpdate) + yield takeLatest(types.SET_TOKEN_TTL, handleUpdateTokenTTL) yield fork(tokenRefreshSaga) } From 9a6e60b1f2808eeed6936d80762f11682a3a492c Mon Sep 17 00:00:00 2001 From: alexstotsky Date: Tue, 23 Apr 2024 14:29:29 +0300 Subject: [PATCH 16/16] Extract ttl selector items getter --- src/ui/TokenTTLSelector/TokenTTLSelector.js | 22 +++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/ui/TokenTTLSelector/TokenTTLSelector.js b/src/ui/TokenTTLSelector/TokenTTLSelector.js index a6a6d16d0..c80de4833 100644 --- a/src/ui/TokenTTLSelector/TokenTTLSelector.js +++ b/src/ui/TokenTTLSelector/TokenTTLSelector.js @@ -1,4 +1,4 @@ -import React, { useCallback } from 'react' +import React, { useCallback, useMemo } from 'react' import { useTranslation } from 'react-i18next' import { useDispatch, useSelector } from 'react-redux' @@ -7,19 +7,21 @@ import { getAuthTokenTTL } from 'state/auth/selectors' import Select from 'ui/Select' +const getItems = (t) => [ + { value: 86400, label: t('auth.ttlSelect.1day') }, + { value: 172800, label: t('auth.ttlSelect.2days') }, + { value: 259200, label: t('auth.ttlSelect.3days') }, + { value: 345600, label: t('auth.ttlSelect.4days') }, + { value: 432000, label: t('auth.ttlSelect.5days') }, + { value: 518400, label: t('auth.ttlSelect.6days') }, + { value: 604800, label: t('auth.ttlSelect.7days') }, +] + const ExportTypeSelector = () => { const { t } = useTranslation() const dispatch = useDispatch() const authTokenTTL = useSelector(getAuthTokenTTL) - const items = [ - { value: 86400, label: t('auth.ttlSelect.1day') }, - { value: 172800, label: t('auth.ttlSelect.2days') }, - { value: 259200, label: t('auth.ttlSelect.3days') }, - { value: 345600, label: t('auth.ttlSelect.4days') }, - { value: 432000, label: t('auth.ttlSelect.5days') }, - { value: 518400, label: t('auth.ttlSelect.6days') }, - { value: 604800, label: t('auth.ttlSelect.7days') }, - ] + const items = useMemo(() => getItems(t), [t]) const handleChange = useCallback((value) => { dispatch(setAuthTokenTTL(value))