Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Commit

Permalink
fix(lnd): show error on problem connecting to lnd
Browse files Browse the repository at this point in the history
If there is a problem connecting to the Lightning interface on a local
lnd instance, return the user to the onboarding screen and show the
user the error message.

Previously, the app would hang on an infinite loading screen.
  • Loading branch information
Tom Kirkpatrick committed Oct 1, 2018
1 parent 88fcf75 commit 0660801
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 8 deletions.
19 changes: 18 additions & 1 deletion app/containers/Root.js
Expand Up @@ -4,6 +4,9 @@ import { ConnectedRouter } from 'react-router-redux'
import { Switch, Route } from 'react-router'
import PropTypes from 'prop-types'
import { hot } from 'react-hot-loader'
import GlobalError from 'components/GlobalError'

import { clearError } from 'reducers/error'

import {
setConnectionType,
Expand Down Expand Up @@ -40,6 +43,7 @@ import App from './App'
import Activity from './Activity'

const mapDispatchToProps = {
clearError,
setConnectionType,
setConnectionString,
setConnectionHost,
Expand Down Expand Up @@ -73,6 +77,7 @@ const mapStateToProps = state => ({
theme: state.settings.theme,
balance: state.balance,
currentTicker: tickerSelectors.currentTicker(state),
error: state.error,
syncPercentage: lndSelectors.syncPercentage(state),
passwordIsValid: onboardingSelectors.passwordIsValid(state),
passwordMinCharsError: onboardingSelectors.passwordMinCharsError(state),
Expand Down Expand Up @@ -218,7 +223,16 @@ class Root extends Component {
}

render() {
const { balance, currentTicker, history, lnd, onboardingProps, syncingProps } = this.props
const {
balance,
clearError,
currentTicker,
error: { error },
history,
lnd,
onboardingProps,
syncingProps
} = this.props

if (!onboardingProps.onboarding.onboarded) {
return (
Expand All @@ -227,6 +241,7 @@ class Root extends Component {
theme={onboardingProps.theme}
visible={!onboardingProps.onboarding.onboarding}
/>
<GlobalError error={error} clearError={clearError} />
<Onboarding {...onboardingProps} />
<Syncing {...syncingProps} />
</div>
Expand Down Expand Up @@ -267,6 +282,8 @@ class Root extends Component {

Root.propTypes = {
balance: PropTypes.object.isRequired,
clearError: PropTypes.func.isRequired,
error: PropTypes.object.isRequired,
fetchTicker: PropTypes.func.isRequired,
currentTicker: PropTypes.object,
history: PropTypes.object.isRequired,
Expand Down
19 changes: 13 additions & 6 deletions app/lib/zap/controller.js
Expand Up @@ -187,6 +187,10 @@ class ZapController {
else if (e.code === 'LND_GRPC_MACAROON_ERROR') {
errors.macaroon = e.message
}
// Other error codes such as UNAVAILABLE most likely indicate that there is a problem with the host.
else {
errors.host = `Unable to connect to host: ${e.details || e.message}`
}

// The `startLightningWallet` call attempts to call the `getInfo` method on the Lightning service in order to
// verify that it is accessible. If it is not, an error 12 is throw whcih is the gRPC code for `UNIMPLEMENTED`
Expand All @@ -196,11 +200,6 @@ class ZapController {
return this.startWalletUnlocker()
}

// Other error codes such as UNAVAILABLE most likely indicate that there is a problem with the host.
else {
errors.host = `Unable to connect to host: ${e.details || e.message}`
}

// Notify the app of errors.
this.sendMessage('startLndError', errors)
throw e
Expand Down Expand Up @@ -436,7 +435,15 @@ class ZapController {
*/
_registerIpcListeners() {
ipcMain.on('startLnd', (event, options: onboardingOptions) => this.finishOnboarding(options))
ipcMain.on('startLightningWallet', () => this.startLightningWallet())
ipcMain.on('startLightningWallet', () =>
this.startLightningWallet().catch(e => {
// Notify the app of errors.
this.sendMessage('startLndError', e.message)

// Return back to the start of the onboarding process.
return this.startOnboarding()
})
)
}

/**
Expand Down
8 changes: 7 additions & 1 deletion app/reducers/onboarding.js
Expand Up @@ -2,6 +2,7 @@ import { createSelector } from 'reselect'
import { ipcRenderer } from 'electron'
import get from 'lodash.get'
import { fetchInfo } from './info'
import { setError } from './error'

// ------------------------------------
// Constants
Expand Down Expand Up @@ -292,14 +293,19 @@ export const startOnboarding = (event, lndConfig = {}) => dispatch => {

// Listener for errors connecting to LND gRPC
export const startLndError = (event, errors) => (dispatch, getState) => {
dispatch(setStartLndError(errors))
const connectionType = connectionTypeSelector(getState())

switch (connectionType) {
case 'local':
dispatch(setError(errors))
dispatch({ type: CHANGE_STEP, step: 0.1 })
break
case 'custom':
dispatch(setStartLndError(errors))
dispatch({ type: CHANGE_STEP, step: 0.2 })
break
case 'btcpayserver':
dispatch(setStartLndError(errors))
dispatch({ type: CHANGE_STEP, step: 0.3 })
break
}
Expand Down

0 comments on commit 0660801

Please sign in to comment.