From a5ac3e88ea5661f31e51111ddda962627c4260f0 Mon Sep 17 00:00:00 2001 From: Anastasia Poupeney Date: Wed, 6 Jun 2018 09:54:26 +0200 Subject: [PATCH 1/2] BUG double request to confirm the address on the device in prod --- src/components/DeviceCheckAddress.js | 36 ----------------- .../modals/Receive/03-step-confirm-address.js | 6 +-- src/components/modals/Receive/index.js | 40 ++++++++++++++++++- 3 files changed, 40 insertions(+), 42 deletions(-) diff --git a/src/components/DeviceCheckAddress.js b/src/components/DeviceCheckAddress.js index 80108ded..e2121b06 100644 --- a/src/components/DeviceCheckAddress.js +++ b/src/components/DeviceCheckAddress.js @@ -1,16 +1,9 @@ // @flow 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 = { - onCheck: boolean => void, render: ({ isVerified?: ?boolean }) => *, - account: Account, - device: Device, } type State = { @@ -22,11 +15,6 @@ class CheckAddress extends PureComponent { isVerified: null, } - componentDidMount() { - const { device, account } = this.props - this.verifyAddress({ device, account }) - } - componentWillUnmount() { this._isUnmounted = true } @@ -40,30 +28,6 @@ class CheckAddress extends PureComponent { 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() { const { render } = this.props const { isVerified } = this.state diff --git a/src/components/modals/Receive/03-step-confirm-address.js b/src/components/modals/Receive/03-step-confirm-address.js index e5bbe89a..d356374b 100644 --- a/src/components/modals/Receive/03-step-confirm-address.js +++ b/src/components/modals/Receive/03-step-confirm-address.js @@ -34,7 +34,6 @@ type Props = { account: ?Account, addressVerified: ?boolean, device: ?Device, - onCheck: Function, t: T, } @@ -55,10 +54,7 @@ export default (props: Props) => ( props.account && ( } + render={() => } /> )} diff --git a/src/components/modals/Receive/index.js b/src/components/modals/Receive/index.js index a7029775..f3a402cb 100644 --- a/src/components/modals/Receive/index.js +++ b/src/components/modals/Receive/index.js @@ -8,6 +8,8 @@ import type { T, Device } from 'types/common' import { MODAL_RECEIVE } from 'config/constants' +import getAddress from 'commands/getAddress' + import Box from 'components/base/Box' import Breadcrumb from 'components/Breadcrumb' import Button from 'components/base/Button' @@ -108,6 +110,11 @@ class ReceiveModal extends PureComponent { return } this.setState({ stepIndex: stepIndex + 1 }) + + // TODO: do that better + if (stepIndex === 1) { + this.verifyAddress() + } } handlePrevStep = () => { @@ -154,12 +161,16 @@ class ReceiveModal extends PureComponent { } } - handleRetryCheckAddress = () => + handleRetryCheckAddress = () => { this.setState({ addressVerified: null, stepsErrors: [], }) + // TODO: do that better + this.verifyAddress() + } + handleChangeAmount = amount => this.setState({ amount }) handleBeforeOpenModal = ({ data }) => { @@ -180,6 +191,33 @@ class ReceiveModal extends PureComponent { 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 = () => { const { account, amount, addressVerified, deviceSelected, stepIndex } = this.state const { t } = this.props From 262d1f4bf98403aa68fb5590d9fcf1c63779749a Mon Sep 17 00:00:00 2001 From: Anastasia Poupeney Date: Wed, 6 Jun 2018 11:16:36 +0200 Subject: [PATCH 2/2] remove not needed anymore component --- src/components/DeviceCheckAddress.js | 39 ------------------- .../modals/Receive/03-step-confirm-address.js | 9 +---- 2 files changed, 1 insertion(+), 47 deletions(-) delete mode 100644 src/components/DeviceCheckAddress.js diff --git a/src/components/DeviceCheckAddress.js b/src/components/DeviceCheckAddress.js deleted file mode 100644 index e2121b06..00000000 --- a/src/components/DeviceCheckAddress.js +++ /dev/null @@ -1,39 +0,0 @@ -// @flow - -import { PureComponent } from 'react' - -type Props = { - render: ({ isVerified?: ?boolean }) => *, -} - -type State = { - isVerified: null | boolean, -} - -class CheckAddress extends PureComponent { - state = { - isVerified: null, - } - - componentWillUnmount() { - this._isUnmounted = true - } - - _isUnmounted = false - - safeSetState = (...args: *) => { - if (this._isUnmounted) { - return - } - this.setState(...args) - } - - render() { - const { render } = this.props - const { isVerified } = this.state - - return render({ isVerified }) - } -} - -export default CheckAddress diff --git a/src/components/modals/Receive/03-step-confirm-address.js b/src/components/modals/Receive/03-step-confirm-address.js index d356374b..30885933 100644 --- a/src/components/modals/Receive/03-step-confirm-address.js +++ b/src/components/modals/Receive/03-step-confirm-address.js @@ -9,7 +9,6 @@ import type { Device, T } from 'types/common' import Box from 'components/base/Box' import CurrentAddressForAccount from 'components/CurrentAddressForAccount' import DeviceConfirm from 'components/DeviceConfirm' -import DeviceCheckAddress from 'components/DeviceCheckAddress' const Container = styled(Box).attrs({ alignItems: 'center', @@ -51,13 +50,7 @@ export default (props: Props) => ( {props.t('receive:steps.confirmAddress.text')} {props.account && } {props.device && - props.account && ( - - } - /> - - )} + props.account && } )}