Browse Source

Fix some errors to happen unexpected and make it more clear to user

master
Gaëtan Renaudeau 7 years ago
parent
commit
5f355480bb
  1. 8
      src/components/modals/Receive/steps/03-step-confirm-address.js
  2. 6
      src/components/modals/Receive/steps/04-step-receive-funds.js
  3. 12
      src/components/modals/Send/index.js
  4. 8
      src/config/errors.js
  5. 4
      src/helpers/deviceAccess.js

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

@ -1,6 +1,5 @@
// @flow
import invariant from 'invariant'
import styled from 'styled-components'
import React, { Fragment, PureComponent } from 'react'
@ -13,9 +12,7 @@ import TranslatedError from '../../../TranslatedError'
export default class StepConfirmAddress extends PureComponent<StepProps> {
render() {
const { t, device, account, isAddressVerified, verifyAddressError, transitionTo } = this.props
invariant(account, 'No account given')
invariant(device, 'No device given')
const { t, account, isAddressVerified, verifyAddressError, transitionTo } = this.props
return (
<Container>
<TrackPage category="Receive Flow" name="Step 3" />
@ -34,7 +31,8 @@ export default class StepConfirmAddress extends PureComponent<StepProps> {
<Fragment>
<Title>{t('app:receive.steps.confirmAddress.action')}</Title>
<Text>
{t('app:receive.steps.confirmAddress.text', { currencyName: account.currency.name })}
{account &&
t('app:receive.steps.confirmAddress.text', { currencyName: account.currency.name })}
</Text>
<Button mt={4} mb={2} primary onClick={() => transitionTo('receive')}>
{t('app:buttons.displayAddressOnDevice')}

6
src/components/modals/Receive/steps/04-step-receive-funds.js

@ -9,6 +9,7 @@ import { isSegwitAccount } from 'helpers/bip32'
import Box from 'components/base/Box'
import CurrentAddressForAccount from 'components/CurrentAddressForAccount'
import { WrongDeviceForAccount } from 'components/EnsureDeviceApp'
import { DisconnectedDevice } from 'config/errors'
import type { StepProps } from '..'
@ -21,9 +22,10 @@ export default class StepReceiveFunds extends PureComponent<StepProps> {
confirmAddress = async () => {
const { account, device, onChangeAddressVerified, transitionTo } = this.props
invariant(account, 'No account given')
invariant(device, 'No device given')
try {
if (!device || !account) {
throw new DisconnectedDevice()
}
const params = {
currencyId: account.currency.id,
devicePath: device.path,

12
src/components/modals/Send/index.js

@ -8,7 +8,6 @@ import { translate } from 'react-i18next'
import { createStructuredSelector } from 'reselect'
import type { Account, Operation } from '@ledgerhq/live-common/lib/types'
import { createCustomErrorClass } from 'helpers/errors'
import Track from 'analytics/Track'
import { updateAccountWithUpdater } from 'actions/accounts'
import { MODAL_SEND } from 'config/constants'
@ -21,6 +20,7 @@ import type { StepProps as DefaultStepProps } from 'components/base/Stepper'
import { getCurrentDevice } from 'reducers/devices'
import { accountsSelector } from 'reducers/accounts'
import { closeModal, openModal } from 'reducers/modals'
import { DisconnectedDevice, UserRefusedOnDevice } from 'config/errors'
import Modal from 'components/base/Modal'
import Stepper from 'components/base/Stepper'
@ -31,8 +31,6 @@ import StepConnectDevice, { StepConnectDeviceFooter } from './steps/02-step-conn
import StepVerification from './steps/03-step-verification'
import StepConfirmation, { StepConfirmationFooter } from './steps/04-step-confirmation'
const UserRefusedOnDevice = createCustomErrorClass('UserRefusedOnDevice')
type Props = {
t: T,
device: ?Device,
@ -204,7 +202,13 @@ class SendModal extends PureComponent<Props, State<*>> {
const { device } = this.props
const { account, transaction, bridge } = this.state
invariant(device && account && transaction && bridge, 'signTransaction invalid conditions')
if (!device) {
this.handleTransactionError(new DisconnectedDevice())
transitionTo('confirmation')
return
}
invariant(account && transaction && bridge, 'signTransaction invalid conditions')
this._signTransactionSub = bridge
.signAndBroadcast(account, transaction, device.path)

8
src/config/errors.js

@ -0,0 +1,8 @@
// @flow
// TODO we need to start porting all custom errors here.
import { createCustomErrorClass } from 'helpers/errors'
export const DisconnectedDevice = createCustomErrorClass('DisconnectedDevice')
export const UserRefusedOnDevice = createCustomErrorClass('UserRefusedOnDevice') // TODO rename because it's just for transaction refusal

4
src/helpers/deviceAccess.js

@ -3,8 +3,8 @@ import logger from 'logger'
import throttle from 'lodash/throttle'
import type Transport from '@ledgerhq/hw-transport'
import TransportNodeHid from '@ledgerhq/hw-transport-node-hid'
import { DisconnectedDevice } from 'config/errors'
import { retry } from './promise'
import { createCustomErrorClass } from './errors'
// all open to device must use openDevice so we can prevent race conditions
// and guarantee we do one device access at a time. It also will handle the .close()
@ -12,8 +12,6 @@ import { createCustomErrorClass } from './errors'
type WithDevice = (devicePath: string) => <T>(job: (Transport<*>) => Promise<*>) => Promise<T>
const DisconnectedDevice = createCustomErrorClass('DisconnectedDevice')
const mapError = e => {
if (e && e.message && e.message.indexOf('HID') >= 0) {
throw new DisconnectedDevice(e.message)

Loading…
Cancel
Save