From 3373ae69e5aabaeab146fd78972f00d647f3e4fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Renaudeau?= Date: Fri, 15 Jun 2018 11:13:23 +0200 Subject: [PATCH] Fix refuse on device to go on step 4 --- src/components/DeviceConfirm/index.js | 4 ++-- .../modals/Send/03-step-verification.js | 5 ++--- src/components/modals/Send/index.js | 16 ++++++++-------- src/helpers/createCustomErrorClass.js | 3 ++- static/i18n/en/errors.yml | 1 + 5 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/components/DeviceConfirm/index.js b/src/components/DeviceConfirm/index.js index a9c88790..6e9a4e8b 100644 --- a/src/components/DeviceConfirm/index.js +++ b/src/components/DeviceConfirm/index.js @@ -41,7 +41,7 @@ const WrapperIcon = styled(Box)` } ` -const Check = ({ error }: { error: * }) => ( +const Check = ({ error }: { error?: boolean }) => ( {error ? : } @@ -74,7 +74,7 @@ const PushButton = styled(Box)` ` type Props = { - error: *, + error?: boolean, } const SVG = ( diff --git a/src/components/modals/Send/03-step-verification.js b/src/components/modals/Send/03-step-verification.js index a6df0e6d..1148b617 100644 --- a/src/components/modals/Send/03-step-verification.js +++ b/src/components/modals/Send/03-step-verification.js @@ -27,14 +27,13 @@ const Info = styled(Box).attrs({ ` type Props = { - hasError: boolean, t: T, } -export default ({ t, hasError }: Props) => ( +export default ({ t }: Props) => ( {multiline(t('app:send.steps.verification.warning'))} {t('app:send.steps.verification.body')} - + ) diff --git a/src/components/modals/Send/index.js b/src/components/modals/Send/index.js index 62fdf864..57106659 100644 --- a/src/components/modals/Send/index.js +++ b/src/components/modals/Send/index.js @@ -15,6 +15,7 @@ import { getBridgeForCurrency } from 'bridge' import { accountsSelector } from 'reducers/accounts' import { updateAccountWithUpdater } from 'actions/accounts' +import createCustomErrorClass from 'helpers/createCustomErrorClass' import { MODAL_SEND } from 'config/constants' import Modal, { ModalBody, ModalContent, ModalTitle } from 'components/base/Modal' @@ -32,6 +33,8 @@ import StepAmount from './01-step-amount' import StepVerification from './03-step-verification' import StepConfirmation from './04-step-confirmation' +export const UserRefusedOnDevice = createCustomErrorClass('UserRefusedOnDevice') + type Props = { updateAccountWithUpdater: (string, (Account) => Account) => void, accounts: Account[], @@ -226,14 +229,11 @@ class SendModal extends Component> { }) } - onOperationError = (error: Error) => { - // $FlowFixMe - if (error.statusCode === 0x6985) { - // User denied on device - this.setState({ error }) - } else { - this.setState({ error, stepIndex: 3 }) - } + onOperationError = (error: *) => { + this.setState({ + error: error.statusCode === 0x6985 ? new UserRefusedOnDevice() : error, + stepIndex: 3, + }) } onChangeAccount = account => { diff --git a/src/helpers/createCustomErrorClass.js b/src/helpers/createCustomErrorClass.js index 78738ef5..698dc61e 100644 --- a/src/helpers/createCustomErrorClass.js +++ b/src/helpers/createCustomErrorClass.js @@ -1,6 +1,6 @@ // @flow -export default (name: string) => { +export default (name: string): Class => { const C = function CustomError(message?: string, fields?: Object) { this.name = name this.message = message || name @@ -9,5 +9,6 @@ export default (name: string) => { } // $FlowFixMe C.prototype = new Error() + // $FlowFixMe we can't easily type a subset of Error for now... return C } diff --git a/static/i18n/en/errors.yml b/static/i18n/en/errors.yml index 34d4f713..7b6596f8 100644 --- a/static/i18n/en/errors.yml +++ b/static/i18n/en/errors.yml @@ -11,3 +11,4 @@ LedgerAPINotAvailable: 'Ledger API is not available for currency {{currencyName} LedgerAPIError: 'A problem occurred with Ledger API. Please try again later. (HTTP {{status}})' NetworkDown: 'Your internet connection seems down. Please try again later.' NoAddressesFound: 'No accounts found' +UserRefusedOnDevice: Transaction have been aborted