From a762c918698f7d26d68158d3744cc90444c64e65 Mon Sep 17 00:00:00 2001 From: Riddhiagrawal001 <50551695+Riddhiagrawal001@users.noreply.github.com> Date: Thu, 13 Jun 2024 19:07:04 +0530 Subject: [PATCH] refactor: totp flow file rename (#822) --- src/context/AuthInfoProvider.res | 4 ++-- src/entryPoints/AuthModule/AuthProviderTypes.res | 2 +- src/entryPoints/AuthModule/AuthWrapper.res | 8 ++++---- .../{TotpAuth => TwoFaAuth/Totp}/OtpInput.res | 0 .../Totp}/TotpAcceptInviteScreen.res | 4 ++-- .../Totp}/TotpEmailVerifyScreen.res | 4 ++-- .../Totp}/TotpMerchantSelectScreen.res | 2 +- .../Totp}/TotpRecoveryCodes.res | 4 ++-- .../Totp}/TotpResetPassword.res | 6 +++--- .../{TotpAuth => TwoFaAuth/Totp}/TotpSetup.res | 14 +++++++------- .../Totp}/TotpUserInfoScreen.res | 2 +- .../TotpAuth.res => TwoFaAuth/TwoFaAuth.res} | 2 +- .../TwoFaAuthScreen.res} | 2 +- .../TwoFaDecisionScreen.res} | 2 +- .../{TotpAuth => TwoFaAuth}/TwoFaElements.res | 0 .../TotpTypes.res => TwoFaAuth/TwoFaTypes.res} | 4 ++-- .../TotpUtils.res => TwoFaAuth/TwoFaUtils.res} | 2 +- .../HSwitchProfile/ModifyTwoFaSettings.res | 2 +- src/screens/SwitchMerchant/SwitchMerchant.res | 2 +- 19 files changed, 33 insertions(+), 33 deletions(-) rename src/entryPoints/AuthModule/{TotpAuth => TwoFaAuth/Totp}/OtpInput.res (100%) rename src/entryPoints/AuthModule/{TotpAuth => TwoFaAuth/Totp}/TotpAcceptInviteScreen.res (97%) rename src/entryPoints/AuthModule/{TotpAuth => TwoFaAuth/Totp}/TotpEmailVerifyScreen.res (97%) rename src/entryPoints/AuthModule/{TotpAuth => TwoFaAuth/Totp}/TotpMerchantSelectScreen.res (98%) rename src/entryPoints/AuthModule/{TotpAuth => TwoFaAuth/Totp}/TotpRecoveryCodes.res (96%) rename src/entryPoints/AuthModule/{TotpAuth => TwoFaAuth/Totp}/TotpResetPassword.res (97%) rename src/entryPoints/AuthModule/{TotpAuth => TwoFaAuth/Totp}/TotpSetup.res (97%) rename src/entryPoints/AuthModule/{TotpAuth => TwoFaAuth/Totp}/TotpUserInfoScreen.res (95%) rename src/entryPoints/AuthModule/{TotpAuth/TotpAuth.res => TwoFaAuth/TwoFaAuth.res} (99%) rename src/entryPoints/AuthModule/{TotpAuth/TotpAuthScreen.res => TwoFaAuth/TwoFaAuthScreen.res} (98%) rename src/entryPoints/AuthModule/{TotpAuth/TotpDecisionScreen.res => TwoFaAuth/TwoFaDecisionScreen.res} (88%) rename src/entryPoints/AuthModule/{TotpAuth => TwoFaAuth}/TwoFaElements.res (100%) rename src/entryPoints/AuthModule/{TotpAuth/TotpTypes.res => TwoFaAuth/TwoFaTypes.res} (91%) rename src/entryPoints/AuthModule/{TotpAuth/TotpUtils.res => TwoFaAuth/TwoFaUtils.res} (99%) diff --git a/src/context/AuthInfoProvider.res b/src/context/AuthInfoProvider.res index 5fbdda16d..8515468f5 100644 --- a/src/context/AuthInfoProvider.res +++ b/src/context/AuthInfoProvider.res @@ -42,7 +42,7 @@ let make = (~children) => { | TotpAuth(totpInfo) => if !(totpInfo.token->LogicUtils.isEmptyString) { setAuth(_ => newAuthStatus) - TotpUtils.setTotpAuthResToStorage(totpInfo) + TwoFaUtils.setTotpAuthResToStorage(totpInfo) } else { setAuth(_ => LoggedOut) CommonAuthUtils.clearLocalStorage() @@ -51,7 +51,7 @@ let make = (~children) => { | PreLogin(preLoginInfo) => if !(preLoginInfo.token->LogicUtils.isEmptyString) { setAuth(_ => newAuthStatus) - TotpUtils.setTotpAuthResToStorage(preLoginInfo) + TwoFaUtils.setTotpAuthResToStorage(preLoginInfo) } else { setAuth(_ => LoggedOut) CommonAuthUtils.clearLocalStorage() diff --git a/src/entryPoints/AuthModule/AuthProviderTypes.res b/src/entryPoints/AuthModule/AuthProviderTypes.res index 427c5835b..a0127ea57 100644 --- a/src/entryPoints/AuthModule/AuthProviderTypes.res +++ b/src/entryPoints/AuthModule/AuthProviderTypes.res @@ -3,6 +3,6 @@ type preLoginType = { token_type: string, email_token: option, } -type authType = BasicAuth(BasicAuthTypes.basicAuthInfo) | TotpAuth(TotpTypes.totpAuthInfo) +type authType = BasicAuth(BasicAuthTypes.basicAuthInfo) | TotpAuth(TwoFaTypes.twoFaAuthInfo) type authStatus = LoggedOut | PreLogin(preLoginType) | LoggedIn(authType) | CheckingAuthStatus diff --git a/src/entryPoints/AuthModule/AuthWrapper.res b/src/entryPoints/AuthModule/AuthWrapper.res index 657ab67eb..dd7549a18 100644 --- a/src/entryPoints/AuthModule/AuthWrapper.res +++ b/src/entryPoints/AuthModule/AuthWrapper.res @@ -50,7 +50,7 @@ let make = (~children) => { let {authStatus, setAuthStatus} = React.useContext(AuthInfoProvider.authStatusContext) let authLogic = () => { - open TotpUtils + open TwoFaUtils open LogicUtils let preLoginInfo = getTotpPreLoginInfoFromStorage() let loggedInInfo = getTotpAuthInfoFromStrorage() @@ -77,7 +77,7 @@ let make = (~children) => { switch tokenFromUrl { | Some(token) => { let response = await updateDetails(url, token->generateBodyForEmailRedirection, Post, ()) - setAuthStatus(PreLogin(TotpUtils.getPreLoginInfo(response, ~email_token=Some(token)))) + setAuthStatus(PreLogin(TwoFaUtils.getPreLoginInfo(response, ~email_token=Some(token)))) } | None => setAuthStatus(LoggedOut) } @@ -105,9 +105,9 @@ let make = (~children) => { {switch authStatus { | LoggedOut => - + - | PreLogin(_) => + | PreLogin(_) => | LoggedIn(_token) => children | CheckingAuthStatus => }} diff --git a/src/entryPoints/AuthModule/TotpAuth/OtpInput.res b/src/entryPoints/AuthModule/TwoFaAuth/Totp/OtpInput.res similarity index 100% rename from src/entryPoints/AuthModule/TotpAuth/OtpInput.res rename to src/entryPoints/AuthModule/TwoFaAuth/Totp/OtpInput.res diff --git a/src/entryPoints/AuthModule/TotpAuth/TotpAcceptInviteScreen.res b/src/entryPoints/AuthModule/TwoFaAuth/Totp/TotpAcceptInviteScreen.res similarity index 97% rename from src/entryPoints/AuthModule/TotpAuth/TotpAcceptInviteScreen.res rename to src/entryPoints/AuthModule/TwoFaAuth/Totp/TotpAcceptInviteScreen.res index 3193ee423..b2597df6e 100644 --- a/src/entryPoints/AuthModule/TotpAuth/TotpAcceptInviteScreen.res +++ b/src/entryPoints/AuthModule/TwoFaAuth/Totp/TotpAcceptInviteScreen.res @@ -10,7 +10,7 @@ let make = () => { let acceptInviteFromEmailWithSPT = async body => { try { - open TotpUtils + open TwoFaUtils let url = getURL( ~entityName=USERS, @@ -31,7 +31,7 @@ let make = () => { React.useEffect0(() => { open CommonAuthUtils - open TotpUtils + open TwoFaUtils open HSwitchGlobalVars RescriptReactRouter.replace(appendDashboardPath(~url="/accept_invite_from_email")) let emailToken = authStatus->getEmailToken diff --git a/src/entryPoints/AuthModule/TotpAuth/TotpEmailVerifyScreen.res b/src/entryPoints/AuthModule/TwoFaAuth/Totp/TotpEmailVerifyScreen.res similarity index 97% rename from src/entryPoints/AuthModule/TotpAuth/TotpEmailVerifyScreen.res rename to src/entryPoints/AuthModule/TwoFaAuth/Totp/TotpEmailVerifyScreen.res index 9c7b38848..8c00407a2 100644 --- a/src/entryPoints/AuthModule/TotpAuth/TotpEmailVerifyScreen.res +++ b/src/entryPoints/AuthModule/TwoFaAuth/Totp/TotpEmailVerifyScreen.res @@ -11,7 +11,7 @@ let make = () => { let verifyEmailWithSPT = async body => { try { - open TotpUtils + open TwoFaUtils let url = getURL( ~entityName=USERS, ~methodType=Post, @@ -31,7 +31,7 @@ let make = () => { React.useEffect0(() => { open CommonAuthUtils - open TotpUtils + open TwoFaUtils open HSwitchGlobalVars RescriptReactRouter.replace(appendDashboardPath(~url="/accept_invite_from_email")) diff --git a/src/entryPoints/AuthModule/TotpAuth/TotpMerchantSelectScreen.res b/src/entryPoints/AuthModule/TwoFaAuth/Totp/TotpMerchantSelectScreen.res similarity index 98% rename from src/entryPoints/AuthModule/TotpAuth/TotpMerchantSelectScreen.res rename to src/entryPoints/AuthModule/TwoFaAuth/Totp/TotpMerchantSelectScreen.res index 467d8a476..4f2bb0f1a 100644 --- a/src/entryPoints/AuthModule/TotpAuth/TotpMerchantSelectScreen.res +++ b/src/entryPoints/AuthModule/TwoFaAuth/Totp/TotpMerchantSelectScreen.res @@ -24,7 +24,7 @@ let make = () => { }) let onClickLoginToDashboard = async () => { - open TotpUtils + open TwoFaUtils try { let url = getURL(~entityName=USERS, ~userType=#ACCEPT_INVITE_TOKEN_ONLY, ~methodType=Post, ()) diff --git a/src/entryPoints/AuthModule/TotpAuth/TotpRecoveryCodes.res b/src/entryPoints/AuthModule/TwoFaAuth/Totp/TotpRecoveryCodes.res similarity index 96% rename from src/entryPoints/AuthModule/TotpAuth/TotpRecoveryCodes.res rename to src/entryPoints/AuthModule/TwoFaAuth/Totp/TotpRecoveryCodes.res index 577c067f6..3c9a150b0 100644 --- a/src/entryPoints/AuthModule/TotpAuth/TotpRecoveryCodes.res +++ b/src/entryPoints/AuthModule/TwoFaAuth/Totp/TotpRecoveryCodes.res @@ -23,7 +23,7 @@ let make = (~setTwoFaPageState, ~onClickDownload, ~setShowNewQR) => { let errorCode = err->safeParse->getDictFromJsonObject->getString("code", "") if errorCode->CommonAuthUtils.errorSubCodeMapper === UR_38 { - setTwoFaPageState(_ => TotpTypes.TOTP_SHOW_QR) + setTwoFaPageState(_ => TwoFaTypes.TOTP_SHOW_QR) setShowNewQR(prev => !prev) } else { showToast(~message="Something went wrong", ~toastType=ToastError, ()) @@ -76,7 +76,7 @@ let make = (~setTwoFaPageState, ~onClickDownload, ~setShowNewQR) => { buttonType={Primary} buttonSize={Small} onClick={_ => { - TotpUtils.downloadRecoveryCodes(~recoveryCodes) + TwoFaUtils.downloadRecoveryCodes(~recoveryCodes) onClickDownload(~skip_2fa=false)->ignore }} /> diff --git a/src/entryPoints/AuthModule/TotpAuth/TotpResetPassword.res b/src/entryPoints/AuthModule/TwoFaAuth/Totp/TotpResetPassword.res similarity index 97% rename from src/entryPoints/AuthModule/TotpAuth/TotpResetPassword.res rename to src/entryPoints/AuthModule/TwoFaAuth/Totp/TotpResetPassword.res index c502f1f07..7d1a7d5af 100644 --- a/src/entryPoints/AuthModule/TotpAuth/TotpResetPassword.res +++ b/src/entryPoints/AuthModule/TwoFaAuth/Totp/TotpResetPassword.res @@ -57,8 +57,8 @@ let make = (~flowType) => { } let confirmButtonAction = async password => { - open TotpTypes - open TotpUtils + open TwoFaTypes + open TwoFaUtils try { switch flowType { | FORCE_SET_PASSWORD => await rotatePassword(password) @@ -131,7 +131,7 @@ let make = (~flowType) => { key="auth" initialValues validate={values => - TotpUtils.validateTotpForm(values, ["create_password", "comfirm_password"])} + TwoFaUtils.validateTotpForm(values, ["create_password", "comfirm_password"])} onSubmit>

diff --git a/src/entryPoints/AuthModule/TotpAuth/TotpSetup.res b/src/entryPoints/AuthModule/TwoFaAuth/Totp/TotpSetup.res similarity index 97% rename from src/entryPoints/AuthModule/TotpAuth/TotpSetup.res rename to src/entryPoints/AuthModule/TwoFaAuth/Totp/TotpSetup.res index 6444d07c0..5ff7f4ed4 100644 --- a/src/entryPoints/AuthModule/TotpAuth/TotpSetup.res +++ b/src/entryPoints/AuthModule/TwoFaAuth/Totp/TotpSetup.res @@ -66,7 +66,7 @@ module EnterAccessCode = { {"Didn't get a code? "->React.string} setTwoFaPageState(_ => TotpTypes.TOTP_SHOW_QR)}> + onClick={_ => setTwoFaPageState(_ => TwoFaTypes.TOTP_SHOW_QR)}> {"Use totp instead"->React.string}

@@ -106,7 +106,7 @@ module ConfigureTotpScreen = { ~setTwoFaPageState, ~terminateTwoFactorAuth, ) => { - open TotpTypes + open TwoFaTypes let verifyTotpLogic = TotpHooks.useVerifyTotp() @@ -128,7 +128,7 @@ module ConfigureTotpScreen = { if twoFaStatus === TWO_FA_SET { terminateTwoFactorAuth(~skip_2fa=false)->ignore } else { - setTwoFaPageState(_ => TotpTypes.TOTP_SHOW_RC) + setTwoFaPageState(_ => TwoFaTypes.TOTP_SHOW_RC) } } else { showToast(~message="OTP field cannot be empty!", ~toastType=ToastError, ()) @@ -226,7 +226,7 @@ module ConfigureTotpScreen = { @react.component let make = () => { open HSwitchUtils - open TotpTypes + open TwoFaTypes let getURL = APIUtils.useGetURL() let showToast = ToastState.useShowToast() @@ -236,7 +236,7 @@ let make = () => { let (isQrVisible, setIsQrVisible) = React.useState(_ => false) let (totpUrl, setTotpUrl) = React.useState(_ => "") let (twoFaStatus, setTwoFaStatus) = React.useState(_ => TWO_FA_NOT_SET) - let (twoFaPageState, setTwoFaPageState) = React.useState(_ => TotpTypes.TOTP_SHOW_QR) + let (twoFaPageState, setTwoFaPageState) = React.useState(_ => TOTP_SHOW_QR) let (showNewQR, setShowNewQR) = React.useState(_ => false) let delayTimer = () => { @@ -256,7 +256,7 @@ let make = () => { let terminateTwoFactorAuth = async (~skip_2fa) => { open LogicUtils try { - open TotpUtils + open TwoFaUtils let url = `${getURL( ~entityName=USERS, @@ -276,7 +276,7 @@ let make = () => { errorCode->CommonAuthUtils.errorSubCodeMapper === UR_40 || errorCode->CommonAuthUtils.errorSubCodeMapper === UR_41 ) { - setTwoFaPageState(_ => TotpTypes.TOTP_SHOW_QR) + setTwoFaPageState(_ => TOTP_SHOW_QR) showToast(~message="Failed to complete 2fa!", ~toastType=ToastError, ()) setShowNewQR(prev => !prev) } else { diff --git a/src/entryPoints/AuthModule/TotpAuth/TotpUserInfoScreen.res b/src/entryPoints/AuthModule/TwoFaAuth/Totp/TotpUserInfoScreen.res similarity index 95% rename from src/entryPoints/AuthModule/TotpAuth/TotpUserInfoScreen.res rename to src/entryPoints/AuthModule/TwoFaAuth/Totp/TotpUserInfoScreen.res index 3770318eb..65634008f 100644 --- a/src/entryPoints/AuthModule/TotpAuth/TotpUserInfoScreen.res +++ b/src/entryPoints/AuthModule/TwoFaAuth/Totp/TotpUserInfoScreen.res @@ -20,7 +20,7 @@ let make = () => { let response = await fetchDetails(url) let dict = response->getDictFromJsonObject dict->setOptionString("token", token) - let info = TotpUtils.getTotpAuthInfo(dict->JSON.Encode.object) + let info = TwoFaUtils.getTotpAuthInfo(dict->JSON.Encode.object) setAuthStatus(LoggedIn(TotpAuth(info))) setIsSidebarDetails("isPinned", false->JSON.Encode.bool) setScreenState(_ => PageLoaderWrapper.Success) diff --git a/src/entryPoints/AuthModule/TotpAuth/TotpAuth.res b/src/entryPoints/AuthModule/TwoFaAuth/TwoFaAuth.res similarity index 99% rename from src/entryPoints/AuthModule/TotpAuth/TotpAuth.res rename to src/entryPoints/AuthModule/TwoFaAuth/TwoFaAuth.res index 984aac3a4..7ad939d23 100644 --- a/src/entryPoints/AuthModule/TotpAuth/TotpAuth.res +++ b/src/entryPoints/AuthModule/TwoFaAuth/TwoFaAuth.res @@ -4,7 +4,7 @@ let make = (~setAuthStatus, ~authType, ~setAuthType) => { open CommonAuthForm open HSwitchGlobalVars open LogicUtils - open TotpUtils + open TwoFaUtils open AuthProviderTypes let getURL = useGetURL() let url = RescriptReactRouter.useUrl() diff --git a/src/entryPoints/AuthModule/TotpAuth/TotpAuthScreen.res b/src/entryPoints/AuthModule/TwoFaAuth/TwoFaAuthScreen.res similarity index 98% rename from src/entryPoints/AuthModule/TotpAuth/TotpAuthScreen.res rename to src/entryPoints/AuthModule/TwoFaAuth/TwoFaAuthScreen.res index 42b646dba..7f9304290 100644 --- a/src/entryPoints/AuthModule/TotpAuth/TotpAuthScreen.res +++ b/src/entryPoints/AuthModule/TwoFaAuth/TwoFaAuthScreen.res @@ -73,5 +73,5 @@ let make = (~setAuthStatus) => { None }, [authType]) - + } diff --git a/src/entryPoints/AuthModule/TotpAuth/TotpDecisionScreen.res b/src/entryPoints/AuthModule/TwoFaAuth/TwoFaDecisionScreen.res similarity index 88% rename from src/entryPoints/AuthModule/TotpAuth/TotpDecisionScreen.res rename to src/entryPoints/AuthModule/TwoFaAuth/TwoFaDecisionScreen.res index a5c45ffef..a984c82a8 100644 --- a/src/entryPoints/AuthModule/TotpAuth/TotpDecisionScreen.res +++ b/src/entryPoints/AuthModule/TwoFaAuth/TwoFaDecisionScreen.res @@ -3,7 +3,7 @@ let make = () => { let {authStatus, setAuthStatus} = React.useContext(AuthInfoProvider.authStatusContext) let flowType = switch authStatus { - | PreLogin(info) => info.token_type->TotpUtils.flowTypeStrToVariantMapperForNewFlow + | PreLogin(info) => info.token_type->TwoFaUtils.flowTypeStrToVariantMapperForNewFlow | _ => ERROR } diff --git a/src/entryPoints/AuthModule/TotpAuth/TwoFaElements.res b/src/entryPoints/AuthModule/TwoFaAuth/TwoFaElements.res similarity index 100% rename from src/entryPoints/AuthModule/TotpAuth/TwoFaElements.res rename to src/entryPoints/AuthModule/TwoFaAuth/TwoFaElements.res diff --git a/src/entryPoints/AuthModule/TotpAuth/TotpTypes.res b/src/entryPoints/AuthModule/TwoFaAuth/TwoFaTypes.res similarity index 91% rename from src/entryPoints/AuthModule/TotpAuth/TotpTypes.res rename to src/entryPoints/AuthModule/TwoFaAuth/TwoFaTypes.res index a09adec0a..9831d9789 100644 --- a/src/entryPoints/AuthModule/TotpAuth/TotpTypes.res +++ b/src/entryPoints/AuthModule/TwoFaAuth/TwoFaTypes.res @@ -1,4 +1,4 @@ -type totpFlowType = +type twoFaFlowType = | MERCHANT_SELECT | TOTP | FORCE_SET_PASSWORD @@ -9,7 +9,7 @@ type totpFlowType = | USER_INFO | ERROR -type totpAuthInfo = { +type twoFaAuthInfo = { token: string, merchant_id: string, name: string, diff --git a/src/entryPoints/AuthModule/TotpAuth/TotpUtils.res b/src/entryPoints/AuthModule/TwoFaAuth/TwoFaUtils.res similarity index 99% rename from src/entryPoints/AuthModule/TotpAuth/TotpUtils.res rename to src/entryPoints/AuthModule/TwoFaAuth/TwoFaUtils.res index a6d593204..7c12211d2 100644 --- a/src/entryPoints/AuthModule/TotpAuth/TotpUtils.res +++ b/src/entryPoints/AuthModule/TwoFaAuth/TwoFaUtils.res @@ -1,4 +1,4 @@ -open TotpTypes +open TwoFaTypes let flowTypeStrToVariantMapper = val => { switch val { diff --git a/src/screens/Settings/HSwitchProfile/ModifyTwoFaSettings.res b/src/screens/Settings/HSwitchProfile/ModifyTwoFaSettings.res index cd0a2a5ca..36e876d2e 100644 --- a/src/screens/Settings/HSwitchProfile/ModifyTwoFaSettings.res +++ b/src/screens/Settings/HSwitchProfile/ModifyTwoFaSettings.res @@ -475,7 +475,7 @@ module RegenerateRecoveryCodes = { buttonType={Primary} buttonSize={Small} onClick={_ => { - TotpUtils.downloadRecoveryCodes(~recoveryCodes) + TwoFaUtils.downloadRecoveryCodes(~recoveryCodes) showToast( ~message="Successfully regenerated new recovery codes !", ~toastType=ToastSuccess, diff --git a/src/screens/SwitchMerchant/SwitchMerchant.res b/src/screens/SwitchMerchant/SwitchMerchant.res index 886b52d3e..a8ef5cad8 100644 --- a/src/screens/SwitchMerchant/SwitchMerchant.res +++ b/src/screens/SwitchMerchant/SwitchMerchant.res @@ -299,7 +299,7 @@ let make = (~userRole, ~isAddMerchantEnabled=false) => { if featureFlagDetails.totp { let responseDict = res->getDictFromJsonObject setAuthStatus( - LoggedIn(TotpAuth(TotpUtils.getTotpAuthInfo(responseDict->JSON.Encode.object))), + LoggedIn(TotpAuth(TwoFaUtils.getTotpAuthInfo(responseDict->JSON.Encode.object))), ) } else { setAuthStatus(LoggedIn(BasicAuth(res->BasicAuthUtils.getBasicAuthInfo)))