You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
1.5 KiB
55 lines
1.5 KiB
7 years ago
|
import { fetchTicker } from './ticker'
|
||
|
import { fetchBalance } from './balance'
|
||
|
import { fetchInfo } from './info'
|
||
|
// ------------------------------------
|
||
|
// Constants
|
||
|
// ------------------------------------
|
||
|
export const START_SYNCING = 'START_SYNCING'
|
||
|
export const STOP_SYNCING = 'STOP_SYNCING'
|
||
|
|
||
|
export const RECEIVE_LINE = 'RECEIVE_LINE'
|
||
|
|
||
|
// ------------------------------------
|
||
|
// Actions
|
||
|
// ------------------------------------
|
||
|
|
||
|
// Receive IPC event for LND starting its syncing process
|
||
|
export const lndSyncing = () => dispatch => dispatch({ type: START_SYNCING })
|
||
|
|
||
|
// Receive IPC event for LND stoping sync
|
||
|
export const lndSynced = () => dispatch => {
|
||
|
// Fetch data now that we know LND is synced
|
||
|
fetchTicker()
|
||
|
fetchBalance()
|
||
|
fetchInfo()
|
||
|
|
||
|
dispatch({ type: STOP_SYNCING })
|
||
|
}
|
||
|
|
||
|
// Receive IPC event for LND streaming a line
|
||
|
export const lndStdout = (event, line) => dispatch => dispatch({ type: RECEIVE_LINE, line })
|
||
|
|
||
|
// ------------------------------------
|
||
|
// Action Handlers
|
||
|
// ------------------------------------
|
||
|
const ACTION_HANDLERS = {
|
||
|
[START_SYNCING]: state => ({ ...state, syncing: true }),
|
||
|
[STOP_SYNCING]: state => ({ ...state, syncing: false }),
|
||
|
|
||
|
[RECEIVE_LINE]: (state, { line }) => ({ ...state, lines: [...state.lines, line] }),
|
||
|
}
|
||
|
|
||
|
// ------------------------------------
|
||
|
// Reducer
|
||
|
// ------------------------------------
|
||
|
const initialState = {
|
||
|
syncing: false,
|
||
|
lines: []
|
||
|
}
|
||
|
|
||
|
export default function lndReducer(state = initialState, action) {
|
||
|
const handler = ACTION_HANDLERS[action.type]
|
||
|
|
||
|
return handler ? handler(state, action) : state
|
||
|
}
|