Gaëtan Renaudeau 7 years ago
parent
commit
833c013fc2
  1. 17
      src/components/Onboarding/index.js
  2. 11
      src/components/OnboardingOrElse.js
  3. 12
      src/components/SettingsPage/LaunchOnboardingBtn.js
  4. 4
      src/components/layout/Default.js
  5. 12
      src/reducers/onboarding.js

17
src/components/Onboarding/index.js

@ -20,6 +20,7 @@ import {
updateGenuineCheck,
isLedgerNano,
flowType,
relaunchOnboarding,
} from 'reducers/onboarding'
import { getCurrentDevice } from 'reducers/devices'
@ -66,6 +67,7 @@ const mapDispatchToProps = {
jumpStep,
unlock,
openModal,
relaunchOnboarding,
}
type Props = {
@ -80,6 +82,7 @@ type Props = {
getCurrentDevice: Function,
unlock: Function,
openModal: string => void,
relaunchOnboarding: boolean => void,
}
export type StepProps = {
@ -103,6 +106,7 @@ class Onboarding extends PureComponent<Props> {
getDeviceInfo = () => this.props.getCurrentDevice
finish = () => {
this.props.saveSettings({ hasCompletedOnboarding: true })
this.props.relaunchOnboarding(false)
setTimeout(() => {
this.props.openModal(MODAL_DISCLAIMER)
}, MODAL_DISCLAIMER_DELAY)
@ -118,18 +122,7 @@ class Onboarding extends PureComponent<Props> {
}
render() {
const {
hasCompletedOnboarding,
onboarding,
prevStep,
nextStep,
jumpStep,
settings,
t,
} = this.props
if (hasCompletedOnboarding) {
return null
}
const { onboarding, prevStep, nextStep, jumpStep, settings, t } = this.props
const StepComponent = STEPS[onboarding.stepName]
const step = onboarding.steps[onboarding.stepIndex]

11
src/components/OnboardingOrElse.js

@ -4,25 +4,28 @@ import React, { PureComponent } from 'react'
import { connect } from 'react-redux'
import { createStructuredSelector } from 'reselect'
import { hasCompletedOnboardingSelector } from 'reducers/settings'
import { onboardingRelaunchedSelector } from 'reducers/onboarding'
import Onboarding from './Onboarding'
type Props = {
hasCompletedOnboarding: boolean,
onboardingRelaunched: boolean,
children: *,
}
class OnboardingOrElse extends PureComponent<Props> {
render() {
const { hasCompletedOnboarding, children } = this.props
if (hasCompletedOnboarding) {
return children
}
const { hasCompletedOnboarding, onboardingRelaunched, children } = this.props
if (!hasCompletedOnboarding || onboardingRelaunched) {
return <Onboarding />
}
return children
}
}
export default connect(
createStructuredSelector({
hasCompletedOnboarding: hasCompletedOnboardingSelector,
onboardingRelaunched: onboardingRelaunchedSelector,
}),
)(OnboardingOrElse)

12
src/components/SettingsPage/LaunchOnboardingBtn.js

@ -2,32 +2,24 @@
import React, { Fragment, PureComponent } from 'react'
import { connect } from 'react-redux'
import { saveSettings } from 'actions/settings'
import { translate } from 'react-i18next'
import type { T } from 'types/common'
import type { SettingsState } from 'reducers/settings'
import type { OnboardingState } from 'reducers/onboarding'
import Track from 'analytics/Track'
import Onboarding from 'components/Onboarding'
import Button from 'components/base/Button/index'
import { relaunchOnboarding } from 'reducers/onboarding'
const mapDispatchToProps = {
saveSettings,
relaunchOnboarding,
}
type Props = {
saveSettings: ($Shape<SettingsState>) => void,
relaunchOnboarding: ($Shape<OnboardingState>) => void,
relaunchOnboarding: boolean => void,
t: T,
}
class LaunchOnboardingBtn extends PureComponent<Props> {
handleLaunchOnboarding = () => {
this.props.saveSettings({ hasCompletedOnboarding: false })
this.props.relaunchOnboarding({ onboardingRelaunched: true })
return <Onboarding />
this.props.relaunchOnboarding(true)
}
render() {
const { t } = this.props

4
src/components/layout/Default.js

@ -88,8 +88,8 @@ class Default extends Component<Props> {
<ExportLogsBtn hookToShortcut />
<Track mandatory onMount event="App Starts" />
<OnboardingOrElse>
<IsUnlocked>
<OnboardingOrElse>
{Object.entries(modals).map(([name, ModalComponent]: [string, any]) => (
<ModalComponent key={name} />
))}
@ -119,8 +119,8 @@ class Default extends Component<Props> {
<KeyboardContent sequence="BJBJBJ">
<PerfIndicator />
</KeyboardContent>
</IsUnlocked>
</OnboardingOrElse>
</IsUnlocked>
</Fragment>
)
}

12
src/reducers/onboarding.js

@ -2,6 +2,7 @@
import { SKIP_ONBOARDING } from 'config/constants'
import { handleActions, createAction } from 'redux-actions'
import type { State } from '.'
type Step = {
name: string,
@ -170,14 +171,17 @@ const handlers = {
...state,
isLedgerNano,
}),
ONBOARDING_RELAUNCH: (
state: OnboardingState,
{ payload: onboardingRelaunched }: { payload: $Shape<OnboardingState> },
) => ({ ...initialState, ...onboardingRelaunched }),
ONBOARDING_RELAUNCH: (state: OnboardingState, { payload: onboardingRelaunched }) => ({
...initialState,
onboardingRelaunched,
}),
}
export default handleActions(handlers, initialState)
export const onboardingRelaunchedSelector = (s: State): ?boolean =>
s.onboarding.onboardingRelaunched
export const relaunchOnboarding = createAction('ONBOARDING_RELAUNCH')
export const nextStep = createAction('ONBOARDING_NEXT_STEP')
export const prevStep = createAction('ONBOARDING_PREV_STEP')

Loading…
Cancel
Save