From c00eff3a1c8df29640c8a8a33a3d6d670f6fbe29 Mon Sep 17 00:00:00 2001 From: Jack Mallers Date: Mon, 27 Nov 2017 23:30:47 -0600 Subject: [PATCH] fix(main.dev.js): onboarding bugs --- app/containers/Root.js | 5 ++++- app/lnd/methods/index.js | 6 +++++- app/main.dev.js | 40 ++++++++++++++++++++++++++++++---------- app/reducers/info.js | 15 ++++++++++++++- app/reducers/ipc.js | 3 ++- app/reducers/lnd.js | 12 +++++++++++- app/startup/index.js | 21 +++++++++++++++++++++ 7 files changed, 87 insertions(+), 15 deletions(-) create mode 100644 app/startup/index.js diff --git a/app/containers/Root.js b/app/containers/Root.js index 902864ab..b37c37c8 100644 --- a/app/containers/Root.js +++ b/app/containers/Root.js @@ -3,6 +3,7 @@ import React from 'react' import { Provider, connect } from 'react-redux' import { ConnectedRouter } from 'react-router-redux' import { fetchBlockHeight, lndSelectors } from 'reducers/lnd' +import LoadingBolt from 'components/LoadingBolt' import LndSyncing from 'components/LndSyncing' import Routes from '../routes' @@ -30,7 +31,7 @@ class Root extends React.Component { fetchBlockHeight, syncPercentage } = this.props - + if (lnd.syncing) { return ( } + return ( diff --git a/app/lnd/methods/index.js b/app/lnd/methods/index.js index ca2603e2..ca9387b6 100644 --- a/app/lnd/methods/index.js +++ b/app/lnd/methods/index.js @@ -24,6 +24,7 @@ import * as networkController from './networkController' export default function (lnd, event, msg, data) { + console.log('msg: ', msg) switch (msg) { case 'info': networkController.getInfo(lnd) @@ -31,7 +32,10 @@ export default function (lnd, event, msg, data) { event.sender.send('receiveInfo', infoData) event.sender.send('receiveCryptocurrency', infoData.chains[0]) }) - .catch(error => console.log('info error: ', error)) + .catch(error => { + console.log('error: ', error) + event.sender.send('infoFailed') + }) break case 'describeNetwork': networkController.describeGraph(lnd) diff --git a/app/main.dev.js b/app/main.dev.js index 16a3c917..976e57ea 100644 --- a/app/main.dev.js +++ b/app/main.dev.js @@ -24,7 +24,8 @@ const plat = os.platform() const homedir = os.homedir() let mainWindow = null let neutrino = null -let syncing = false + +let didFinishLoad = false let lndPath let certPath @@ -84,7 +85,7 @@ app.on('ready', async () => { icon: icon }) - mainWindow.maximize(); + mainWindow.maximize() mainWindow.loadURL(`file://${__dirname}/app.html`) @@ -98,9 +99,8 @@ app.on('ready', async () => { mainWindow.show() mainWindow.focus() - if (syncing) { - mainWindow.webContents.send('lndSyncing') - } + // now sync and grpc events can be fired to the front end + didFinishLoad = true }) mainWindow.on('closed', () => { @@ -117,9 +117,6 @@ app.on('ready', async () => { // No LND process was found if (!results.length) { - // Let the front end know we have started syncing LND - syncing = true - // Assign path to certs to certPath switch (os.platform()) { case 'darwin': @@ -206,8 +203,7 @@ const startLnd = () => { console.log('NEUTRINO IS SYNCED') // Let the front end know we have stopped syncing LND - syncing = false - mainWindow.webContents.send('lndSynced') + sendLndSynced() } }) } @@ -222,5 +218,29 @@ const startGrpc = () => { ipcMain.on('lnd', (event, { msg, data }) => { lndMethods(event, msg, data) }) + + sendGrpcStarted() }) } + +// Send the front end event letting them know LND is synced to the blockchain +const sendLndSynced = () => { + let sendLndSyncedInterval = setInterval(() => { + if (didFinishLoad) { + clearInterval(sendLndSyncedInterval) + + mainWindow.webContents.send('lndSynced') + } + }, 1000) +} + +// Send the front end event letting them know the gRPC connection has started +const sendGrpcStarted = () => { + let sendGrpcStartedInterval = setInterval(() => { + if (didFinishLoad) { + clearInterval(sendGrpcStartedInterval) + + mainWindow.webContents.send('grpcStarted') + } + }, 1000) +} diff --git a/app/reducers/info.js b/app/reducers/info.js index f87dcce1..c3c0e514 100644 --- a/app/reducers/info.js +++ b/app/reducers/info.js @@ -1,5 +1,7 @@ import { createSelector } from 'reselect' import { ipcRenderer } from 'electron' +import { fetchBalance } from './balance' +import { newAddress } from './address' // ------------------------------------ // Constants // ------------------------------------ @@ -17,12 +19,23 @@ export function getInfo() { // Send IPC event for getinfo export const fetchInfo = () => async (dispatch) => { + console.log('fetching info') dispatch(getInfo()) ipcRenderer.send('lnd', { msg: 'info' }) } // Receive IPC event for info -export const receiveInfo = (event, data) => dispatch => dispatch({ type: RECEIVE_INFO, data }) +export const receiveInfo = (event, data) => dispatch => { + console.log('receiving info and fetching other stuff') + dispatch(fetchBalance()) + dispatch(newAddress('p2pkh')) + dispatch({ type: RECEIVE_INFO, data }) +} + +// IPC info fetch failed +export const infoFailed = (event, data) => dispatch => { + console.log('INFO FAILED data: ', data) +} // ------------------------------------ // Action Handlers diff --git a/app/reducers/ipc.js b/app/reducers/ipc.js index c31a0e42..1b5b8b79 100644 --- a/app/reducers/ipc.js +++ b/app/reducers/ipc.js @@ -1,5 +1,5 @@ import createIpc from 'redux-electron-ipc' -import { lndSyncing, lndSynced, lndStdout } from './lnd' +import { lndSyncing, lndSynced, lndStdout, grpcStarted } from './lnd' import { receiveInfo } from './info' import { receiveAddress } from './address' import { receiveCryptocurrency } from './ticker' @@ -40,6 +40,7 @@ const ipc = createIpc({ lndSyncing, lndSynced, lndStdout, + grpcStarted, receiveInfo, diff --git a/app/reducers/lnd.js b/app/reducers/lnd.js index b59a8f93..9dafffd2 100644 --- a/app/reducers/lnd.js +++ b/app/reducers/lnd.js @@ -14,6 +14,8 @@ export const RECEIVE_LINE = 'RECEIVE_LINE' export const GET_BLOCK_HEIGHT = 'GET_BLOCK_HEIGHT' export const RECEIVE_BLOCK_HEIGHT = 'RECEIVE_BLOCK_HEIGHT' +export const GRPC_STARTED = 'GRPC_STARTED' + // ------------------------------------ // Actions // ------------------------------------ @@ -31,6 +33,11 @@ export const lndSynced = () => (dispatch) => { dispatch({ type: STOP_SYNCING }) } +export const grpcStarted = () => (dispatch) => { + console.log('hello????') + dispatch({ type: GRPC_STARTED }) +} + // Receive IPC event for LND streaming a line export const lndStdout = (event, line) => dispatch => { let height @@ -80,7 +87,9 @@ const ACTION_HANDLERS = { [RECEIVE_LINE]: (state, { lndBlockHeight }) => ({ ...state, lndBlockHeight }), [GET_BLOCK_HEIGHT]: state => ({ ...state, fetchingBlockHeight: true }), - [RECEIVE_BLOCK_HEIGHT]: (state, { blockHeight }) => ({ ...state, blockHeight, fetchingBlockHeight: false }) + [RECEIVE_BLOCK_HEIGHT]: (state, { blockHeight }) => ({ ...state, blockHeight, fetchingBlockHeight: false }), + + [GRPC_STARTED]: state => ({ ...state, grpcStarted: true }) } // ------------------------------------ @@ -88,6 +97,7 @@ const ACTION_HANDLERS = { // ------------------------------------ const initialState = { syncing: false, + grpcStarted: false, fetchingBlockHeight: false, lines: [], blockHeight: 0, diff --git a/app/startup/index.js b/app/startup/index.js new file mode 100644 index 00000000..8c4ee4d2 --- /dev/null +++ b/app/startup/index.js @@ -0,0 +1,21 @@ +// Send the front end event letting them know LND is synced to the blockchain +export const sendLndSynced = (didFinishLoad, mainWindow) => { + let sendLndSyncedInterval = setInterval(() => { + if (didFinishLoad) { + clearInterval(sendLndSyncedInterval) + + mainWindow.webContents.send('lndSynced') + } + }, 1000) +} + +// Send the front end event letting them know the gRPC connection has started +export const sendGrpcStarted = (didFinishLoad, mainWindow) => { + let sendGrpcStartedInterval = setInterval(() => { + if (didFinishLoad) { + clearInterval(sendGrpcStartedInterval) + + mainWindow.webContents.send('grpcStarted') + } + }, 1000) +} \ No newline at end of file