Browse Source

BUG double request to confirm the address on the device in prod

master
Anastasia Poupeney 7 years ago
parent
commit
a5ac3e88ea
  1. 36
      src/components/DeviceCheckAddress.js
  2. 6
      src/components/modals/Receive/03-step-confirm-address.js
  3. 40
      src/components/modals/Receive/index.js

36
src/components/DeviceCheckAddress.js

@ -1,16 +1,9 @@
// @flow // @flow
import { PureComponent } from 'react' import { PureComponent } from 'react'
import type { Account } from '@ledgerhq/live-common/lib/types'
import type { Device } from 'types/common'
import getAddress from 'commands/getAddress'
type Props = { type Props = {
onCheck: boolean => void,
render: ({ isVerified?: ?boolean }) => *, render: ({ isVerified?: ?boolean }) => *,
account: Account,
device: Device,
} }
type State = { type State = {
@ -22,11 +15,6 @@ class CheckAddress extends PureComponent<Props, State> {
isVerified: null, isVerified: null,
} }
componentDidMount() {
const { device, account } = this.props
this.verifyAddress({ device, account })
}
componentWillUnmount() { componentWillUnmount() {
this._isUnmounted = true this._isUnmounted = true
} }
@ -40,30 +28,6 @@ class CheckAddress extends PureComponent<Props, State> {
this.setState(...args) this.setState(...args)
} }
verifyAddress = async ({ device, account }: { device: Device, account: Account }) => {
try {
const { address } = await getAddress
.send({
currencyId: account.currency.id,
devicePath: device.path,
path: account.freshAddressPath,
segwit: !!account.isSegwit,
verify: true,
})
.toPromise()
if (address !== account.freshAddress) {
throw new Error('Confirmed address is different')
}
this.safeSetState({ isVerified: true })
this.props.onCheck(true)
} catch (err) {
this.safeSetState({ isVerified: false })
this.props.onCheck(false)
}
}
render() { render() {
const { render } = this.props const { render } = this.props
const { isVerified } = this.state const { isVerified } = this.state

6
src/components/modals/Receive/03-step-confirm-address.js

@ -34,7 +34,6 @@ type Props = {
account: ?Account, account: ?Account,
addressVerified: ?boolean, addressVerified: ?boolean,
device: ?Device, device: ?Device,
onCheck: Function,
t: T, t: T,
} }
@ -55,10 +54,7 @@ export default (props: Props) => (
props.account && ( props.account && (
<Box mb={2} mt={-1}> <Box mb={2} mt={-1}>
<DeviceCheckAddress <DeviceCheckAddress
account={props.account} render={() => <DeviceConfirm error={props.addressVerified === false} />}
device={props.device}
onCheck={props.onCheck}
render={({ isVerified }) => <DeviceConfirm error={isVerified === false} />}
/> />
</Box> </Box>
)} )}

40
src/components/modals/Receive/index.js

@ -8,6 +8,8 @@ import type { T, Device } from 'types/common'
import { MODAL_RECEIVE } from 'config/constants' import { MODAL_RECEIVE } from 'config/constants'
import getAddress from 'commands/getAddress'
import Box from 'components/base/Box' import Box from 'components/base/Box'
import Breadcrumb from 'components/Breadcrumb' import Breadcrumb from 'components/Breadcrumb'
import Button from 'components/base/Button' import Button from 'components/base/Button'
@ -108,6 +110,11 @@ class ReceiveModal extends PureComponent<Props, State> {
return return
} }
this.setState({ stepIndex: stepIndex + 1 }) this.setState({ stepIndex: stepIndex + 1 })
// TODO: do that better
if (stepIndex === 1) {
this.verifyAddress()
}
} }
handlePrevStep = () => { handlePrevStep = () => {
@ -154,12 +161,16 @@ class ReceiveModal extends PureComponent<Props, State> {
} }
} }
handleRetryCheckAddress = () => handleRetryCheckAddress = () => {
this.setState({ this.setState({
addressVerified: null, addressVerified: null,
stepsErrors: [], stepsErrors: [],
}) })
// TODO: do that better
this.verifyAddress()
}
handleChangeAmount = amount => this.setState({ amount }) handleChangeAmount = amount => this.setState({ amount })
handleBeforeOpenModal = ({ data }) => { handleBeforeOpenModal = ({ data }) => {
@ -180,6 +191,33 @@ class ReceiveModal extends PureComponent<Props, State> {
stepIndex: this._steps.length - 1, // last step stepIndex: this._steps.length - 1, // last step
}) })
verifyAddress = async () => {
const { account, deviceSelected: device } = this.state
try {
if (account && device) {
const { address } = await getAddress
.send({
currencyId: account.currency.id,
devicePath: device.path,
path: account.freshAddressPath,
segwit: !!account.isSegwit,
verify: true,
})
.toPromise()
if (address !== account.freshAddress) {
throw new Error('Confirmed address is different')
}
this.setState({ addressVerified: true, stepIndex: 3 })
} else {
this.setState({ addressVerified: false })
}
} catch (err) {
this.setState({ addressVerified: false })
}
}
renderStep = () => { renderStep = () => {
const { account, amount, addressVerified, deviceSelected, stepIndex } = this.state const { account, amount, addressVerified, deviceSelected, stepIndex } = this.state
const { t } = this.props const { t } = this.props

Loading…
Cancel
Save