From d95d81974a322102cb852435179f8f67cd3d05cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Renaudeau?= Date: Fri, 29 Jun 2018 15:11:43 +0200 Subject: [PATCH] Fix error --- src/components/modals/Send/index.js | 8 +++----- src/helpers/errors.js | 18 +++++++++++++++++- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/components/modals/Send/index.js b/src/components/modals/Send/index.js index 9772ef6b..2f4bbafe 100644 --- a/src/components/modals/Send/index.js +++ b/src/components/modals/Send/index.js @@ -49,7 +49,6 @@ type State = { transaction: ?Transaction, optimisticOperation: ?Operation, isAppOpened: boolean, - errorSteps: number[], amount: number, error: ?Error, } @@ -125,7 +124,6 @@ const INITIAL_STATE = { error: null, optimisticOperation: null, isAppOpened: false, - errorSteps: [], } class SendModal extends PureComponent> { @@ -170,7 +168,6 @@ class SendModal extends PureComponent> { handleRetry = () => { this.setState({ error: null, - errorSteps: [], optimisticOperation: null, isAppOpened: false, }) @@ -179,7 +176,7 @@ class SendModal extends PureComponent> { handleTransactionError = (error: Error) => { const stepVerificationIndex = this.STEPS.findIndex(step => step.id === 'verification') if (stepVerificationIndex === -1) return - this.setState({ error, errorSteps: [stepVerificationIndex] }) + this.setState({ error }) } handleOperationBroadcasted = (optimisticOperation: Operation) => { @@ -232,7 +229,6 @@ class SendModal extends PureComponent> { stepId, account, isAppOpened, - errorSteps, bridge, transaction, optimisticOperation, @@ -256,6 +252,8 @@ class SendModal extends PureComponent> { signTransaction: this.handleSignTransaction, } + const errorSteps = error ? [error instanceof UserRefusedOnDevice ? 2 : 3] : [] + const isModalLocked = stepId === 'verification' return ( diff --git a/src/helpers/errors.js b/src/helpers/errors.js index 61e10c3d..5b6221ab 100644 --- a/src/helpers/errors.js +++ b/src/helpers/errors.js @@ -1,6 +1,7 @@ // @flow /* eslint-disable no-continue */ +// TODO we need to centralize the error in one place. so all are recorded const errorClasses = {} export const createCustomErrorClass = (name: string): Class => { @@ -21,7 +22,22 @@ export const createCustomErrorClass = (name: string): Class => { // inspired from https://github.com/programble/errio/blob/master/index.js export const deserializeError = (object: mixed): Error => { if (typeof object === 'object' && object) { - const constructor = (typeof object.name === 'string' && errorClasses[object.name]) || Error + try { + // $FlowFixMe FIXME HACK + const msg = JSON.parse(object.message) + if (msg.message && msg.name) { + object = msg + } + } catch (e) { + // nothing + } + const constructor = + object.name === 'Error' + ? Error + : typeof object.name === 'string' + ? errorClasses[object.name] || createCustomErrorClass(object.name) + : Error + const error = Object.create(constructor.prototype) for (const prop in object) { if (object.hasOwnProperty(prop)) {