Browse Source

fix(main.dev.js): onboarding bugs

renovate/lint-staged-8.x
Jack Mallers 7 years ago
parent
commit
c00eff3a1c
  1. 3
      app/containers/Root.js
  2. 6
      app/lnd/methods/index.js
  3. 40
      app/main.dev.js
  4. 15
      app/reducers/info.js
  5. 3
      app/reducers/ipc.js
  6. 12
      app/reducers/lnd.js
  7. 21
      app/startup/index.js

3
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'
@ -41,6 +42,8 @@ class Root extends React.Component {
)
}
if (!lnd.grpcStarted) { return <LoadingBolt /> }
return (
<Provider store={store}>
<ConnectedRouter history={history}>

6
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)

40
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)
}

15
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

3
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,

12
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,

21
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)
}
Loading…
Cancel
Save