Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/app/(setup)/setup/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,16 @@ function SetupPageContent() {

// If invite code is present, set the step to the signup screen
if (determinedSetupInitialStepId && userInviteCode) {
const signupScreenIndex = steps.findIndex((s: ISetupStep) => s.screenId === 'signup')
dispatch(setupActions.setStep(signupScreenIndex + 1))
// if user is on android and not in a standalone pwa, force them to install the PWA first
if (localDeviceType === 'android' && !isStandalonePWA) {
const androidInitialPwaInstallScreenIndex = steps.findIndex(
(s: ISetupStep) => s.screenId === 'android-initial-pwa-install'
)
dispatch(setupActions.setStep(androidInitialPwaInstallScreenIndex + 1))
} else {
const signupScreenIndex = steps.findIndex((s: ISetupStep) => s.screenId === 'signup')
dispatch(setupActions.setStep(signupScreenIndex + 1))
}
Comment on lines +129 to +138
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Add missing error handling for findIndex results.

The code uses findIndex to locate step indices but doesn't check if the step exists (returns -1), unlike the existing logic at lines 140-148 which properly handles this case. If either 'android-initial-pwa-install' or 'signup' steps are missing from the steps array, this would dispatch invalid step indices.

Apply this diff to add consistent error handling:

 // If invite code is present, set the step to the signup screen
 if (determinedSetupInitialStepId && userInviteCode) {
     // if user is on android and not in a standalone pwa, force them to install the PWA first
     if (localDeviceType === 'android' && !isStandalonePWA) {
         const androidInitialPwaInstallScreenIndex = steps.findIndex(
             (s: ISetupStep) => s.screenId === 'android-initial-pwa-install'
         )
-        dispatch(setupActions.setStep(androidInitialPwaInstallScreenIndex + 1))
+        if (androidInitialPwaInstallScreenIndex !== -1) {
+            dispatch(setupActions.setStep(androidInitialPwaInstallScreenIndex + 1))
+        } else {
+            console.warn('Could not find android-initial-pwa-install step. Defaulting to step 1.')
+            dispatch(setupActions.setStep(1))
+        }
     } else {
         const signupScreenIndex = steps.findIndex((s: ISetupStep) => s.screenId === 'signup')
-        dispatch(setupActions.setStep(signupScreenIndex + 1))
+        if (signupScreenIndex !== -1) {
+            dispatch(setupActions.setStep(signupScreenIndex + 1))
+        } else {
+            console.warn('Could not find signup step. Defaulting to step 1.')
+            dispatch(setupActions.setStep(1))
+        }
     }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// if user is on android and not in a standalone pwa, force them to install the PWA first
if (localDeviceType === 'android' && !isStandalonePWA) {
const androidInitialPwaInstallScreenIndex = steps.findIndex(
(s: ISetupStep) => s.screenId === 'android-initial-pwa-install'
)
dispatch(setupActions.setStep(androidInitialPwaInstallScreenIndex + 1))
} else {
const signupScreenIndex = steps.findIndex((s: ISetupStep) => s.screenId === 'signup')
dispatch(setupActions.setStep(signupScreenIndex + 1))
}
// if user is on android and not in a standalone pwa, force them to install the PWA first
if (localDeviceType === 'android' && !isStandalonePWA) {
const androidInitialPwaInstallScreenIndex = steps.findIndex(
(s: ISetupStep) => s.screenId === 'android-initial-pwa-install'
)
if (androidInitialPwaInstallScreenIndex !== -1) {
dispatch(setupActions.setStep(androidInitialPwaInstallScreenIndex + 1))
} else {
console.warn('Could not find android-initial-pwa-install step. Defaulting to step 1.')
dispatch(setupActions.setStep(1))
}
} else {
const signupScreenIndex = steps.findIndex((s: ISetupStep) => s.screenId === 'signup')
if (signupScreenIndex !== -1) {
dispatch(setupActions.setStep(signupScreenIndex + 1))
} else {
console.warn('Could not find signup step. Defaulting to step 1.')
dispatch(setupActions.setStep(1))
}
}
🤖 Prompt for AI Agents
In src/app/(setup)/setup/page.tsx around lines 129 to 138, the code calls
findIndex for 'android-initial-pwa-install' and 'signup' but doesn't handle a -1
result; mirror the existing handling at lines 140-148 by checking the found
index for -1, and if -1 log an error (or console.error) and dispatch a safe
fallback (e.g., setStep(0) or the same fallback used later) instead of
dispatching an invalid index; otherwise dispatch setStep(foundIndex + 1) as
before.

} else if (determinedSetupInitialStepId) {
const initialStepIndex = steps.findIndex((s: ISetupStep) => s.screenId === determinedSetupInitialStepId)
if (initialStepIndex !== -1) {
Expand Down
21 changes: 19 additions & 2 deletions src/components/Setup/Views/InstallPWA.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ import ErrorAlert from '@/components/Global/ErrorAlert'
import { Icon } from '@/components/Global/Icons/Icon'
import Modal from '@/components/Global/Modal'
import QRCodeWrapper from '@/components/Global/QRCodeWrapper'
import { type BeforeInstallPromptEvent, type ScreenId } from '@/components/Setup/Setup.types'
import { type BeforeInstallPromptEvent, type ISetupStep, type ScreenId } from '@/components/Setup/Setup.types'
import { useAuth } from '@/context/authContext'
import { useSetupFlow } from '@/hooks/useSetupFlow'
import { useRouter } from 'next/navigation'
import { useCallback, useEffect, useState } from 'react'
import { captureException } from '@sentry/nextjs'
import { DeviceType } from '@/hooks/useGetDeviceType'
import { useAppDispatch, useSetupStore } from '@/redux/hooks'
import { setupActions } from '@/redux/slices/setup-slice'

const StepTitle = ({ text }: { text: string }) => <h3 className="text-xl font-extrabold leading-6">{text}</h3>

Expand All @@ -34,6 +36,7 @@ const InstallPWA = ({
}) => {
const toast = useToast()
const { handleNext, isLoading: isSetupFlowLoading } = useSetupFlow()
const { inviteCode, steps } = useSetupStore()
const [showModal, setShowModal] = useState(false)
const [installComplete, setInstallComplete] = useState(false)
const [installCancelled, setInstallCancelled] = useState(false)
Expand All @@ -42,6 +45,7 @@ const InstallPWA = ({
const [isBrave, setIsBrave] = useState(false)
const { user } = useAuth()
const { push } = useRouter()
const dispatch = useAppDispatch()

useEffect(() => {
if (installComplete) {
Expand Down Expand Up @@ -215,7 +219,20 @@ const InstallPWA = ({
<div className="space-y-2 text-center">
<p className="text-sm text-grey-1">Could not initiate automatic installation.</p>
<p className="text-sm text-grey-1">Please try adding to Home Screen manually via your browser menu.</p>
<Button onClick={() => handleNext()} className="mt-4 w-full" shadowSize="4" variant="purple">
<Button
onClick={() => {
// If user is on android and has an invite code, redirect to signup screen
if (inviteCode && deviceType === DeviceType.ANDROID) {
const signupScreeenIndex = steps.findIndex((s: ISetupStep) => s.screenId === 'signup')
dispatch(setupActions.setStep(signupScreeenIndex + 1))
} else {
handleNext()
}
Comment on lines +224 to +230
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Fix typos and add error handling for missing signup step.

Issues identified:

  1. Typo in variable name (line 226): signupScreeenIndex has three 'e's—should be signupScreenIndex.
  2. Typo in comment (line 224): "screeeen" should be "screen".
  3. Logic clarification needed: The comment states "redirect to signup screen", but the code navigates to signupScreenIndex + 1 (the step after signup). Please verify if the intent is to navigate TO the signup step or to the step AFTER signup.
  4. Missing error handling: If the signup step is not found, findIndex returns -1, causing setStep(0) to be dispatched, which may not be the desired behavior.

Apply this diff to fix the typos and add error handling:

-                        // If user is on android and has an invite code, redirect to signup screen
+                        // If user is on android and has an invite code, redirect to signup screen
                         if (inviteCode && deviceType === DeviceType.ANDROID) {
-                            const signupScreeenIndex = steps.findIndex((s: ISetupStep) => s.screenId === 'signup')
-                            dispatch(setupActions.setStep(signupScreeenIndex + 1))
+                            const signupScreenIndex = steps.findIndex((s: ISetupStep) => s.screenId === 'signup')
+                            if (signupScreenIndex !== -1) {
+                                dispatch(setupActions.setStep(signupScreenIndex + 1))
+                            } else {
+                                // Fallback to handleNext if signup step not found
+                                handleNext()
+                            }
                         } else {
                             handleNext()
                         }

Note: If the intent is to navigate TO the signup step (not after it), remove the + 1. Please clarify the expected navigation target and update the comment accordingly.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// If user is on android and has an invite code, redirect to signup screen
if (inviteCode && deviceType === DeviceType.ANDROID) {
const signupScreeenIndex = steps.findIndex((s: ISetupStep) => s.screenId === 'signup')
dispatch(setupActions.setStep(signupScreeenIndex + 1))
} else {
handleNext()
}
// If user is on android and has an invite code, redirect to signup screen
if (inviteCode && deviceType === DeviceType.ANDROID) {
const signupScreenIndex = steps.findIndex((s: ISetupStep) => s.screenId === 'signup')
if (signupScreenIndex !== -1) {
dispatch(setupActions.setStep(signupScreenIndex + 1))
} else {
// Fallback to handleNext if signup step not found
handleNext()
}
} else {
handleNext()
}
🤖 Prompt for AI Agents
In src/components/Setup/Views/InstallPWA.tsx around lines 224 to 230, fix the
typos and add error handling: rename signupScreeenIndex to signupScreenIndex and
correct the comment to "screen"; determine navigation target — if the intent is
to go TO the signup step remove the "+ 1" when calling setStep, otherwise keep
it to go after signup; add a guard after findIndex that checks for -1 and, in
that case, log an error/warning and fall back to handleNext() (do not dispatch
setStep(0) silently).

}}
className="mt-4 w-full"
shadowSize="4"
variant="purple"
>
Continue
</Button>
</div>
Expand Down
Loading