<commit_before>import { DescriptionHeader } from "layout";
import { FormattedMessage as T } from "react-intl";
import { lnPage } from "connectors";
import Page from "./Page";

export const ChannelsTabHeader = () =>
  <DescriptionHeader
    description={<T id="ln.description.channels" m="Open and pending channels of this LN Wallet" />}
  />;

@autobind
class ChannelsTab extends React.Component {
  constructor(props)  {
    super(props);
    this.state = {
      node: "",
      localAmt: 0,
      localAmtAtoms: 0,
      pushAmt: 0,
      pushAmtAtoms: 0,
      canOpen: false,
      opening: false
    };
  }

  onNodeChanged(e) {
    const canOpen = e.target.value && this.state.localAmt > 0;
    this.setState({ node: (""+e.target.value).trim(), canOpen });
  }

  onLocalAmtChanged({ value, atomValue }) {
    const canOpen = atomValue > 0 && this.state.node;
    this.setState({ localAmt: value, localAmtAtoms: atomValue, canOpen });
  }

  onPushAmtChanged({ value, atomValue }) {
    this.setState({ pushAmt: value, pushAmtAtoms: atomValue });
  }

  onOpenChannel() {
    const { node, localAmtAtoms, pushAmtAtoms } = this.state;
    if (!node || !localAmtAtoms) {
      return;
    }
    this.setState({ opening: true });
    this.props.openChannel(node, localAmtAtoms, pushAmtAtoms).then(() => {
      this.setState({ opening: false, node: "", localAmt: 0, pushAmt: 0,
        localAmtAtoms: 0, pushAmtAtoms: 0 });
    }).catch(() => {
      this.setState({ opening: false });
    });
  }

  onCloseChannel(channel) {
    this.props.closeChannel(channel.channelPoint, !channel.active);
  }

  onToggleChannelDetails(channel) {
    if (this.state.detailedChannel === channel) {
      this.setState({ detailedChannel: null });
    } else {
      this.setState({ detailedChannel: channel });
    }
  }

  render() {
    const { balance, pendingOpenBalance, maxInboundAmount,
      maxOutboundAmount } = this.props.channelBalances;

    const { channels, pendingChannels, closedChannels, isMainNet } = this.props;
    const { node, localAmt, pushAmt, opening, canOpen,
      detailedChannel } = this.state;
    const { onNodeChanged, onLocalAmtChanged, onPushAmtChanged,
      onOpenChannel, onCloseChannel, onToggleChannelDetails } = this;

    return (
      <Page
        balance={balance}
        pendingOpenBalance={pendingOpenBalance}
        maxInboundAmount={maxInboundAmount}
        maxOutboundAmount={maxOutboundAmount}
        channels={channels}
        pendingChannels={pendingChannels}
        closedChannels={closedChannels}
        node={node}
        localAmt={localAmt}
        pushAmt={pushAmt}
        opening={opening}
        canOpen={canOpen}
        detailedChannel={detailedChannel}
        testnet={isMainNet}
        onNodeChanged={onNodeChanged}
        onLocalAmtChanged={onLocalAmtChanged}
        onPushAmtChanged={onPushAmtChanged}<commit_msg>[ln] Fix testnet/mainnet attr (#2353)<commit_after>import { DescriptionHeader } from "layout";
import { FormattedMessage as T } from "react-intl";
import { lnPage } from "connectors";
import Page from "./Page";

export const ChannelsTabHeader = () =>
  <DescriptionHeader
    description={<T id="ln.description.channels" m="Open and pending channels of this LN Wallet" />}
  />;

@autobind
class ChannelsTab extends React.Component {
  constructor(props)  {
    super(props);
    this.state = {
      node: "",
      localAmt: 0,
      localAmtAtoms: 0,
      pushAmt: 0,
      pushAmtAtoms: 0,
      canOpen: false,
      opening: false
    };
  }

  onNodeChanged(e) {
    const canOpen = e.target.value && this.state.localAmt > 0;
    this.setState({ node: (""+e.target.value).trim(), canOpen });
  }

  onLocalAmtChanged({ value, atomValue }) {
    const canOpen = atomValue > 0 && this.state.node;
    this.setState({ localAmt: value, localAmtAtoms: atomValue, canOpen });
  }

  onPushAmtChanged({ value, atomValue }) {
    this.setState({ pushAmt: value, pushAmtAtoms: atomValue });
  }

  onOpenChannel() {
    const { node, localAmtAtoms, pushAmtAtoms } = this.state;
    if (!node || !localAmtAtoms) {
      return;
    }
    this.setState({ opening: true });
    this.props.openChannel(node, localAmtAtoms, pushAmtAtoms).then(() => {
      this.setState({ opening: false, node: "", localAmt: 0, pushAmt: 0,
        localAmtAtoms: 0, pushAmtAtoms: 0 });
    }).catch(() => {
      this.setState({ opening: false });
    });
  }

  onCloseChannel(channel) {
    this.props.closeChannel(channel.channelPoint, !channel.active);
  }

  onToggleChannelDetails(channel) {
    if (this.state.detailedChannel === channel) {
      this.setState({ detailedChannel: null });
    } else {
      this.setState({ detailedChannel: channel });
    }
  }

  render() {
    const { balance, pendingOpenBalance, maxInboundAmount,
      maxOutboundAmount } = this.props.channelBalances;

    const { channels, pendingChannels, closedChannels, isMainNet } = this.props;
    const { node, localAmt, pushAmt, opening, canOpen,
      detailedChannel } = this.state;
    const { onNodeChanged, onLocalAmtChanged, onPushAmtChanged,
      onOpenChannel, onCloseChannel, onToggleChannelDetails } = this;

    return (
      <Page
        balance={balance}
        pendingOpenBalance={pendingOpenBalance}
        maxInboundAmount={maxInboundAmount}
        maxOutboundAmount={maxOutboundAmount}
        channels={channels}
        pendingChannels={pendingChannels}
        closedChannels={closedChannels}
        node={node}
        localAmt={localAmt}
        pushAmt={pushAmt}
        opening={opening}
        canOpen={canOpen}
        detailedChannel={detailedChannel}
        isMainNet={isMainNet}
        onNodeChanged={onNodeChanged}
        onLocalAmtChanged={onLocalAmtChanged}
        onPushAmtChanged={onPushAmtChanged}
{'fraction_non_alphanumeric': 0.12525879917184266, 'fraction_numerical': 0.004140786749482402, 'mean_word_length': 3.2313868613138688, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2643901', 'n_tokens_mistral': 1834, 'n_tokens_neox': 1807, 'n_words': 361}