import React, { Component } from 'react' import PropTypes from 'prop-types' import find from 'lodash/find' import Isvg from 'react-inlinesvg' import { FaAngleDown, FaCircle, FaRepeat } from 'react-icons/lib/fa' import { btc } from 'utils' import plus from 'icons/plus.svg' import search from 'icons/search.svg' import styles from './Network.scss' class Network extends Component { constructor(props) { super(props) this.state = { refreshing: false } } render() { const { channels: { searchQuery, filterPulldown, filter, loadingChannelPubkeys, // closingChannelIds }, currentChannels, balance, currentTicker, nodes, fetchChannels, openContactsForm, nonActiveFilters, toggleFilterPulldown, changeFilter, updateChannelSearchQuery, openContactModal } = this.props const refreshClicked = () => { // turn the spinner on this.setState({ refreshing: true }) // store event in icon so we dont get an error when react clears it const icon = this.repeat.childNodes // fetch channels fetchChannels() // wait for the svg to appear as child const svgTimeout = setTimeout(() => { if (icon[0].tagName === 'svg') { // spin icon for 1 sec icon[0].style.animation = 'spin 1000ms linear 1' clearTimeout(svgTimeout) } }, 1) // clear animation after the second so we can reuse it const refreshTimeout = setTimeout(() => { icon[0].style.animation = '' this.setState({ refreshing: false }) clearTimeout(refreshTimeout) }, 1000) } const displayNodeName = (channel) => { const node = find(nodes, n => channel.remote_pubkey === n.pub_key) if (node && node.alias.length) { return node.alias } return channel.remote_pubkey ? channel.remote_pubkey.substring(0, 10) : channel.remote_node_pub.substring(0, 10) } const channelStatus = (channel) => { // if the channel has a confirmation_height property that means it's pending if (Object.prototype.hasOwnProperty.call(channel, 'confirmation_height')) { return 'pending' } // if the channel has a closing tx that means it's closing if (Object.prototype.hasOwnProperty.call(channel, 'closing_txid')) { return 'closing' } // if the channel isn't active that means the remote peer isn't online if (!channel.active) { return 'offline' } // if all of the above conditionals fail we can assume the node is online :) return 'online' } const usdAmount = btc.satoshisToUsd(balance.channelBalance, currentTicker.price_usd) return (