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

Commit

Permalink
fix(home): show connection errors
Browse files Browse the repository at this point in the history
Show a global error if we fail when launching a remote connection.
  • Loading branch information
mrfelton committed Dec 17, 2018
1 parent c5876ad commit a77cab2
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 6 deletions.
9 changes: 9 additions & 0 deletions app/components/Home/Home.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class Home extends React.Component {
activeWalletSettings: PropTypes.object,
deleteWallet: PropTypes.func.isRequired,
lndConnect: PropTypes.object,
startLndHostError: PropTypes.string,
lightningGrpcActive: PropTypes.bool.isRequired,
walletUnlockerGrpcActive: PropTypes.bool.isRequired,
wallets: PropTypes.array.isRequired,
Expand All @@ -31,6 +32,8 @@ class Home extends React.Component {
setActiveWallet: PropTypes.func.isRequired,
unlockWallet: PropTypes.func.isRequired,
setUnlockWalletError: PropTypes.func.isRequired,
setStartLndError: PropTypes.func.isRequired,
setError: PropTypes.func.isRequired,
unlockingWallet: PropTypes.bool,
unlockWalletError: PropTypes.string
}
Expand Down Expand Up @@ -58,9 +61,12 @@ class Home extends React.Component {
activeWallet,
deleteWallet,
startLnd,
startLndHostError,
unlockWallet,
wallets,
setActiveWallet,
setError,
setStartLndError,
stopLnd,
lightningGrpcActive,
walletUnlockerGrpcActive,
Expand Down Expand Up @@ -105,6 +111,9 @@ class Home extends React.Component {
stopLnd={stopLnd}
lightningGrpcActive={lightningGrpcActive}
walletUnlockerGrpcActive={walletUnlockerGrpcActive}
startLndHostError={startLndHostError}
setError={setError}
setStartLndError={setStartLndError}
deleteWallet={deleteWallet}
key={wallet.id}
/>
Expand Down
19 changes: 18 additions & 1 deletion app/components/Home/WalletLauncher.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ class WalletLauncher extends React.Component {
startLnd: PropTypes.func.isRequired,
lightningGrpcActive: PropTypes.bool.isRequired,
walletUnlockerGrpcActive: PropTypes.bool.isRequired,
startLndHostError: PropTypes.string,
setStartLndError: PropTypes.func.isRequired,
setError: PropTypes.func.isRequired,
stopLnd: PropTypes.func.isRequired,
history: PropTypes.shape({
push: PropTypes.func.isRequired
Expand All @@ -29,7 +32,21 @@ class WalletLauncher extends React.Component {
* Redirect to the login page when we establish a connection to lnd.
*/
componentDidUpdate(prevProps) {
const { history, lightningGrpcActive, walletUnlockerGrpcActive, wallet } = this.props
const {
history,
lightningGrpcActive,
walletUnlockerGrpcActive,
startLndHostError,
setError,
setStartLndError,
wallet
} = this.props

// If the wallet unlocker became active, switch to the login screen
if (startLndHostError && !prevProps.startLndHostError) {
setError(startLndHostError)
setStartLndError(null)
}

// If the wallet unlocker became active, switch to the login screen
if (walletUnlockerGrpcActive && !prevProps.walletUnlockerGrpcActive) {
Expand Down
14 changes: 12 additions & 2 deletions app/containers/Home.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import { connect } from 'react-redux'
import { setActiveWallet, walletSelectors, deleteWallet } from 'reducers/wallet'
import { setUnlockWalletError, stopLnd, startLnd, unlockWallet } from 'reducers/lnd'
import {
setUnlockWalletError,
stopLnd,
startLnd,
unlockWallet,
setStartLndError
} from 'reducers/lnd'
import { setError } from 'reducers/error'
import { Home } from 'components/Home'

const mapStateToProps = state => ({
Expand All @@ -10,17 +17,20 @@ const mapStateToProps = state => ({
activeWalletSettings: walletSelectors.activeWalletSettings(state),
lightningGrpcActive: state.lnd.lightningGrpcActive,
walletUnlockerGrpcActive: state.lnd.walletUnlockerGrpcActive,
startLndHostError: state.lnd.startLndHostError,
unlockingWallet: state.lnd.unlockingWallet,
unlockWalletError: state.lnd.unlockWalletError
})

const mapDispatchToProps = {
setActiveWallet,
setUnlockWalletError,
setStartLndError,
stopLnd,
startLnd,
unlockWallet,
deleteWallet
deleteWallet,
setError
}

export default connect(
Expand Down
6 changes: 3 additions & 3 deletions app/reducers/lnd.js
Original file line number Diff line number Diff line change
Expand Up @@ -377,9 +377,9 @@ const ACTION_HANDLERS = {
[SET_START_LND_ERROR]: (state, { errors }) => ({
...state,
startingLnd: false,
startLndHostError: errors.host,
startLndCertError: errors.cert,
startLndMacaroonError: errors.macaroon
startLndHostError: errors ? errors.host : '',
startLndCertError: errors ? errors.cert : '',
startLndMacaroonError: errors ? errors.macaroon : ''
}),

[SET_WALLET_UNLOCKER_ACTIVE]: state => ({
Expand Down

0 comments on commit a77cab2

Please sign in to comment.