From da8c03a89735e0587ecd97dca00b63d245d9050b Mon Sep 17 00:00:00 2001 From: ruijialin Date: Wed, 18 Dec 2024 14:28:14 -0500 Subject: [PATCH] address pr comments --- .../totp}/AuthenticatorSetup.tsx | 0 .../totp}/CopyCode.tsx | 0 .../components => components/totp}/Loader.tsx | 0 .../totp}/ScanQrCode.tsx | 0 .../totp}/VerifyCode.tsx | 0 .../app/new/contexts/SignupProvider.tsx | 24 ----------------- .../(authenticator)/settingsTotp/_layout.tsx | 16 ------------ .../routes/(authenticator)/totp/_layout.tsx | 16 ------------ .../routes/(authenticator)/totp/copyCode.tsx | 20 -------------- .../(authenticator)/totp/scanQrCode.tsx | 16 ------------ .../app/new/routes/(totp)/_layout.tsx | 13 ++++++++++ .../totp => (totp)}/authenticatorSetup.tsx | 25 ++++++++++-------- .../app/new/routes/(totp)/copyCode.tsx | 26 +++++++++++++++++++ .../app/new/routes/(totp)/scanQrCode.tsx | 25 ++++++++++++++++++ .../totp => (totp)}/verifyCode.tsx | 2 +- .../core-mobile/app/new/routes/_layout.tsx | 1 + .../app/new/routes/addRecoveryMethods.tsx | 2 +- 17 files changed, 81 insertions(+), 105 deletions(-) rename packages/core-mobile/app/new/{routes/(authenticator)/components => components/totp}/AuthenticatorSetup.tsx (100%) rename packages/core-mobile/app/new/{routes/(authenticator)/components => components/totp}/CopyCode.tsx (100%) rename packages/core-mobile/app/new/{routes/(authenticator)/components => components/totp}/Loader.tsx (100%) rename packages/core-mobile/app/new/{routes/(authenticator)/components => components/totp}/ScanQrCode.tsx (100%) rename packages/core-mobile/app/new/{routes/(authenticator)/components => components/totp}/VerifyCode.tsx (100%) delete mode 100644 packages/core-mobile/app/new/routes/(authenticator)/settingsTotp/_layout.tsx delete mode 100644 packages/core-mobile/app/new/routes/(authenticator)/totp/_layout.tsx delete mode 100644 packages/core-mobile/app/new/routes/(authenticator)/totp/copyCode.tsx delete mode 100644 packages/core-mobile/app/new/routes/(authenticator)/totp/scanQrCode.tsx create mode 100644 packages/core-mobile/app/new/routes/(totp)/_layout.tsx rename packages/core-mobile/app/new/routes/{(authenticator)/totp => (totp)}/authenticatorSetup.tsx (73%) create mode 100644 packages/core-mobile/app/new/routes/(totp)/copyCode.tsx create mode 100644 packages/core-mobile/app/new/routes/(totp)/scanQrCode.tsx rename packages/core-mobile/app/new/routes/{(authenticator)/totp => (totp)}/verifyCode.tsx (79%) diff --git a/packages/core-mobile/app/new/routes/(authenticator)/components/AuthenticatorSetup.tsx b/packages/core-mobile/app/new/components/totp/AuthenticatorSetup.tsx similarity index 100% rename from packages/core-mobile/app/new/routes/(authenticator)/components/AuthenticatorSetup.tsx rename to packages/core-mobile/app/new/components/totp/AuthenticatorSetup.tsx diff --git a/packages/core-mobile/app/new/routes/(authenticator)/components/CopyCode.tsx b/packages/core-mobile/app/new/components/totp/CopyCode.tsx similarity index 100% rename from packages/core-mobile/app/new/routes/(authenticator)/components/CopyCode.tsx rename to packages/core-mobile/app/new/components/totp/CopyCode.tsx diff --git a/packages/core-mobile/app/new/routes/(authenticator)/components/Loader.tsx b/packages/core-mobile/app/new/components/totp/Loader.tsx similarity index 100% rename from packages/core-mobile/app/new/routes/(authenticator)/components/Loader.tsx rename to packages/core-mobile/app/new/components/totp/Loader.tsx diff --git a/packages/core-mobile/app/new/routes/(authenticator)/components/ScanQrCode.tsx b/packages/core-mobile/app/new/components/totp/ScanQrCode.tsx similarity index 100% rename from packages/core-mobile/app/new/routes/(authenticator)/components/ScanQrCode.tsx rename to packages/core-mobile/app/new/components/totp/ScanQrCode.tsx diff --git a/packages/core-mobile/app/new/routes/(authenticator)/components/VerifyCode.tsx b/packages/core-mobile/app/new/components/totp/VerifyCode.tsx similarity index 100% rename from packages/core-mobile/app/new/routes/(authenticator)/components/VerifyCode.tsx rename to packages/core-mobile/app/new/components/totp/VerifyCode.tsx diff --git a/packages/core-mobile/app/new/contexts/SignupProvider.tsx b/packages/core-mobile/app/new/contexts/SignupProvider.tsx index bda1017a8..88ca464ad 100644 --- a/packages/core-mobile/app/new/contexts/SignupProvider.tsx +++ b/packages/core-mobile/app/new/contexts/SignupProvider.tsx @@ -20,13 +20,9 @@ import { OidcAuth } from 'new/types' export interface SignupContextState { handleAccountVerified: () => Promise - handleBack: () => void handleCopyCode: () => void onVerifyCode: (code: string) => Promise> onVerifySuccess: () => void - goToEnterCodeManually: () => void - goToScanQrCode: () => void - goToVerifyCode: () => void totpKey?: string totpChallenge?: TotpChallenge setTotpChallenge: Dispatch> @@ -60,22 +56,6 @@ export const SignupProvider = ({ totpKey && copyToClipboard(totpKey, 'Code copied') }, [totpKey]) - const handleBack = useCallback((): void => { - router.canGoBack() && router.back() - }, [router]) - - const goToEnterCodeManually = (): void => { - router.navigate('./copyCode') - } - - const goToScanQrCode = (): void => { - router.navigate('./scanQrCode') - } - - const goToVerifyCode = (): void => { - router.push('./verifyCode') - } - const onVerifyCode = useCallback( async (code: string): Promise> => { await totpChallenge?.answer(code) @@ -116,13 +96,9 @@ export const SignupProvider = ({ const state: SignupContextState = { handleAccountVerified, - handleBack, handleCopyCode, onVerifyCode, onVerifySuccess, - goToEnterCodeManually, - goToScanQrCode, - goToVerifyCode, totpKey, totpChallenge, setTotpChallenge, diff --git a/packages/core-mobile/app/new/routes/(authenticator)/settingsTotp/_layout.tsx b/packages/core-mobile/app/new/routes/(authenticator)/settingsTotp/_layout.tsx deleted file mode 100644 index 35911f079..000000000 --- a/packages/core-mobile/app/new/routes/(authenticator)/settingsTotp/_layout.tsx +++ /dev/null @@ -1,16 +0,0 @@ -// import React from 'react' -// import { Stack } from 'new/components/navigation/Stack' -// import { SettingsTotpProvider } from 'new/contexts/SettingsTotpProvider' - -// export default function SettingsTotpLayout(): JSX.Element { -// return ( -// -// -// -// -// -// -// -// -// ) -// } diff --git a/packages/core-mobile/app/new/routes/(authenticator)/totp/_layout.tsx b/packages/core-mobile/app/new/routes/(authenticator)/totp/_layout.tsx deleted file mode 100644 index ec4291f09..000000000 --- a/packages/core-mobile/app/new/routes/(authenticator)/totp/_layout.tsx +++ /dev/null @@ -1,16 +0,0 @@ -import React from 'react' -import { Stack } from 'new/components/navigation/Stack' -import { SignupProvider } from 'new/contexts/SignupProvider' - -export default function TotpLayout(): JSX.Element { - return ( - - - - - - - - - ) -} diff --git a/packages/core-mobile/app/new/routes/(authenticator)/totp/copyCode.tsx b/packages/core-mobile/app/new/routes/(authenticator)/totp/copyCode.tsx deleted file mode 100644 index 6736d4179..000000000 --- a/packages/core-mobile/app/new/routes/(authenticator)/totp/copyCode.tsx +++ /dev/null @@ -1,20 +0,0 @@ -import React from 'react' -import { useSignupContext } from 'new/contexts/SignupProvider' -import { CopyCode as CopyCodeComponent } from '../components/CopyCode' -import { Loader } from '../components/Loader' - -export default function CopyCode(): JSX.Element { - const { handleCopyCode, handleBack, totpKey } = useSignupContext() - - if (totpKey === undefined) { - return - } - - return ( - - ) -} diff --git a/packages/core-mobile/app/new/routes/(authenticator)/totp/scanQrCode.tsx b/packages/core-mobile/app/new/routes/(authenticator)/totp/scanQrCode.tsx deleted file mode 100644 index fb19f8976..000000000 --- a/packages/core-mobile/app/new/routes/(authenticator)/totp/scanQrCode.tsx +++ /dev/null @@ -1,16 +0,0 @@ -import React from 'react' -import { useSignupContext } from 'new/contexts/SignupProvider' -import { ScanQrCode as ScanQrCodeComponent } from '../components/ScanQrCode' - -export default function ScanQrCode(): JSX.Element { - const { goToVerifyCode, goToEnterCodeManually, totpChallenge } = - useSignupContext() - - return ( - - ) -} diff --git a/packages/core-mobile/app/new/routes/(totp)/_layout.tsx b/packages/core-mobile/app/new/routes/(totp)/_layout.tsx new file mode 100644 index 000000000..4ad11dcb0 --- /dev/null +++ b/packages/core-mobile/app/new/routes/(totp)/_layout.tsx @@ -0,0 +1,13 @@ +import React from 'react' +import { Stack } from 'new/components/navigation/Stack' + +export default function TotpLayout(): JSX.Element { + return ( + + + + + + + ) +} diff --git a/packages/core-mobile/app/new/routes/(authenticator)/totp/authenticatorSetup.tsx b/packages/core-mobile/app/new/routes/(totp)/authenticatorSetup.tsx similarity index 73% rename from packages/core-mobile/app/new/routes/(authenticator)/totp/authenticatorSetup.tsx rename to packages/core-mobile/app/new/routes/(totp)/authenticatorSetup.tsx index e6afe7169..5a24b7432 100644 --- a/packages/core-mobile/app/new/routes/(authenticator)/totp/authenticatorSetup.tsx +++ b/packages/core-mobile/app/new/routes/(totp)/authenticatorSetup.tsx @@ -3,21 +3,24 @@ import { useSignupContext } from 'new/contexts/SignupProvider' import useSeedlessManageMFA from 'new/hooks/useSeedlessManageMFA' import AnalyticsService from 'services/analytics/AnalyticsService' import Logger from 'utils/Logger' -import { AuthenticatorSetup as AuthenticatorSetupComponent } from '../components/AuthenticatorSetup' -import { Loader } from '../components/Loader' +import { useRouter } from 'expo-router' +import { AuthenticatorSetup as AuthenticatorSetupComponent } from '../../components/totp/AuthenticatorSetup' +import { Loader } from '../../components/totp/Loader' export default function AuthenticatorSetup(): JSX.Element { - const { - totpKey, - goToScanQrCode, - handleCopyCode, - goToVerifyCode, - totpChallenge, - setTotpChallenge - } = useSignupContext() - + const { totpKey, handleCopyCode, totpChallenge, setTotpChallenge } = + useSignupContext() + const router = useRouter() const { totpResetInit } = useSeedlessManageMFA() + const goToVerifyCode = (): void => { + router.push('./verifyCode') + } + + const goToScanQrCode = (): void => { + router.navigate('./scanQrCode') + } + useEffect(() => { const initChallenge = async (): Promise => { try { diff --git a/packages/core-mobile/app/new/routes/(totp)/copyCode.tsx b/packages/core-mobile/app/new/routes/(totp)/copyCode.tsx new file mode 100644 index 000000000..b8bbd5dac --- /dev/null +++ b/packages/core-mobile/app/new/routes/(totp)/copyCode.tsx @@ -0,0 +1,26 @@ +import React from 'react' +import { useSignupContext } from 'new/contexts/SignupProvider' +import { useRouter } from 'expo-router' +import { CopyCode as CopyCodeComponent } from '../../components/totp/CopyCode' +import { Loader } from '../../components/totp/Loader' + +export default function CopyCode(): JSX.Element { + const { handleCopyCode, totpKey } = useSignupContext() + const router = useRouter() + + const handleBack = (): void => { + router.canGoBack() && router.back() + } + + if (totpKey === undefined) { + return + } + + return ( + + ) +} diff --git a/packages/core-mobile/app/new/routes/(totp)/scanQrCode.tsx b/packages/core-mobile/app/new/routes/(totp)/scanQrCode.tsx new file mode 100644 index 000000000..fb8d4457e --- /dev/null +++ b/packages/core-mobile/app/new/routes/(totp)/scanQrCode.tsx @@ -0,0 +1,25 @@ +import React from 'react' +import { useSignupContext } from 'new/contexts/SignupProvider' +import { useRouter } from 'expo-router' +import { ScanQrCode as ScanQrCodeComponent } from '../../components/totp/ScanQrCode' + +export default function ScanQrCode(): JSX.Element { + const { totpChallenge } = useSignupContext() + const router = useRouter() + + const goToVerifyCode = (): void => { + router.push('./verifyCode') + } + + const goToEnterCodeManually = (): void => { + router.navigate('./copyCode') + } + + return ( + + ) +} diff --git a/packages/core-mobile/app/new/routes/(authenticator)/totp/verifyCode.tsx b/packages/core-mobile/app/new/routes/(totp)/verifyCode.tsx similarity index 79% rename from packages/core-mobile/app/new/routes/(authenticator)/totp/verifyCode.tsx rename to packages/core-mobile/app/new/routes/(totp)/verifyCode.tsx index e9c85de3a..0ae3ee1c2 100644 --- a/packages/core-mobile/app/new/routes/(authenticator)/totp/verifyCode.tsx +++ b/packages/core-mobile/app/new/routes/(totp)/verifyCode.tsx @@ -1,6 +1,6 @@ import React from 'react' import { useSignupContext } from 'new/contexts/SignupProvider' -import { VerifyCode as VerifyCodeComponent } from '../components/VerifyCode' +import { VerifyCode as VerifyCodeComponent } from '../../components/totp/VerifyCode' export default function VerifyCode(): JSX.Element { const { onVerifyCode, onVerifySuccess } = useSignupContext() diff --git a/packages/core-mobile/app/new/routes/_layout.tsx b/packages/core-mobile/app/new/routes/_layout.tsx index 3a6f2e962..984e057e4 100644 --- a/packages/core-mobile/app/new/routes/_layout.tsx +++ b/packages/core-mobile/app/new/routes/_layout.tsx @@ -112,6 +112,7 @@ export default function RootLayout(): JSX.Element | null { /> + {enabledPrivacyScreen && } diff --git a/packages/core-mobile/app/new/routes/addRecoveryMethods.tsx b/packages/core-mobile/app/new/routes/addRecoveryMethods.tsx index 2c1ac8c28..134267b45 100644 --- a/packages/core-mobile/app/new/routes/addRecoveryMethods.tsx +++ b/packages/core-mobile/app/new/routes/addRecoveryMethods.tsx @@ -48,7 +48,7 @@ const AddRecoveryMethods = (): JSX.Element => { return } if (selectedMethod === RecoveryMethods.Authenticator) { - navigate('./totp/authenticatorSetup') + navigate('./authenticatorSetup') AnalyticsService.capture('SeedlessAddMfa', { type: 'Authenticator' }) } }