From fcb148037678d57bf9fe7e54f5194b2f06cee181 Mon Sep 17 00:00:00 2001 From: Anastasia Poupeney Date: Mon, 2 Jul 2018 17:34:55 +0200 Subject: [PATCH] translated error wired into receive modal and the Upgrade Firmware case handled --- src/commands/getAddress.js | 17 ++++++++++++++++- src/components/SettingsPage/ResetButton.js | 2 +- src/components/modals/Receive/index.js | 14 ++++++++++---- .../Receive/steps/03-step-confirm-address.js | 13 +++++++++---- static/i18n/en/app.yml | 3 --- static/i18n/en/errors.yml | 6 ++++++ 6 files changed, 42 insertions(+), 13 deletions(-) diff --git a/src/commands/getAddress.js b/src/commands/getAddress.js index fd4c3a73..d4a73ae9 100644 --- a/src/commands/getAddress.js +++ b/src/commands/getAddress.js @@ -6,6 +6,11 @@ import { fromPromise } from 'rxjs/observable/fromPromise' import { withDevice } from 'helpers/deviceAccess' import getAddressForCurrency from 'helpers/getAddressForCurrency' +import { createCustomErrorClass } from 'helpers/errors' + +const DeviceAppVerifyNotSupported = createCustomErrorClass('DeviceAppVerifyNotSupported') +const UserRefusedAddress = createCustomErrorClass('UserRefusedAddress') + type Input = { currencyId: string, devicePath: string, @@ -26,7 +31,17 @@ const cmd: Command = createCommand( fromPromise( withDevice(devicePath)(transport => getAddressForCurrency(transport, getCryptoCurrencyById(currencyId), path, options), - ), + ).catch(e => { + if (e && e.name === 'TransportStatusError') { + if (e.statusCode === 0x6b00 && options.verify) { + throw new DeviceAppVerifyNotSupported() + } + if (e.statusCode === 0x6985) { + throw new UserRefusedAddress() + } + } + throw e + }), ), ) diff --git a/src/components/SettingsPage/ResetButton.js b/src/components/SettingsPage/ResetButton.js index 25943e73..6a5d99b8 100644 --- a/src/components/SettingsPage/ResetButton.js +++ b/src/components/SettingsPage/ResetButton.js @@ -75,7 +75,7 @@ export const IconWrapperCircle = styled(Box)` height: 50px; border-radius: 50%; background: #ea2e4919; - text-align: center; + align-items: center; justify-content: center; ` diff --git a/src/components/modals/Receive/index.js b/src/components/modals/Receive/index.js index 208d5b6c..df3b6fb9 100644 --- a/src/components/modals/Receive/index.js +++ b/src/components/modals/Receive/index.js @@ -41,6 +41,7 @@ type State = { isAddressVerified: ?boolean, disabledSteps: number[], errorSteps: number[], + verifyAddressError: ?Error, } export type StepProps = DefaultStepProps & { @@ -49,12 +50,13 @@ export type StepProps = DefaultStepProps & { closeModal: void => void, isAppOpened: boolean, isAddressVerified: ?boolean, + verifyAddressError: ?Error, onRetry: void => void, onSkipConfirm: void => void, onResetSkip: void => void, onChangeAccount: (?Account) => void, onChangeAppOpened: boolean => void, - onChangeAddressVerified: (?boolean) => void, + onChangeAddressVerified: (?boolean, ?Error) => void, } const createSteps = ({ t }: { t: T }) => [ @@ -102,6 +104,7 @@ const INITIAL_STATE = { isAddressVerified: null, disabledSteps: [], errorSteps: [], + verifyAddressError: null, } class ReceiveModal extends PureComponent { @@ -127,16 +130,17 @@ class ReceiveModal extends PureComponent { handleStepChange = step => this.setState({ stepId: step.id }) handleChangeAccount = (account: ?Account) => this.setState({ account }) handleChangeAppOpened = (isAppOpened: boolean) => this.setState({ isAppOpened }) - handleChangeAddressVerified = (isAddressVerified: boolean) => { + handleChangeAddressVerified = (isAddressVerified: boolean, err: ?Error) => { if (isAddressVerified) { - this.setState({ isAddressVerified }) + this.setState({ isAddressVerified, verifyAddressError: err }) } else if (isAddressVerified === null) { - this.setState({ isAddressVerified: null, errorSteps: [] }) + this.setState({ isAddressVerified: null, errorSteps: [], verifyAddressError: err }) } else { const confirmStepIndex = this.STEPS.findIndex(step => step.id === 'confirm') if (confirmStepIndex > -1) { this.setState({ isAddressVerified, + verifyAddressError: err, errorSteps: [confirmStepIndex], }) } @@ -161,6 +165,7 @@ class ReceiveModal extends PureComponent { isAddressVerified, disabledSteps, errorSteps, + verifyAddressError, } = this.state const addtionnalProps = { @@ -168,6 +173,7 @@ class ReceiveModal extends PureComponent { account, isAppOpened, isAddressVerified, + verifyAddressError, closeModal: this.handleCloseModal, onRetry: this.handleRetry, onSkipConfirm: this.handleSkipConfirm, diff --git a/src/components/modals/Receive/steps/03-step-confirm-address.js b/src/components/modals/Receive/steps/03-step-confirm-address.js index debdc74a..1329881e 100644 --- a/src/components/modals/Receive/steps/03-step-confirm-address.js +++ b/src/components/modals/Receive/steps/03-step-confirm-address.js @@ -15,6 +15,7 @@ import CurrentAddressForAccount from 'components/CurrentAddressForAccount' import { WrongDeviceForAccount } from 'components/EnsureDeviceApp' import type { StepProps } from '../index' +import TranslatedError from '../../../TranslatedError' export default class StepConfirmAddress extends PureComponent { componentDidMount() { @@ -43,12 +44,12 @@ export default class StepConfirmAddress extends PureComponent { onChangeAddressVerified(true) transitionTo('receive') } catch (err) { - onChangeAddressVerified(false) + onChangeAddressVerified(false, err) } } render() { - const { t, device, account, isAddressVerified } = this.props + const { t, device, account, isAddressVerified, verifyAddressError } = this.props invariant(account, 'No account given') invariant(device, 'No device given') return ( @@ -56,8 +57,12 @@ export default class StepConfirmAddress extends PureComponent { {isAddressVerified === false ? ( - {t('app:receive.steps.confirmAddress.error.title')} - {t('app:receive.steps.confirmAddress.error.text')} + + <TranslatedError error={verifyAddressError} /> + + + + ) : ( diff --git a/static/i18n/en/app.yml b/static/i18n/en/app.yml index 0ac3f0d9..842849e3 100644 --- a/static/i18n/en/app.yml +++ b/static/i18n/en/app.yml @@ -250,9 +250,6 @@ receive: action: Confirm address on device text: Verify that the address below matches the address displayed on your device support: Contact us - error: - title: Receive address rejected - text: Please try again or contact Support when in doubt receiveFunds: title: Receive label: Amount (optional) diff --git a/static/i18n/en/errors.yml b/static/i18n/en/errors.yml index a0033f12..bf7339e7 100644 --- a/static/i18n/en/errors.yml +++ b/static/i18n/en/errors.yml @@ -83,6 +83,9 @@ TransportStatusError: UserRefusedOnDevice: title: Transaction refused on device description: Please retry or contact Ledger Support in case of doubt. +UserRefusedAddress: + title: Receive address rejected + description: Please try again or contact Support WebsocketConnectionError: title: Sorry, try again (websocket error). description: #context @@ -95,3 +98,6 @@ WrongAppOpened: WrongDeviceForAccount: title: Oops, wrong device for ‘{{accountName}}’. description: The connected device is not associated with the account you selected. Please connect the right device. +DeviceAppVerifyNotSupported: + title: Open Manager to update firmware + description: The app verification is not supported