Skip to content

Commit

Permalink
Only show terms once and restore to onboarding education if the user …
Browse files Browse the repository at this point in the history
…didn't go far enough
  • Loading branch information
jeanregisser committed Jul 28, 2020
1 parent 2c7ea83 commit b219b74
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 20 deletions.
11 changes: 11 additions & 0 deletions packages/mobile/src/account/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { PaymentRequest } from 'src/account/types'

// TODO(Rossy): Remove the _ACTION suffix from these actions for consistency with other other names
export enum Actions {
CHOOSE_CREATE_ACCOUNT = 'ACCOUNT/CHOOSE_CREATE',
CHOOSE_RESTORE_ACCOUNT = 'ACCOUNT/CHOOSE_RESTORE',
CANCEL_CREATE_OR_RESTORE_ACCOUNT = 'ACCOUNT/CANCEL_CREATE_OR_RESTORE_ACCOUNT',
SET_NAME = 'ACCOUNT/SET_NAME',
Expand All @@ -29,6 +30,9 @@ export enum Actions {
MIGRATE_ACCOUNT_BIP39 = 'MIGRATE_ACCOUNT_BIP39',
}

export interface ChooseCreateAccountAction {
type: Actions.CHOOSE_CREATE_ACCOUNT
}
export interface ChooseRestoreAccountAction {
type: Actions.CHOOSE_RESTORE_ACCOUNT
}
Expand Down Expand Up @@ -137,6 +141,7 @@ export interface MigrateAccount {
}

export type ActionTypes =
| ChooseCreateAccountAction
| ChooseRestoreAccountAction
| CancelCreateOrRestoreAccountAction
| SetNameAction
Expand All @@ -162,6 +167,12 @@ export type ActionTypes =
| AcceptTermsAction
| MigrateAccount

export function chooseCreateAccount(): ChooseCreateAccountAction {
return {
type: Actions.CHOOSE_CREATE_ACCOUNT,
}
}

export function chooseRestoreAccount(): ChooseRestoreAccountAction {
return {
type: Actions.CHOOSE_RESTORE_ACCOUNT,
Expand Down
5 changes: 5 additions & 0 deletions packages/mobile/src/account/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ export const reducer = (
dismissedGetVerified: false,
}
}
case Actions.CHOOSE_CREATE_ACCOUNT:
return {
...state,
isRestoringAccount: false,
}
case Actions.CHOOSE_RESTORE_ACCOUNT:
return {
...state,
Expand Down
7 changes: 2 additions & 5 deletions packages/mobile/src/navigator/Navigator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -483,12 +483,9 @@ export function MainStackScreen() {

if (!language) {
initialRoute = Screens.Language
} else if (!e164Number) {
} else if (!e164Number || !acceptedTerms || pincodeType === PincodeType.Unset) {
// User didn't go far enough in onboarding, start again from education
initialRoute = Screens.OnboardingEducationScreen
} else if (!acceptedTerms) {
initialRoute = Screens.RegulatoryTerms
} else if (pincodeType === PincodeType.Unset) {
initialRoute = Screens.PincodeSet
} else if (!redeemComplete && !account) {
initialRoute = isRestoringAccount ? Screens.ImportWallet : Screens.EnterInviteCode
} else if (!hasSeenVerificationNux) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import 'react-native'
import { fireEvent, render } from 'react-native-testing-library'
import { Provider } from 'react-redux'
import * as renderer from 'react-test-renderer'
import { PincodeType } from 'src/account/reducer'
import { ErrorMessages } from 'src/app/ErrorMessages'
import { Screens } from 'src/navigator/Screens'
import NameAndNumber, {
Expand Down Expand Up @@ -40,7 +39,6 @@ describe('NameAndNumberScreen', () => {
const wrapper = render(
<Provider store={store}>
<NameAndNumberClass
acceptedTerms={false}
showError={showErrorMock}
hideAlert={jest.fn()}
setPromptForno={jest.fn()}
Expand All @@ -49,7 +47,6 @@ describe('NameAndNumberScreen', () => {
cachedName={''}
cachedNumber={''}
cachedCountryCallingCode={'+1'}
pincodeType={PincodeType.Unset}
{...getMockI18nProps()}
{...mockScreenProps}
/>
Expand All @@ -64,7 +61,6 @@ describe('NameAndNumberScreen', () => {
const wrapper = render(
<Provider store={createMockStore()}>
<NameAndNumberClass
acceptedTerms={false}
showError={jest.fn()}
hideAlert={jest.fn()}
setPromptForno={jest.fn()}
Expand All @@ -73,7 +69,6 @@ describe('NameAndNumberScreen', () => {
cachedName={''}
cachedNumber={''}
cachedCountryCallingCode={''}
pincodeType={PincodeType.Unset}
{...getMockI18nProps()}
{...mockScreenProps}
/>
Expand All @@ -88,7 +83,6 @@ describe('NameAndNumberScreen', () => {
const wrapper = render(
<Provider store={createMockStore()}>
<NameAndNumberClass
acceptedTerms={false}
showError={error}
hideAlert={jest.fn()}
setPhoneNumber={jest.fn()}
Expand All @@ -97,7 +91,6 @@ describe('NameAndNumberScreen', () => {
cachedName={''}
cachedNumber={''}
cachedCountryCallingCode={''}
pincodeType={PincodeType.Unset}
{...getMockI18nProps()}
{...mockScreenProps}
/>
Expand Down
5 changes: 0 additions & 5 deletions packages/mobile/src/onboarding/registration/NameAndNumber.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import * as RNLocalize from 'react-native-localize'
import { SafeAreaView } from 'react-native-safe-area-context'
import { connect } from 'react-redux'
import { setName, setPhoneNumber, setPromptForno } from 'src/account/actions'
import { PincodeType } from 'src/account/reducer'
import { hideAlert, showError } from 'src/alert/actions'
import { OnboardingEvents } from 'src/analytics/Events'
import ValoraAnalytics from 'src/analytics/ValoraAnalytics'
Expand All @@ -30,8 +29,6 @@ interface StateProps {
cachedName: string | null
cachedNumber: string | null
cachedCountryCallingCode: string | null
pincodeType: PincodeType
acceptedTerms: boolean
}

interface DispatchProps {
Expand Down Expand Up @@ -67,8 +64,6 @@ const mapStateToProps = (state: RootState): StateProps => {
cachedName: state.account.name,
cachedNumber: state.account.e164PhoneNumber,
cachedCountryCallingCode: state.account.defaultCountryCode,
pincodeType: state.account.pincodeType,
acceptedTerms: state.account.acceptedTerms,
}
}

Expand Down
10 changes: 9 additions & 1 deletion packages/mobile/src/onboarding/welcome/Welcome.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,15 @@ describe('Welcome', () => {
fireEvent.press(getByTestId('CreateAccountButton'))
jest.runAllTimers()
expect(navigate).toHaveBeenCalledWith(Screens.RegulatoryTerms)
expect(store.getActions()).toMatchInlineSnapshot(`Array []`)
expect(store.getActions()).toMatchInlineSnapshot(`
Array [
Object {
"type": "ACCOUNT/CHOOSE_CREATE",
},
]
`)

store.clearActions()

fireEvent.press(getByTestId('RestoreAccountButton'))
jest.runAllTimers()
Expand Down
11 changes: 9 additions & 2 deletions packages/mobile/src/onboarding/welcome/Welcome.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,32 @@ import { useTranslation } from 'react-i18next'
import { Image, StyleSheet, Text, View } from 'react-native'
import { SafeAreaView, useSafeAreaInsets } from 'react-native-safe-area-context'
import { useDispatch } from 'react-redux'
import { chooseRestoreAccount } from 'src/account/actions'
import { chooseCreateAccount, chooseRestoreAccount } from 'src/account/actions'
import { Namespaces } from 'src/i18n'
import Logo, { LogoTypes } from 'src/icons/Logo.v2'
import { welcomeBackground } from 'src/images/Images'
import { nuxNavigationOptions } from 'src/navigator/Headers.v2'
import { navigate } from 'src/navigator/NavigationService'
import { Screens } from 'src/navigator/Screens'
import LanguageButton from 'src/onboarding/LanguageButton'
import useSelector from 'src/redux/useSelector'

export default function Welcome() {
const { t } = useTranslation(Namespaces.onboarding)
const dispatch = useDispatch()
const acceptedTerms = useSelector((state) => state.account.acceptedTerms)
const insets = useSafeAreaInsets()

const navigateNext = () => {
navigate(Screens.RegulatoryTerms)
if (!acceptedTerms) {
navigate(Screens.RegulatoryTerms)
} else {
navigate(Screens.NameAndNumber)
}
}

const onPressCreateAccount = () => {
dispatch(chooseCreateAccount())
navigateNext()
}

Expand Down

0 comments on commit b219b74

Please sign in to comment.