Browse Source

Merge pull request #70 from LN-Zap/feature/subscribe-network

Feature/subscribe network
renovate/lint-staged-8.x
JimmyMow 7 years ago
committed by GitHub
parent
commit
5f389c1936
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 12
      app/lnd/subscribe/channelgraph.js
  2. 2
      app/lnd/subscribe/index.js
  3. 40
      app/reducers/channels.js
  4. 6
      app/reducers/ipc.js
  5. 2
      app/routes/channels/components/Channels.js

12
app/lnd/subscribe/channelgraph.js

@ -0,0 +1,12 @@
/* eslint-disable */
export default function subscribeToChannelGraph(mainWindow, lnd) {
console.log('subscribeChannelGraph is happening')
const call = lnd.subscribeChannelGraph({})
call.on('data', channelGraphData => mainWindow.send('channelGraphData', { channelGraphData }))
call.on('end', () => console.log('channel graph end'))
call.on('error', error => console.log('channelgraph error: ', error))
call.on('status', channelGraphStatus => mainWindow.send('channelGraphStatus', { channelGraphStatus }))
}

2
app/lnd/subscribe/index.js

@ -1,7 +1,9 @@
import subscribeToTransactions from './transactions' import subscribeToTransactions from './transactions'
import subscribeToInvoices from './invoices' import subscribeToInvoices from './invoices'
import subscribeToChannelGraph from './channelgraph'
export default (mainWindow, lnd) => { export default (mainWindow, lnd) => {
subscribeToTransactions(mainWindow, lnd) subscribeToTransactions(mainWindow, lnd)
subscribeToInvoices(mainWindow, lnd) subscribeToInvoices(mainWindow, lnd)
subscribeToChannelGraph(mainWindow, lnd)
} }

40
app/reducers/channels.js

@ -1,8 +1,10 @@
import { createSelector } from 'reselect' import { createSelector } from 'reselect'
import { ipcRenderer } from 'electron' import { ipcRenderer } from 'electron'
import { btc } from 'utils' import { btc } from 'utils'
import { fetchDescribeNetwork } from './network'
import { closeChannelForm } from './channelform' import { closeChannelForm } from './channelform'
import { setError } from './error' import { setError } from './error'
import { showNotification } from 'notifications'
// ------------------------------------ // ------------------------------------
// Constants // Constants
// ------------------------------------ // ------------------------------------
@ -181,6 +183,44 @@ export const pushclosechannelstatus = () => (dispatch) => {
dispatch(fetchChannels()) dispatch(fetchChannels())
} }
// IPC event for channel graph data
export const channelGraphData = (event, data) => (dispatch, getState) => {
const info = getState().info
const { channelGraphData: { channel_updates } } = data
// if there are any new channel updates
if (channel_updates.length) {
// The network has updated, so fetch a new result
dispatch(fetchDescribeNetwork())
// loop through the channel updates
for(let i = 0; i < channel_updates.length; i++) {
let channel_update = channel_updates[i]
let { advertising_node, connecting_node } = channel_update
// if our node is involved in this update we wanna show a notification
if(info.data.identity_pubkey === advertising_node || info.data.identity_pubkey === connecting_node) {
// this channel has to do with the user, lets fetch a new channel list for them
// TODO: full fetch is probably not necessary
dispatch(fetchChannels())
// Construct the notification
let otherParty = info.data.identity_pubkey === advertising_node ? connecting_node : advertising_node
let notifBody = `No new friends, just new channels. Your channel with ${otherParty}` // eslint-disable-line
const notifTitle = 'New channel detected'
// HTML 5 notification for channel updates involving our node
showNotification(notifTitle, notifBody)
}
}
}
}
// IPC event for channel graph status
export const channelGraphStatus = (event, data) => (dispatch) => {
console.log('channelGraphStatus: ', data)
}
export function toggleFilterPulldown() { export function toggleFilterPulldown() {
return { return {
type: TOGGLE_PULLDOWN type: TOGGLE_PULLDOWN

6
app/reducers/ipc.js

@ -17,8 +17,10 @@ import {
pushclosechannelupdated, pushclosechannelupdated,
pushclosechannelend, pushclosechannelend,
pushclosechannelerror, pushclosechannelerror,
pushclosechannelstatus pushclosechannelstatus,
channelGraphData,
channelGraphStatus
} from './channels' } from './channels'
import { lightningPaymentUri } from './payform' import { lightningPaymentUri } from './payform'
import { receivePayments, paymentSuccessful, paymentFailed } from './payment' import { receivePayments, paymentSuccessful, paymentFailed } from './payment'
@ -70,6 +72,8 @@ const ipc = createIpc({
pushclosechannelend, pushclosechannelend,
pushclosechannelerror, pushclosechannelerror,
pushclosechannelstatus, pushclosechannelstatus,
channelGraphData,
channelGraphStatus,
connectSuccess, connectSuccess,
connectFailure, connectFailure,

2
app/routes/channels/components/Channels.js

@ -115,7 +115,7 @@ class Channels extends Component {
} }
</ul> </ul>
</section> </section>
<section className={`${styles.refreshContainer} hint--left`} data-hint='Refresh your peers list'> <section className={`${styles.refreshContainer} hint--left`} data-hint='Refresh your channels list'>
<FaRepeat <FaRepeat
style={{ verticalAlign: 'baseline' }} style={{ verticalAlign: 'baseline' }}
onClick={refreshClicked} onClick={refreshClicked}

Loading…
Cancel
Save