From fba19122ea35fa148472e7bd6a3c0377fe5b9d1a Mon Sep 17 00:00:00 2001 From: alexstotsky Date: Wed, 21 Feb 2024 11:28:27 +0200 Subject: [PATCH 1/6] Update auth constants --- 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 503ff15b0..b5bfb5e4a 100644 --- a/src/state/auth/constants.js +++ b/src/state/auth/constants.js @@ -24,6 +24,7 @@ export default { LOGOUT: 'BITFINEX/AUTH/LOGOUT', DELETE_ACCOUNT: 'BITFINEX/AUTH/ACCOUNT/DELETE', SET_SYNC_AFTER_UPDATE: 'BITFINEX/SYNC/SYNC_AFTER_UPDATE/SET', + DISABLE_AUTH_BUTTON: 'BITFINEX/AUTH/BUTTON/DISABLE', WS_SIGN_IN: 'ws_signIn', LOGIN_2FA_OTP: 'otp', From cfef6428ac0d03d7eec0d643ab9387deef87bbb4 Mon Sep 17 00:00:00 2001 From: alexstotsky Date: Wed, 21 Feb 2024 11:29:45 +0200 Subject: [PATCH 2/6] Add disableAuthBtn action --- src/state/auth/actions.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/state/auth/actions.js b/src/state/auth/actions.js index 83b13925f..5b4ab5116 100644 --- a/src/state/auth/actions.js +++ b/src/state/auth/actions.js @@ -217,6 +217,13 @@ export function syncAfterUpdate(payload) { } } +export function disableAuthBtn(payload) { + return { + type: types.DISABLE_AUTH_BUTTON, + payload, + } +} + export default { checkAuth, addUser, @@ -243,4 +250,5 @@ export default { signInOtp, deleteAccount, syncAfterUpdate, + disableAuthBtn, } From 96e6753d7409c9dd6db1e55f104a38da9279ee23 Mon Sep 17 00:00:00 2001 From: alexstotsky Date: Wed, 21 Feb 2024 11:32:38 +0200 Subject: [PATCH 3/6] Extend auth init state and reducers --- src/state/auth/reducer.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/state/auth/reducer.js b/src/state/auth/reducer.js index 59aafd919..ebc3dbfdd 100644 --- a/src/state/auth/reducer.js +++ b/src/state/auth/reducer.js @@ -56,6 +56,7 @@ const initialState = { loginToken: '', userShouldReLogin: '', shouldNotSyncOnStartupAfterUpdate: false, + isAuthBtnDisabled: false, } export function authReducer(state = initialState, action) { @@ -148,6 +149,11 @@ export function authReducer(state = initialState, action) { ...state, shouldNotSyncOnStartupAfterUpdate: payload, } + case types.DISABLE_AUTH_BUTTON: + return { + ...state, + isAuthBtnDisabled: payload, + } case types.HIDE_AUTH: return { ...state, From 99a3600d18e2b02b4ef1f6e1edb7210967127213 Mon Sep 17 00:00:00 2001 From: alexstotsky Date: Wed, 21 Feb 2024 11:34:32 +0200 Subject: [PATCH 4/6] Implement getIsAuthBtnDisabled selector --- src/state/auth/selectors.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/state/auth/selectors.js b/src/state/auth/selectors.js index 7b0428e87..97a5f5369 100644 --- a/src/state/auth/selectors.js +++ b/src/state/auth/selectors.js @@ -22,6 +22,7 @@ export const getIsSubAccsAvailable = state => _first( _filter(getUsers(state), user => isEqual(user?.email, getEmail(state))), )?.isApiKeysAuth ?? true export const getLocalUsername = state => getAuth(state)?.localUsername ?? null +export const getIsAuthBtnDisabled = state => getAuth(state)?.isAuthBtnDisabled ?? false export const getAuthData = state => { const { @@ -108,4 +109,5 @@ export default { getIsSubAccsAvailable, getLocalUsername, getShouldNotSyncOnStartupAfterUpdate, + getIsAuthBtnDisabled, } From d6bb912455e1c588d9ab9fc10b32b78fe0374386 Mon Sep 17 00:00:00 2001 From: alexstotsky Date: Wed, 21 Feb 2024 11:48:39 +0200 Subject: [PATCH 5/6] Adjust signUpOtp saga to handle auth btn status --- src/state/auth/saga.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/state/auth/saga.js b/src/state/auth/saga.js index 45d61a675..ba5f3dd34 100644 --- a/src/state/auth/saga.js +++ b/src/state/auth/saga.js @@ -177,6 +177,7 @@ function* signUpEmail({ payload }) { function* signUpOtp({ payload }) { try { + yield put(actions.disableAuthBtn(true)) const { otp, password, isNotProtected } = payload const loginToken = yield select(getLoginToken) const params = { @@ -193,16 +194,19 @@ function* signUpOtp({ payload }) { password, isNotProtected, } + yield put(actions.disableAuthBtn(false)) yield put(actions.signUp(authParams)) } if (error) { + yield put(actions.disableAuthBtn(false)) yield put(updateErrorStatus({ id: 'auth.2FA.invalidToken', })) } } catch (fail) { yield put(updateAuthErrorStatus(fail)) + yield put(actions.disableAuthBtn(false)) } } From acb11682b601d79cf335c3e6c6772bbf484b30d1 Mon Sep 17 00:00:00 2001 From: alexstotsky Date: Wed, 21 Feb 2024 11:52:00 +0200 Subject: [PATCH 6/6] Extend auth button disabling cases --- src/components/Auth/LoginOtp/LoginOtp.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/components/Auth/LoginOtp/LoginOtp.js b/src/components/Auth/LoginOtp/LoginOtp.js index a9aed0b8f..82ffc5657 100644 --- a/src/components/Auth/LoginOtp/LoginOtp.js +++ b/src/components/Auth/LoginOtp/LoginOtp.js @@ -1,10 +1,12 @@ import React, { memo, useEffect } from 'react' +import { useSelector } from 'react-redux' import PropTypes from 'prop-types' import { useTranslation } from 'react-i18next' import { Button, Intent } from '@blueprintjs/core' import { isEmpty } from '@bitfinex/lib-js-util-base' import useKeyDown from 'hooks/useKeyDown' +import { getIsAuthBtnDisabled } from 'state/auth/selectors' import InputKey from '../InputKey' @@ -15,9 +17,12 @@ export const LoginOtp = ({ handleOneTimePassword, }) => { const { t } = useTranslation() + const isAuthBtnDisabled = useSelector(getIsAuthBtnDisabled) useKeyDown(() => { - handleOneTimePassword() + if (!isAuthBtnDisabled) { + handleOneTimePassword() + } }, ['Enter']) useEffect(() => { @@ -48,9 +53,9 @@ export const LoginOtp = ({