From 80213c5e443a03e1ea8c2d2ff5e68b7990a9004c Mon Sep 17 00:00:00 2001 From: Jack Mallers Date: Tue, 14 Nov 2017 16:27:07 -0600 Subject: [PATCH 1/3] feature(subscribe channel graph): add subscribe channel graph functionality and log output --- app/lnd/subscribe/channelgraph.js | 12 ++++++++++++ app/lnd/subscribe/index.js | 2 ++ app/reducers/channels.js | 10 ++++++++++ app/reducers/ipc.js | 6 +++++- app/routes/channels/components/Channels.js | 2 +- 5 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 app/lnd/subscribe/channelgraph.js diff --git a/app/lnd/subscribe/channelgraph.js b/app/lnd/subscribe/channelgraph.js new file mode 100644 index 00000000..666cd3cf --- /dev/null +++ b/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 })) +} diff --git a/app/lnd/subscribe/index.js b/app/lnd/subscribe/index.js index 170adf60..7ad6e1b8 100644 --- a/app/lnd/subscribe/index.js +++ b/app/lnd/subscribe/index.js @@ -1,7 +1,9 @@ import subscribeToTransactions from './transactions' import subscribeToInvoices from './invoices' +import subscribeToChannelGraph from './channelgraph' export default (mainWindow, lnd) => { subscribeToTransactions(mainWindow, lnd) subscribeToInvoices(mainWindow, lnd) + subscribeToChannelGraph(mainWindow, lnd) } diff --git a/app/reducers/channels.js b/app/reducers/channels.js index d6225ed7..06c01795 100644 --- a/app/reducers/channels.js +++ b/app/reducers/channels.js @@ -181,6 +181,16 @@ export const pushclosechannelstatus = () => (dispatch) => { dispatch(fetchChannels()) } +// IPC event for channel graph data +export const channelGraphData = (event, data) => (dispatch) => { + console.log('channelGraphData: ', data) +} + +// IPC event for channel graph status +export const channelGraphStatus = (event, data) => (dispatch) => { + console.log('channelGraphStatus: ', data) +} + export function toggleFilterPulldown() { return { type: TOGGLE_PULLDOWN diff --git a/app/reducers/ipc.js b/app/reducers/ipc.js index 2afcdff5..c31a0e42 100644 --- a/app/reducers/ipc.js +++ b/app/reducers/ipc.js @@ -17,8 +17,10 @@ import { pushclosechannelupdated, pushclosechannelend, pushclosechannelerror, - pushclosechannelstatus + pushclosechannelstatus, + channelGraphData, + channelGraphStatus } from './channels' import { lightningPaymentUri } from './payform' import { receivePayments, paymentSuccessful, paymentFailed } from './payment' @@ -70,6 +72,8 @@ const ipc = createIpc({ pushclosechannelend, pushclosechannelerror, pushclosechannelstatus, + channelGraphData, + channelGraphStatus, connectSuccess, connectFailure, diff --git a/app/routes/channels/components/Channels.js b/app/routes/channels/components/Channels.js index f46ec7fd..7fbad947 100644 --- a/app/routes/channels/components/Channels.js +++ b/app/routes/channels/components/Channels.js @@ -115,7 +115,7 @@ class Channels extends Component { } -
+
Date: Tue, 14 Nov 2017 22:17:40 -0600 Subject: [PATCH 2/3] feature(notification channel graph): notifications for when you have a new channel opened --- app/reducers/channels.js | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/app/reducers/channels.js b/app/reducers/channels.js index 06c01795..4800f42f 100644 --- a/app/reducers/channels.js +++ b/app/reducers/channels.js @@ -3,6 +3,7 @@ import { ipcRenderer } from 'electron' import { btc } from 'utils' import { closeChannelForm } from './channelform' import { setError } from './error' +import { showNotification } from 'notifications' // ------------------------------------ // Constants // ------------------------------------ @@ -182,8 +183,32 @@ export const pushclosechannelstatus = () => (dispatch) => { } // IPC event for channel graph data -export const channelGraphData = (event, data) => (dispatch) => { +export const channelGraphData = (event, data) => (dispatch, getState) => { + const info = getState().info + + console.log('info: ', info) console.log('channelGraphData: ', data) + const { channelGraphData: { channel_updates } } = data + + // if there are any new channel updates + if (channel_updates.length) { + // 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) { + + 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 From 706cb15a550b0d50052f384d24d6d4c7aec522fd Mon Sep 17 00:00:00 2001 From: Jack Mallers Date: Tue, 14 Nov 2017 22:21:43 -0600 Subject: [PATCH 3/3] feature(fetchNetwork + fetchChannels): fetchNetwork on new network update and fetchChannels on new channel that has to do with the current node --- app/reducers/channels.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/app/reducers/channels.js b/app/reducers/channels.js index 4800f42f..0e70f890 100644 --- a/app/reducers/channels.js +++ b/app/reducers/channels.js @@ -1,6 +1,7 @@ import { createSelector } from 'reselect' import { ipcRenderer } from 'electron' import { btc } from 'utils' +import { fetchDescribeNetwork } from './network' import { closeChannelForm } from './channelform' import { setError } from './error' import { showNotification } from 'notifications' @@ -185,13 +186,13 @@ export const pushclosechannelstatus = () => (dispatch) => { // IPC event for channel graph data export const channelGraphData = (event, data) => (dispatch, getState) => { const info = getState().info - - console.log('info: ', info) - console.log('channelGraphData: ', data) 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] @@ -199,7 +200,11 @@ export const channelGraphData = (event, data) => (dispatch, getState) => { // 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'