Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(onboarding): remove steps on phone verification screen when importing #4834

Merged
merged 2 commits into from
Feb 2, 2024
Merged
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
4 changes: 1 addition & 3 deletions src/RevokePhoneNumber.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,7 @@
}, [revokeNumberAsync.status])

const handleNavigateToVerifiedNumber = () => {
navigate(Screens.VerificationStartScreen, {
hideOnboardingStep: true,
})
navigate(Screens.VerificationStartScreen)

Check warning on line 54 in src/RevokePhoneNumber.tsx

View check run for this annotation

Codecov / codecov/patch

src/RevokePhoneNumber.tsx#L54

Added line #L54 was not covered by tests
}

const handleRevokePhoneNumber = async () => {
Expand Down
4 changes: 1 addition & 3 deletions src/account/Settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,7 @@

const goToConfirmNumber = () => {
ValoraAnalytics.track(SettingsEvents.settings_verify_number)
navigate(Screens.VerificationStartScreen, {
hideOnboardingStep: true,
})
navigate(Screens.VerificationStartScreen)

Check warning on line 119 in src/account/Settings.tsx

View check run for this annotation

Codecov / codecov/patch

src/account/Settings.tsx#L119

Added line #L119 was not covered by tests
}

const goToLanguageSetting = () => {
Expand Down
4 changes: 1 addition & 3 deletions src/consumerIncentives/ConsumerIncentivesHomeScreen.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,7 @@ describe('ConsumerIncentivesHomeScreen', () => {

fireEvent.press(getByTestId('ConsumerIncentives/CTA'))

expect(navigate).toHaveBeenCalledWith(Screens.VerificationStartScreen, {
hideOnboardingStep: true,
})
expect(navigate).toHaveBeenCalledWith(Screens.VerificationStartScreen)
})

it('opens a WebView when Learn More is tapped', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/consumerIncentives/ConsumerIncentivesHomeScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ export default function ConsumerIncentivesHomeScreen() {
buttonPressed: RewardsScreenCta.CashIn,
})
} else {
navigate(Screens.VerificationStartScreen, { hideOnboardingStep: true })
navigate(Screens.VerificationStartScreen)
ValoraAnalytics.track(RewardsEvents.rewards_screen_cta_pressed, {
buttonPressed: RewardsScreenCta.VerifyPhone,
})
Expand Down
4 changes: 1 addition & 3 deletions src/home/NotificationBox.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,7 @@ describe('NotificationBox', () => {
expect(getByText('reverifyUsingCPVHomecard.description')).toBeTruthy()

fireEvent.press(getByText('reverifyUsingCPVHomecard.buttonLabel'))
expect(navigate).toHaveBeenCalledWith(Screens.VerificationStartScreen, {
hideOnboardingStep: true,
})
expect(navigate).toHaveBeenCalledWith(Screens.VerificationStartScreen)
})

it('renders educations when not complete yet', () => {
Expand Down
6 changes: 2 additions & 4 deletions src/home/NotificationBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ export function useSimpleActions() {
notificationId: NotificationType.reverify_using_CPV,
notificationPositionInList: params?.index,
})
navigate(Screens.VerificationStartScreen, { hideOnboardingStep: true })
navigate(Screens.VerificationStartScreen)
},
},
],
Expand Down Expand Up @@ -282,9 +282,7 @@ export function useSimpleActions() {
notificationId: NotificationType.verification_prompt,
notificationPositionInList: params?.index,
})
navigate(Screens.VerificationStartScreen, {
hideOnboardingStep: true,
})
navigate(Screens.VerificationStartScreen)
},
},
{
Expand Down
4 changes: 1 addition & 3 deletions src/home/NotificationCenter.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -294,9 +294,7 @@ describe('NotificationCenter', () => {
expect(getByText('reverifyUsingCPVHomecard.description')).toBeTruthy()

fireEvent.press(getByText('reverifyUsingCPVHomecard.buttonLabel'))
expect(navigate).toHaveBeenCalledWith(Screens.VerificationStartScreen, {
hideOnboardingStep: true,
})
expect(navigate).toHaveBeenCalledWith(Screens.VerificationStartScreen)
})

it('emits correct analytics event when CTA button is pressed', () => {
Expand Down
3 changes: 1 addition & 2 deletions src/navigator/types.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -292,9 +292,8 @@ export type StackParamList = {
[Screens.ValidateRecipientAccount]: ValidateRecipientParams
[Screens.VerificationStartScreen]:
| {
hideOnboardingStep?: boolean
isOnboarding?: boolean
selectedCountryCodeAlpha2?: string
choseToRestoreAccount?: boolean
}
| undefined
[Screens.VerificationCodeInputScreen]: {
Expand Down
58 changes: 37 additions & 21 deletions src/onboarding/steps.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ describe('onboarding steps', () => {
chooseAdventureEnabled: false,
},
screens: [
Screens.NameAndPicture,
Screens.PincodeSet,
Screens.EnableBiometry,
Screens.ProtectWallet,
Screens.VerificationStartScreen,
{ screen: Screens.NameAndPicture, props: undefined },
{ screen: Screens.PincodeSet, props: undefined },
{ screen: Screens.EnableBiometry, props: undefined },
{ screen: Screens.ProtectWallet, props: undefined },
{ screen: Screens.VerificationStartScreen, props: { isOnboarding: true } },
],
name: 'newUserFlowWithEverythingEnabled',
finalScreen: Screens.WalletHome,
Expand All @@ -47,10 +47,10 @@ describe('onboarding steps', () => {
onboardingNameScreenEnabled: false,
},
screens: [
Screens.PincodeSet,
Screens.EnableBiometry,
Screens.ProtectWallet,
Screens.VerificationStartScreen,
{ screen: Screens.PincodeSet, props: undefined },
{ screen: Screens.EnableBiometry, props: undefined },
{ screen: Screens.ProtectWallet, props: undefined },
{ screen: Screens.VerificationStartScreen, props: { isOnboarding: true } },
],
name: 'newUserChooseAdventure',
finalScreen: Screens.ChooseYourAdventure,
Expand All @@ -64,7 +64,11 @@ describe('onboarding steps', () => {
recoveringFromStoreWipe: false,
chooseAdventureEnabled: false,
},
screens: [Screens.NameAndPicture, Screens.PincodeSet, Screens.ProtectWallet],
screens: [
{ screen: Screens.NameAndPicture, props: undefined },
{ screen: Screens.PincodeSet, props: undefined },
{ screen: Screens.ProtectWallet, props: undefined },
],
name: 'newUserFlowWithEverythingDisabled',
finalScreen: Screens.WalletHome,
}
Expand All @@ -79,26 +83,30 @@ describe('onboarding steps', () => {
chooseAdventureEnabled: false,
},
screens: [
Screens.NameAndPicture,
Screens.PincodeSet,
Screens.EnableBiometry,
Screens.ImportWallet,
Screens.VerificationStartScreen,
{ screen: Screens.NameAndPicture, props: undefined },
{ screen: Screens.PincodeSet, props: undefined },
{ screen: Screens.EnableBiometry, props: undefined },
{ screen: Screens.ImportWallet, props: undefined },
{ screen: Screens.VerificationStartScreen, props: { isOnboarding: true } },
],
name: 'importWalletFlowEverythingEnabled',
finalScreen: Screens.WalletHome,
}

beforeEach(() => {
jest.clearAllMocks()
})

it.each([
newUserFlowWithEverythingEnabled,
newUserChooseAdventure,
newUserFlowWithEverythingDisabled,
importWalletFlowEverythingEnabled,
])(
'goToNextOnboardingScreen and getOnboardingStepValues work as expected',
'goToNextOnboardingScreen and getOnboardingStepValues work as expected for $name',
({ onboardingProps, screens, name, finalScreen }) => {
const expectedTotalSteps = screens.length
screens.forEach((screen, index) => {
screens.forEach(({ screen, props }, index) => {
const { totalSteps, step } = getOnboardingStepValues(screen, onboardingProps)
// Checking that the step number is correct
try {
Expand All @@ -122,12 +130,16 @@ describe('onboarding steps', () => {
updateStatsigAndNavigate(finalScreen as keyof StackParamList)
)
} else {
const args: any[] = [screens[index + 1].screen]
if (screens[index + 1].props) {
args.push(screens[index + 1].props)
}
try {
// eslint-disable-next-line jest/no-conditional-expect
expect(navigate).toHaveBeenCalledWith(screens[index + 1])
expect(navigate).toHaveBeenCalledWith(...args)
} catch {
// eslint-disable-next-line jest/no-conditional-expect
expect(navigateClearingStack).toHaveBeenCalledWith(screens[index + 1])
expect(navigateClearingStack).toHaveBeenCalledWith(...args)
}
}
})
Expand Down Expand Up @@ -286,7 +298,9 @@ describe('onboarding steps', () => {
},
})
expect(mockStore.dispatch).not.toHaveBeenCalled()
expect(navigate).toHaveBeenCalledWith(Screens.VerificationStartScreen)
expect(navigate).toHaveBeenCalledWith(Screens.VerificationStartScreen, {
isOnboarding: true,
})
})
})
describe('Screens.VerificationStartScreen', () => {
Expand Down Expand Up @@ -330,7 +344,9 @@ describe('onboarding steps', () => {
},
})
expect(mockStore.dispatch).not.toHaveBeenCalled()
expect(navigate).toHaveBeenCalledWith(Screens.VerificationStartScreen)
expect(navigate).toHaveBeenCalledWith(Screens.VerificationStartScreen, {
isOnboarding: true,
})
})
})
})
Expand Down
15 changes: 7 additions & 8 deletions src/onboarding/steps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,10 @@ import { StatsigExperiments } from 'src/statsig/types'
export const END_OF_ONBOARDING_SCREENS = [Screens.WalletHome, Screens.ChooseYourAdventure]

interface NavigatorFunctions {
navigate: typeof NavigationService.navigate | ((screen: Screens) => void)
Copy link
Contributor Author

@satish-ravi satish-ravi Jan 31, 2024

Choose a reason for hiding this comment

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

this dummy type (for calculating total steps) wasn't allowing setting screen props, updated the fn below to match navigate's type

popToScreen: typeof NavigationService.popToScreen | ((screen: Screens) => void)
navigate: typeof NavigationService.navigate
popToScreen: typeof NavigationService.popToScreen
finishOnboarding: (screen: keyof StackParamList) => void
navigateClearingStack:
| typeof NavigationService.navigateClearingStack
| ((screen: Screens) => void)
navigateClearingStack: typeof NavigationService.navigateClearingStack
}

interface GetStepInfoProps {
Expand Down Expand Up @@ -110,8 +108,9 @@ export function getOnboardingStepValues(screen: Screens, onboardingProps: Onboar
let reachedStep = false // tracks whether we have reached the step the user is on in onboarding, and we can stop incrementing stepCounter
let currentScreen: Screens = firstScreen // pointer that we will update when simulating navigation through the onboarding screens to calculate "step" and "totalSteps"

const nextStepAndCount = (nextScreen: Screens) => {
const nextStepAndCount: typeof NavigationService.navigate = (...args) => {
// dummy navigation function to help determine what onboarding step the user is on, without triggering side effects like actually cycling them back through the first few onboarding screens
const [nextScreen] = args
if (!END_OF_ONBOARDING_SCREENS.includes(nextScreen)) {
totalCounter++
if (currentScreen === screen) {
Expand Down Expand Up @@ -252,7 +251,7 @@ export function _getStepInfo({ firstScreenInStep, navigator, dispatch, props }:
navigateHomeOrChooseAdventure()
} else {
// DO NOT CLEAR NAVIGATION STACK HERE - breaks restore flow on initial app open in native-stack v6
navigate(Screens.VerificationStartScreen)
navigate(Screens.VerificationStartScreen, { isOnboarding: true })
}
},
}
Expand All @@ -271,7 +270,7 @@ export function _getStepInfo({ firstScreenInStep, navigator, dispatch, props }:
dispatch(setHasSeenVerificationNux(true))
finishOnboarding(Screens.WalletHome)
} else {
navigate(Screens.VerificationStartScreen)
navigate(Screens.VerificationStartScreen, { isOnboarding: true })
}
},
}
Expand Down
4 changes: 1 addition & 3 deletions src/send/SelectRecipientButtons.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,7 @@ describe('SelectRecipientButtons', () => {
expect(getByTestId('SelectRecipient/PhoneNumberModal')).not.toBeVisible()
})
await waitFor(() => {
expect(navigate).toHaveBeenCalledWith(Screens.VerificationStartScreen, {
hideOnboardingStep: true,
})
expect(navigate).toHaveBeenCalledWith(Screens.VerificationStartScreen)
})
})

Expand Down
2 changes: 1 addition & 1 deletion src/send/SelectRecipientButtons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ export default function SelectRecipientButtons({ onContactsPermissionGranted }:
// reset state so the next time the modal is dismissed, this doesn't end
// up navigating
setNavigateToPhoneVerification(false)
navigate(Screens.VerificationStartScreen, { hideOnboardingStep: true })
navigate(Screens.VerificationStartScreen)
}
}

Expand Down
4 changes: 1 addition & 3 deletions src/send/Send.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,7 @@
}

const onPressStartVerification = () => {
navigate(Screens.VerificationStartScreen, {
hideOnboardingStep: true,
})
navigate(Screens.VerificationStartScreen)

Check warning on line 195 in src/send/Send.tsx

View check run for this annotation

Codecov / codecov/patch

src/send/Send.tsx#L195

Added line #L195 was not covered by tests
}

const onPressContactsSettings = () => {
Expand Down
Loading
Loading