|
|
@ -1,6 +1,7 @@ |
|
|
|
import { fetchTicker } from './ticker' |
|
|
|
import { fetchBalance } from './balance' |
|
|
|
import { fetchInfo } from './info' |
|
|
|
import { requestBlockHeight } from '../api' |
|
|
|
// ------------------------------------
|
|
|
|
// Constants
|
|
|
|
// ------------------------------------
|
|
|
@ -9,6 +10,9 @@ export const STOP_SYNCING = 'STOP_SYNCING' |
|
|
|
|
|
|
|
export const RECEIVE_LINE = 'RECEIVE_LINE' |
|
|
|
|
|
|
|
export const GET_BLOCK_HEIGHT = 'GET_BLOCK_HEIGHT' |
|
|
|
export const RECEIVE_BLOCK_HEIGHT = 'RECEIVE_BLOCK_HEIGHT' |
|
|
|
|
|
|
|
// ------------------------------------
|
|
|
|
// Actions
|
|
|
|
// ------------------------------------
|
|
|
@ -27,7 +31,30 @@ export const lndSynced = () => dispatch => { |
|
|
|
} |
|
|
|
|
|
|
|
// Receive IPC event for LND streaming a line
|
|
|
|
export const lndStdout = (event, line) => dispatch => dispatch({ type: RECEIVE_LINE, line }) |
|
|
|
export const lndStdout = (event, lndBlockHeight) => dispatch => { |
|
|
|
dispatch({ type: RECEIVE_LINE, lndBlockHeight: lndBlockHeight.split(' ')[0].split(/(\r\n|\n|\r)/gm)[0] }) |
|
|
|
} |
|
|
|
|
|
|
|
export function getBlockHeight() { |
|
|
|
return { |
|
|
|
type: GET_BLOCK_HEIGHT |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
export function receiveBlockHeight(blockHeight) { |
|
|
|
return { |
|
|
|
type: RECEIVE_BLOCK_HEIGHT, |
|
|
|
blockHeight |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// Fetch current block height
|
|
|
|
export const fetchBlockHeight = () => async (dispatch) => { |
|
|
|
dispatch(getBlockHeight()) |
|
|
|
const blockData = await requestBlockHeight() |
|
|
|
console.log('blockHeight: ', blockData.blocks[0].height) |
|
|
|
dispatch(receiveBlockHeight(blockData.blocks[0].height)) |
|
|
|
} |
|
|
|
|
|
|
|
// ------------------------------------
|
|
|
|
// Action Handlers
|
|
|
@ -36,7 +63,10 @@ const ACTION_HANDLERS = { |
|
|
|
[START_SYNCING]: state => ({ ...state, syncing: true }), |
|
|
|
[STOP_SYNCING]: state => ({ ...state, syncing: false }), |
|
|
|
|
|
|
|
[RECEIVE_LINE]: (state, { line }) => ({ ...state, lines: [...state.lines, line] }), |
|
|
|
[RECEIVE_LINE]: (state, { lndBlockHeight }) => ({ ...state, lndBlockHeight }), |
|
|
|
|
|
|
|
[GET_BLOCK_HEIGHT]: state => ({ ...state, fetchingBlockHeight: true }), |
|
|
|
[RECEIVE_BLOCK_HEIGHT]: (state, { blockHeight }) => ({ ...state, blockHeight, fetchingBlockHeight: false }), |
|
|
|
} |
|
|
|
|
|
|
|
// ------------------------------------
|
|
|
@ -44,7 +74,10 @@ const ACTION_HANDLERS = { |
|
|
|
// ------------------------------------
|
|
|
|
const initialState = { |
|
|
|
syncing: false, |
|
|
|
lines: [] |
|
|
|
fetchingBlockHeight: false, |
|
|
|
lines: [], |
|
|
|
blockHeight: 0, |
|
|
|
lndBlockHeight: 0 |
|
|
|
} |
|
|
|
|
|
|
|
export default function lndReducer(state = initialState, action) { |
|
|
|