diff --git a/src/components/App.js b/src/components/App.js index 41be7c6b..76dbf57c 100644 --- a/src/components/App.js +++ b/src/components/App.js @@ -12,6 +12,7 @@ import theme from 'styles/theme' import i18n from 'renderer/i18n/electron' +import ThrowBlock from 'components/ThrowBlock' import Default from 'components/layout/Default' import Dev from 'components/layout/Dev' import Print from 'components/layout/Print' @@ -30,13 +31,15 @@ const App = ({ - - - {(__DEV__ || DEV_TOOLS) && } - - - - + + + + {(__DEV__ || DEV_TOOLS) && } + + + + + diff --git a/src/components/ThrowBlock.js b/src/components/ThrowBlock.js new file mode 100644 index 00000000..0e98a92d --- /dev/null +++ b/src/components/ThrowBlock.js @@ -0,0 +1,100 @@ +// @flow + +import React, { PureComponent } from 'react' +import styled from 'styled-components' +import { shell, remote } from 'electron' +import qs from 'querystring' + +import { rgba } from 'styles/helpers' +import db from 'helpers/db' + +import Box from 'components/base/Box' +import Button from 'components/base/Button' + +type Props = { + children: any, +} + +type State = { + error: ?Error, +} + +const Container = styled(Box).attrs({ + grow: true, + align: 'center', + justify: 'center', + bg: 'lightGraphite', + color: 'alertRed', + ff: 'Museo Sans|Bold', + flow: 2, +})`` + +const Inner = styled(Box).attrs({ + p: 2, + bg: p => rgba(p.theme.colors.alertRed, 0.05), + borderRadius: 1, +})` + border: ${p => `1px solid ${rgba(p.theme.colors.alertRed, 0.1)}`}; +` + +class ThrowBlock extends PureComponent { + state = { + error: null, + } + + componentDidCatch(error: Error) { + this.setState({ error }) + } + + handleCreateIssue = () => { + const { error } = this.state + if (!error) { + return + } + const q = qs.stringify({ + title: `Error: ${error.message}`, + body: `Error was thrown: + +\`\`\` +${error.stack} +\`\`\` +`, + }) + shell.openExternal(`https://github.com/LedgerHQ/ledger-wallet-desktop/issues/new?${q}`) + } + + handleRestart = () => { + remote.app.relaunch() + remote.app.exit() + } + + handleReset = () => { + db.resetAll() + this.handleRestart() + } + + render() { + const { error } = this.state + if (error) { + return ( + + {`Error: ${error.message}`} + + + + + + + ) + } + return this.props.children + } +} + +export default ThrowBlock diff --git a/src/helpers/db.js b/src/helpers/db.js index 6110a036..086a1db3 100644 --- a/src/helpers/db.js +++ b/src/helpers/db.js @@ -83,4 +83,12 @@ export default { return val }, + + resetAll: () => { + const keys = ['settings', 'accounts', 'counterValues'] + keys.forEach(k => { + const db = store(k) + db.clear() + }) + }, }