Browse Source

feature(channels): channel network map working

renovate/lint-staged-8.x
Jack Mallers 7 years ago
parent
commit
ede5c64e91
  1. 8
      app/components/Network/ChannelsList.js
  2. 45
      app/components/Network/NetworkGraph.js
  3. 8
      app/components/Network/NetworkGraph.scss
  4. 34
      app/reducers/network.js
  5. 5
      app/routes/network/components/Network.js
  6. 5
      app/routes/network/containers/NetworkContainer.js

8
app/components/Network/ChannelsList.js

@ -4,12 +4,12 @@ import PropTypes from 'prop-types'
import { btc } from 'utils' import { btc } from 'utils'
import styles from './ChannelsList.scss' import styles from './ChannelsList.scss'
const ChannelsList = ({ channels }) => ( const ChannelsList = ({ channels, updateSelectedChannels, selectedChannelIds }) => (
<ul className={styles.channels}> <ul className={styles.channels}>
{ {
channels.map((channel, index) => channels.map(channel =>
<li key={index} className={styles.channel} onClick={() => console.log('channel clicked')}> <li key={channel.chan_id} className={styles.channel} onClick={() => updateSelectedChannels(channel)}>
<span className={`${styles.dot}`} /> <span className={`${styles.dot} ${selectedChannelIds.includes(channel.chan_id) && styles.active}`} />
<header> <header>
<h1>Capacity: {btc.satoshisToBtc(channel.capacity)}</h1> <h1>Capacity: {btc.satoshisToBtc(channel.capacity)}</h1>

45
app/components/Network/NetworkGraph.js

@ -23,6 +23,7 @@ class NetworkGraph extends Component {
const { const {
network: { nodes, edges, selectedChannel, networkLoading }, network: { nodes, edges, selectedChannel, networkLoading },
selectedPeerPubkeys, selectedPeerPubkeys,
selectedChannelIds,
identity_pubkey, identity_pubkey,
} = this.props } = this.props
@ -36,6 +37,7 @@ class NetworkGraph extends Component {
) )
} }
console.log('selectedChannelIds: ', selectedChannelIds)
return ( return (
<section className={styles.network}> <section className={styles.network}>
<ForceGraph <ForceGraph
@ -55,31 +57,28 @@ class NetworkGraph extends Component {
zoom zoom
> >
{ {
nodes.map(node => { nodes.map(node =>
return ( <ForceGraphNode
<ForceGraphNode r={25}
r={25} label={node.pub_key}
label={node.pub_key} key={node.pub_key}
key={node.pub_key} node={{ id: node.pub_key }}
node={{ id: node.pub_key }} fill={selectedPeerPubkeys.includes(node.pub_key) ? '#5589F3' : '#353535'}
fill={selectedPeerPubkeys.includes(node.pub_key) ? '#5589F3' : '#353535'} strokeWidth={2.5}
strokeWidth={2.5} className={styles.node}
className={styles.node} />
/> )
)
})
} }
{ {
edges.map(edge => { edges.map(edge =>
return ( <ForceGraphLink
<ForceGraphLink className={selectedChannelIds.includes(edge.channel_id) && styles.activeEdge}
key={edge.channel_id} key={edge.channel_id}
link={{ source: edge.node1_pub, target: edge.node2_pub }} link={{ source: edge.node1_pub, target: edge.node2_pub }}
stroke='silver' stroke='silver'
strokeWidth='5' strokeWidth='5'
/> />
) )
})
} }
</ForceGraph> </ForceGraph>
</section> </section>

8
app/components/Network/NetworkGraph.scss

@ -52,6 +52,14 @@
stroke-width: 2 !important; stroke-width: 2 !important;
} }
.activeEdge {
opacity: 1;
stroke: #88D4A2;
stroke-width: 5;
stroke-dasharray: 100;
animation: dash 2.5s infinite linear;
}
.network { .network {
display: inline-block; display: inline-block;
vertical-align: top; vertical-align: top;

34
app/reducers/network.js

@ -22,6 +22,8 @@ export const UPDATE_PAY_REQ = 'UPDATE_PAY_REQ'
export const UPDATE_SELECTED_PEERS = 'UPDATE_SELECTED_PEERS' export const UPDATE_SELECTED_PEERS = 'UPDATE_SELECTED_PEERS'
export const UPDATE_SELECTED_CHANNELS = 'UPDATE_SELECTED_CHANNELS'
// ------------------------------------ // ------------------------------------
// Actions // Actions
// ------------------------------------ // ------------------------------------
@ -80,6 +82,13 @@ export function updateSelectedPeers(peer) {
} }
} }
export function updateSelectedChannels(channel) {
return {
type: UPDATE_SELECTED_CHANNELS,
channel
}
}
// Send IPC event for describeNetwork // Send IPC event for describeNetwork
export const fetchDescribeNetwork = () => (dispatch) => { export const fetchDescribeNetwork = () => (dispatch) => {
dispatch(getDescribeNetwork()) dispatch(getDescribeNetwork())
@ -141,6 +150,22 @@ const ACTION_HANDLERS = {
return { return {
...state, selectedPeers ...state, selectedPeers
} }
},
[UPDATE_SELECTED_CHANNELS]: (state, { channel }) => {
let selectedChannels
if (state.selectedChannels.includes(channel)) {
selectedChannels = state.selectedChannels.filter(selectedChannel => selectedChannel.chan_id !== channel.chan_id)
}
if (!state.selectedChannels.includes(channel)) {
selectedChannels = [...state.selectedChannels, channel]
}
return {
...state, selectedChannels
}
} }
} }
@ -150,6 +175,7 @@ const ACTION_HANDLERS = {
const networkSelectors = {} const networkSelectors = {}
const currentRouteSelector = state => state.network.selectedNode.currentRoute const currentRouteSelector = state => state.network.selectedNode.currentRoute
const selectedPeers = state => state.network.selectedPeers const selectedPeers = state => state.network.selectedPeers
const selectedChannels = state => state.network.selectedChannels
networkSelectors.currentRouteHopChanIds = createSelector( networkSelectors.currentRouteHopChanIds = createSelector(
currentRouteSelector, currentRouteSelector,
@ -165,6 +191,11 @@ networkSelectors.selectedPeerPubkeys = createSelector(
peers => peers.map(peer => peer.pub_key) peers => peers.map(peer => peer.pub_key)
) )
networkSelectors.selectedChannelIds = createSelector(
selectedChannels,
channels => channels.map(channel => channel.chan_id)
)
export { networkSelectors } export { networkSelectors }
// ------------------------------------ // ------------------------------------
@ -187,7 +218,8 @@ const initialState = {
pay_req: '', pay_req: '',
selectedPeers: [] selectedPeers: [],
selectedChannels: []
} }

5
app/routes/network/components/Network.js

@ -29,6 +29,8 @@ class Network extends Component {
peers: { peers }, peers: { peers },
activeChannels, activeChannels,
selectedChannelIds,
updateSelectedChannels,
identity_pubkey identity_pubkey
} = this.props } = this.props
@ -39,7 +41,7 @@ class Network extends Component {
return <PeersList peers={peers} updateSelectedPeers={updateSelectedPeers} selectedPeerPubkeys={selectedPeerPubkeys} /> return <PeersList peers={peers} updateSelectedPeers={updateSelectedPeers} selectedPeerPubkeys={selectedPeerPubkeys} />
break break
case 2: case 2:
return <ChannelsList channels={activeChannels} /> return <ChannelsList channels={activeChannels} updateSelectedChannels={updateSelectedChannels} selectedChannelIds={selectedChannelIds} />
break break
case 3: case 3:
return <h1>transactions</h1> return <h1>transactions</h1>
@ -54,6 +56,7 @@ class Network extends Component {
network={network} network={network}
identity_pubkey={identity_pubkey} identity_pubkey={identity_pubkey}
selectedPeerPubkeys={selectedPeerPubkeys} selectedPeerPubkeys={selectedPeerPubkeys}
selectedChannelIds={selectedChannelIds}
/> />
<section className={styles.toolbox}> <section className={styles.toolbox}>

5
app/routes/network/containers/NetworkContainer.js

@ -6,6 +6,7 @@ import {
setCurrentTab, setCurrentTab,
updateSelectedPeers, updateSelectedPeers,
updateSelectedChannels,
networkSelectors networkSelectors
} from '../../../reducers/network' } from '../../../reducers/network'
@ -21,7 +22,8 @@ const mapDispatchToProps = {
fetchPeers, fetchPeers,
fetchChannels fetchChannels,
updateSelectedChannels
} }
const mapStateToProps = state => ({ const mapStateToProps = state => ({
@ -30,6 +32,7 @@ const mapStateToProps = state => ({
identity_pubkey: state.info.data.identity_pubkey, identity_pubkey: state.info.data.identity_pubkey,
selectedPeerPubkeys: networkSelectors.selectedPeerPubkeys(state), selectedPeerPubkeys: networkSelectors.selectedPeerPubkeys(state),
selectedChannelIds: networkSelectors.selectedChannelIds(state),
activeChannels: channelsSelectors.activeChannels(state) activeChannels: channelsSelectors.activeChannels(state)
}) })

Loading…
Cancel
Save