Skip to content
Permalink
Browse files

fix(lnd): prevent duplicate lnd stop actions

  • Loading branch information...
mrfelton committed Apr 24, 2019
1 parent 8c67eff commit 6f1569977b26ef3f927188f2fab8169076c021d1
Showing with 26 additions and 17 deletions.
  1. +24 −17 renderer/reducers/lnd.js
  2. +2 −0 test/unit/reducers/__snapshots__/lnd.spec.js.snap
@@ -22,6 +22,7 @@ export const CLEAR_START_LND_ERROR = 'CLEAR_START_LND_ERROR'

export const STOP_LND = 'STOP_LND'
export const STOP_LND_SUCCESS = 'STOP_LND_SUCCESS'
export const STOP_LND_FAILURE = 'STOP_LND_FAILURE'

export const CREATE_WALLET = 'CREATE_WALLET'
export const CREATE_WALLET_SUCCESS = 'CREATE_WALLET_SUCCESS'
@@ -215,30 +216,28 @@ export const clearStartLndError = () => {
* Stop lnd.
*/
export const stopLnd = () => async (dispatch, getState) => {
const { lndConfig } = getState().lnd
const { isStoppingLnd, lndConfig } = getState().lnd
if (isStoppingLnd) {
return
}

dispatch({ type: STOP_LND })

// Disconnect from the gRPC service.
await dispatch(disconnectGrpcService())
try {
// Disconnect from the gRPC service.
await dispatch(disconnectGrpcService())

// Stop the neutrino process.
if (lndConfig.type === 'local') {
await dispatch(stopNeutrino())
}
// Stop the neutrino process.
if (lndConfig.type === 'local') {
await dispatch(stopNeutrino())
}

dispatch(lndStopped())
dispatch({ type: STOP_LND_SUCCESS })
} catch (error) {
dispatch({ type: STOP_LND_FAILURE, error })
}
}

/**
* Stop lnd success callback.
*
* Called when lnd+neutrino has fully stopped.
*/
export const lndStopped = () => ({
type: STOP_LND_SUCCESS,
})

/**
* Lightning gRPC connect callback.
*
@@ -520,11 +519,19 @@ const ACTION_HANDLERS = {
[STOP_LND]: state => ({
...state,
isStoppingLnd: true,
stopLndError: null,
}),
[STOP_LND_SUCCESS]: state => ({
...state,
isStoppingLnd: false,
isLndActive: false,
stopLndError: null,
}),
[STOP_LND_FAILURE]: (state, { error }) => ({
...state,
isStoppingLnd: false,
isLndActive: false,
stopLndError: error,
}),

[CREATE_WALLET]: state => ({
@@ -137,13 +137,15 @@ Object {
exports[`reducers neutrinoReducer should handle STOP_LND 1`] = `
Object {
"isStoppingLnd": true,
"stopLndError": null,
}
`;

exports[`reducers neutrinoReducer should handle STOP_LND_SUCCESS 1`] = `
Object {
"isLndActive": false,
"isStoppingLnd": false,
"stopLndError": null,
}
`;

0 comments on commit 6f15699

Please sign in to comment.
You can’t perform that action at this time.