Browse Source

Use GenuineCheck in GenuineCheckModal

master
meriadec 7 years ago
parent
commit
4237942949
No known key found for this signature in database GPG Key ID: 1D2FC2305E2CB399
  1. 37
      src/components/GenuineCheckModal.js
  2. 90
      src/components/GenuineCheckModal/index.js
  3. 6
      src/components/Onboarding/steps/GenuineCheck/index.js

37
src/components/GenuineCheckModal.js

@ -0,0 +1,37 @@
// @flow
import React, { PureComponent } from 'react'
import { translate } from 'react-i18next'
import type { T } from 'types/common'
import Modal, { ModalBody, ModalTitle, ModalContent } from 'components/base/Modal'
import GenuineCheck from 'components/GenuineCheck'
type Props = {
t: T,
onSuccess: void => void,
onFail: void => void,
onUnavailable: Error => void,
}
class GenuineCheckModal extends PureComponent<Props> {
renderBody = ({ onClose }) => {
const { t, onSuccess, onFail, onUnavailable } = this.props
return (
<ModalBody onClose={onClose}>
<ModalTitle>{t('app:genuinecheck.modal.title')}</ModalTitle>
<ModalContent>
<GenuineCheck onSuccess={onSuccess} onFail={onFail} onUnavailable={onUnavailable} />
</ModalContent>
</ModalBody>
)
}
render() {
const { t, ...props } = this.props
return <Modal {...props} render={this.renderBody} />
}
}
export default translate()(GenuineCheckModal)

90
src/components/GenuineCheckModal/index.js

@ -1,90 +0,0 @@
// @flow
import React, { PureComponent, Fragment } from 'react'
import { translate } from 'react-i18next'
import type { T } from 'types/common'
import Modal, { ModalBody, ModalTitle, ModalContent } from 'components/base/Modal'
import Workflow from 'components/Workflow'
import WorkflowDefault from 'components/Workflow/WorkflowDefault'
type Props = {
t: T,
onGenuineCheckPass: () => void,
onGenuineCheckFailed: () => void,
onGenuineCheckUnavailable: Error => void,
}
type State = {}
class GenuineCheckStatus extends PureComponent<*> {
componentDidUpdate() {
this.sideEffect()
}
sideEffect() {
const {
isGenuine,
error,
onGenuineCheckPass,
onGenuineCheckFailed,
onGenuineCheckUnavailable,
} = this.props
if (isGenuine !== null) {
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> {
renderBody = ({ onClose }) => {
const { t, onGenuineCheckPass, onGenuineCheckFailed, onGenuineCheckUnavailable } = this.props
// TODO: use the real devices list. for now we force choosing only
// the current device because we don't handle multi device in MVP
return (
<ModalBody onClose={onClose}>
<ModalTitle>{t('app:genuinecheck.modal.title')}</ModalTitle>
<ModalContent>
<Workflow
renderDefault={(device, deviceInfo, isGenuine, errors) => (
<Fragment>
<GenuineCheckStatus
isGenuine={isGenuine}
error={errors.genuineError}
onGenuineCheckPass={onGenuineCheckPass}
onGenuineCheckFailed={onGenuineCheckFailed}
onGenuineCheckUnavailable={onGenuineCheckUnavailable}
/>
<WorkflowDefault
device={device}
deviceInfo={deviceInfo}
isGenuine={isGenuine}
errors={errors} // TODO: FIX ERRORS
/>
</Fragment>
)}
/>
</ModalContent>
</ModalBody>
)
}
render() {
const { ...props } = this.props
return <Modal {...props} render={({ onClose }) => this.renderBody({ onClose })} />
}
}
export default translate()(GenuineCheck)

6
src/components/Onboarding/steps/GenuineCheck/index.js

@ -263,9 +263,9 @@ class GenuineCheck extends PureComponent<StepProps, State> {
<GenuineCheckModal
isOpened={isGenuineCheckModalOpened}
onClose={this.handleCloseGenuineCheckModal}
onGenuineCheckPass={this.handleGenuineCheckPass}
onGenuineCheckFailed={this.handleGenuineCheckFailed}
onGenuineCheckUnavailable={this.handleGenuineCheckUnavailable}
onSuccess={this.handleGenuineCheckPass}
onFail={this.handleGenuineCheckFailed}
onUnavailable={this.handleGenuineCheckUnavailable}
/>
</FixedTopContainer>
)

Loading…
Cancel
Save