Browse Source

Progress on Onboarding Genuine Check

master
Gaëtan Renaudeau 7 years ago
parent
commit
375398b4a4
  1. 61
      src/components/GenuineCheckModal/index.js
  2. 26
      src/components/Onboarding/steps/GenuineCheck.js
  3. 5
      src/components/Workflow/index.js
  4. 2
      src/reducers/onboarding.js

61
src/components/GenuineCheckModal/index.js

@ -1,6 +1,6 @@
// @flow // @flow
import React, { PureComponent } from 'react' import React, { PureComponent, Fragment } from 'react'
import { translate } from 'react-i18next' import { translate } from 'react-i18next'
import type { T } from 'types/common' import type { T } from 'types/common'
@ -11,14 +11,47 @@ import WorkflowDefault from 'components/Workflow/WorkflowDefault'
type Props = { type Props = {
t: T, t: T,
onGenuineCheck: (isGenuine: boolean) => void, onGenuineCheckPass: () => void,
onGenuineCheckFailed: () => void,
onGenuineCheckUnavailable: Error => void,
} }
type State = {} type State = {}
class GenuineCheckStatus extends PureComponent<*> {
componentDidMount() {
this.sideEffect()
}
componentDidUpdate() {
this.sideEffect()
}
sideEffect() {
const {
isGenuine,
error,
onGenuineCheckPass,
onGenuineCheckFailed,
onGenuineCheckUnavailable,
} = this.props
if (isGenuine !== undefined) {
if (isGenuine) {
onGenuineCheckPass()
} else {
onGenuineCheckFailed()
}
} else if (error) {
onGenuineCheckUnavailable(error)
}
}
render() {
return null
}
}
/* eslint-disable react/no-multi-comp */
class GenuineCheck extends PureComponent<Props, State> { class GenuineCheck extends PureComponent<Props, State> {
renderBody = ({ onClose }) => { renderBody = ({ onClose }) => {
const { t, onGenuineCheck } = this.props const { t, onGenuineCheckPass, onGenuineCheckFailed, onGenuineCheckUnavailable } = this.props
// TODO: use the real devices list. for now we force choosing only // TODO: use the real devices list. for now we force choosing only
// the current device because we don't handle multi device in MVP // the current device because we don't handle multi device in MVP
@ -28,14 +61,22 @@ class GenuineCheck extends PureComponent<Props, State> {
<ModalTitle>{t('app:genuinecheck.modal.title')}</ModalTitle> <ModalTitle>{t('app:genuinecheck.modal.title')}</ModalTitle>
<ModalContent> <ModalContent>
<Workflow <Workflow
onGenuineCheck={isGenuine => onGenuineCheck(isGenuine)}
renderDefault={(device, deviceInfo, isGenuine, errors) => ( renderDefault={(device, deviceInfo, isGenuine, errors) => (
<WorkflowDefault <Fragment>
device={device} <GenuineCheckStatus
deviceInfo={deviceInfo} isGenuine={isGenuine}
isGenuine={isGenuine} error={errors.genuineError}
errors={errors} // TODO: FIX ERRORS onGenuineCheckPass={onGenuineCheckPass}
/> onGenuineCheckFailed={onGenuineCheckFailed}
onGenuineCheckUnavailable={onGenuineCheckUnavailable}
/>
<WorkflowDefault
device={device}
deviceInfo={deviceInfo}
isGenuine={isGenuine}
errors={errors} // TODO: FIX ERRORS
/>
</Fragment>
)} )}
/> />
</ModalContent> </ModalContent>

26
src/components/Onboarding/steps/GenuineCheck.js

@ -90,10 +90,28 @@ class GenuineCheck extends PureComponent<StepProps, State> {
handleCloseGenuineCheckModal = (cb?: Function) => handleCloseGenuineCheckModal = (cb?: Function) =>
this.setState(state => ({ ...state, isGenuineCheckModalOpened: false }), () => cb && cb()) this.setState(state => ({ ...state, isGenuineCheckModalOpened: false }), () => cb && cb())
handleGenuineCheck = isGenuine => { handleGenuineCheckPass = () => {
this.handleCloseGenuineCheckModal(() => { this.handleCloseGenuineCheckModal(() => {
this.props.updateGenuineCheck({ this.props.updateGenuineCheck({
isDeviceGenuine: isGenuine, isDeviceGenuine: true,
genuineCheckUnavailable: null,
})
})
}
handleGenuineCheckFailed = () => {
this.handleCloseGenuineCheckModal(() => {
this.props.updateGenuineCheck({
isDeviceGenuine: false,
genuineCheckUnavailable: null,
})
})
}
handleGenuineCheckUnavailable = error => {
this.handleCloseGenuineCheckModal(() => {
this.props.updateGenuineCheck({
isDeviceGenuine: false,
genuineCheckUnavailable: error,
}) })
}) })
} }
@ -219,7 +237,9 @@ class GenuineCheck extends PureComponent<StepProps, State> {
<GenuineCheckModal <GenuineCheckModal
isOpened={isGenuineCheckModalOpened} isOpened={isGenuineCheckModalOpened}
onClose={this.handleCloseGenuineCheckModal} onClose={this.handleCloseGenuineCheckModal}
onGenuineCheck={this.handleGenuineCheck} onGenuineCheckPass={this.handleGenuineCheckPass}
onGenuineCheckFailed={this.handleGenuineCheckFailed}
onGenuineCheckUnavailable={this.handleGenuineCheckUnavailable}
/> />
</FixedTopContainer> </FixedTopContainer>
) )

5
src/components/Workflow/index.js

@ -34,11 +34,11 @@ type Props = {
renderMcuUpdate?: (deviceInfo: DeviceInfo) => Node, renderMcuUpdate?: (deviceInfo: DeviceInfo) => Node,
renderFinalUpdate?: (deviceInfo: DeviceInfo) => Node, renderFinalUpdate?: (deviceInfo: DeviceInfo) => Node,
renderDashboard?: (device: Device, deviceInfo: DeviceInfo, isGenuine: boolean) => Node, renderDashboard?: (device: Device, deviceInfo: DeviceInfo, isGenuine: boolean) => Node,
onGenuineCheck?: (isGenuine: boolean) => void,
renderError?: (dashboardError: ?Error, genuineError: ?Error) => Node, renderError?: (dashboardError: ?Error, genuineError: ?Error) => Node,
} }
type State = {} type State = {}
// In future, move to meri's approach; this code is way too much specific
class Workflow extends PureComponent<Props, State> { class Workflow extends PureComponent<Props, State> {
render() { render() {
const { const {
@ -47,7 +47,6 @@ class Workflow extends PureComponent<Props, State> {
renderMcuUpdate, renderMcuUpdate,
renderError, renderError,
renderDefault, renderDefault,
onGenuineCheck,
} = this.props } = this.props
return ( return (
<EnsureDevice> <EnsureDevice>
@ -74,8 +73,6 @@ class Workflow extends PureComponent<Props, State> {
} }
if (isGenuine && deviceInfo && device && !dashboardError && !genuineError) { if (isGenuine && deviceInfo && device && !dashboardError && !genuineError) {
if (onGenuineCheck) onGenuineCheck(isGenuine)
if (renderDashboard) return renderDashboard(device, deviceInfo, isGenuine) if (renderDashboard) return renderDashboard(device, deviceInfo, isGenuine)
} }

2
src/reducers/onboarding.js

@ -23,6 +23,7 @@ export type OnboardingState = {
recoveryStepPass: boolean, recoveryStepPass: boolean,
isGenuineFail: boolean, isGenuineFail: boolean,
isDeviceGenuine: boolean, isDeviceGenuine: boolean,
genuineCheckUnavailable: ?Error,
}, },
isLedgerNano: boolean | null, isLedgerNano: boolean | null,
flowType: string, flowType: string,
@ -36,6 +37,7 @@ const state: OnboardingState = {
recoveryStepPass: false, recoveryStepPass: false,
isGenuineFail: false, isGenuineFail: false,
isDeviceGenuine: false, isDeviceGenuine: false,
genuineCheckUnavailable: null,
}, },
isLedgerNano: null, isLedgerNano: null,
flowType: '', flowType: '',

Loading…
Cancel
Save