From a314c2faedc19b8727950f4ce7c5dfa5e1093600 Mon Sep 17 00:00:00 2001 From: Vladimir Volek Date: Mon, 13 Aug 2018 14:52:43 +0200 Subject: [PATCH] ErrorBoundary added --- .../wallet/account/receive/Receive.js | 5 +++- .../wallet/account/send/SendForm.js | 7 +++-- src/js/index.js | 5 +--- src/js/router/index.js | 30 +++++++++++-------- src/js/support/ErrorBoundary.js | 25 ++++++++++++++++ src/js/utils/ethUtils.js | 1 - 6 files changed, 52 insertions(+), 21 deletions(-) create mode 100644 src/js/support/ErrorBoundary.js diff --git a/src/js/components/wallet/account/receive/Receive.js b/src/js/components/wallet/account/receive/Receive.js index 2dc4e007..bd92bc10 100644 --- a/src/js/components/wallet/account/receive/Receive.js +++ b/src/js/components/wallet/account/receive/Receive.js @@ -12,6 +12,9 @@ import { Notification } from '~/js/components/common/Notification'; import type { Props } from './index'; const Wrapper = styled.div``; +const StyledH2 = styled(H2)` + padding: 20px 48px; +`; const Receive = (props: Props) => { const device = props.wallet.selectedDevice; @@ -78,7 +81,7 @@ const Receive = (props: Props) => { return ( -

Receive Ethereum or tokens

+ Receive Ethereum or tokens
{ ver }
diff --git a/src/js/components/wallet/account/send/SendForm.js b/src/js/components/wallet/account/send/SendForm.js index b78b49a5..7af77fa7 100644 --- a/src/js/components/wallet/account/send/SendForm.js +++ b/src/js/components/wallet/account/send/SendForm.js @@ -1,6 +1,7 @@ /* @flow */ import React, { Component } from 'react'; +import styled from 'styled-components'; import Select from 'react-select'; import { H2 } from '~/js/components/common/Heading'; import AdvancedForm from './AdvancedForm'; @@ -15,7 +16,6 @@ import { findToken } from '~/js/reducers/TokensReducer'; import type { Props } from './index'; import type { Token } from '~/flowtype'; - export default class SendContainer extends Component { componentWillReceiveProps(newProps: Props) { calculate(this.props, newProps); @@ -33,6 +33,9 @@ export default class SendContainer extends Component { } } +const StyledH2 = styled(H2)` + padding: 20px 48px; +`; const Send = (props: Props) => { const device = props.wallet.selectedDevice; @@ -117,7 +120,7 @@ const Send = (props: Props) => { return (
-

Send Ethereum or tokens

+ Send Ethereum or tokens
, - root, - ); + render(, root); } window.onbeforeunload = () => { diff --git a/src/js/router/index.js b/src/js/router/index.js index 68ad389c..3d684345 100644 --- a/src/js/router/index.js +++ b/src/js/router/index.js @@ -5,6 +5,8 @@ import { Provider } from 'react-redux'; import { ConnectedRouter } from 'react-router-redux'; import store, { history } from '../store'; +import ErrorBoundary from '~/js/support/ErrorBoundary'; + import LandingPageContainer from '../components/landing'; import WalletContainer from '../components/wallet'; import BootloaderContainer from '../components/wallet/pages/Bootloader'; @@ -29,19 +31,21 @@ const App = () => ( - - - - - - - - - - - - - + + + + + + + + + + + + + + + diff --git a/src/js/support/ErrorBoundary.js b/src/js/support/ErrorBoundary.js new file mode 100644 index 00000000..f47d2581 --- /dev/null +++ b/src/js/support/ErrorBoundary.js @@ -0,0 +1,25 @@ +import React, { Component } from 'react'; + +class ErrorBoundary extends Component { + constructor(props) { + super(props); + this.state = { hasError: false }; + } + + componentDidCatch(error, info) { + // Display fallback UI + this.setState({ hasError: true }); + // You can also log the error to an error reporting service + // logErrorToMyService(error, info); + } + + render() { + if (this.state.hasError) { + // You can render any custom fallback UI + return
Something went wrong.
; + } + return this.props.children; + } +} + +export default ErrorBoundary; \ No newline at end of file diff --git a/src/js/utils/ethUtils.js b/src/js/utils/ethUtils.js index 53f248e8..be1c889a 100644 --- a/src/js/utils/ethUtils.js +++ b/src/js/utils/ethUtils.js @@ -1,6 +1,5 @@ /* @flow */ - import BigNumber from 'bignumber.js'; export const decimalToHex = (dec: number): string => new BigNumber(dec).toString(16);