From 80fd495445f553ca187c68ef51adefdccd91c0a4 Mon Sep 17 00:00:00 2001 From: Jack Mallers Date: Tue, 14 Nov 2017 22:17:40 -0600 Subject: [PATCH] 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