Browse Source

Merge pull request #764 from gre/error

Fix error
master
Meriadec Pillet 7 years ago
committed by GitHub
parent
commit
aa6ebeba80
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      src/components/modals/Send/index.js
  2. 18
      src/helpers/errors.js

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

@ -49,7 +49,6 @@ type State<Transaction> = {
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<Props, State<*>> {
@ -170,7 +168,6 @@ class SendModal extends PureComponent<Props, State<*>> {
handleRetry = () => {
this.setState({
error: null,
errorSteps: [],
optimisticOperation: null,
isAppOpened: false,
})
@ -179,7 +176,7 @@ class SendModal extends PureComponent<Props, State<*>> {
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<Props, State<*>> {
stepId,
account,
isAppOpened,
errorSteps,
bridge,
transaction,
optimisticOperation,
@ -256,6 +252,8 @@ class SendModal extends PureComponent<Props, State<*>> {
signTransaction: this.handleSignTransaction,
}
const errorSteps = error ? [error instanceof UserRefusedOnDevice ? 2 : 3] : []
const isModalLocked = stepId === 'verification'
return (

18
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<any> => {
@ -21,7 +22,22 @@ export const createCustomErrorClass = (name: string): Class<any> => {
// 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)) {

Loading…
Cancel
Save