{"size": 2826, "ext": "js", "max_stars_repo_path": "src/App/Send/index.js", "max_stars_repo_name": "LinuxDevSecOps/NexusInterface", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/App/Send/index.js", "max_issues_repo_name": "LinuxDevSecOps/NexusInterface", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/App/Send/index.js", "max_forks_repo_name": "LinuxDevSecOps/NexusInterface", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 22.9756097561, "max_line_length": 73, "alphanum_fraction": 0.6213729653}
// External Dependencies
import React, { Component } from 'react';
import { connect } from 'react-redux';
import { remote } from 'electron';

// Internal Global Dependencies
import GA from 'lib/googleAnalytics';
import ContextMenuBuilder from 'contextmenu';
import Icon from 'components/Icon';
import Panel from 'components/Panel';
import Button from 'components/Button';
import WaitingMessage from 'components/WaitingMessage';
import Tooltip from 'components/Tooltip';
import { openModal } from 'actions/overlays';
import { isCoreConnected } from 'selectors';

// Internal Local Dependencies
import MoveBetweenAccountsModal from './MoveBetweenAccountsModal';
import SendForm from './SendForm';

// Resources
import sendIcon from 'images/send.sprite.svg';
import swapIcon from 'images/swap.sprite.svg';

const mapStateToProps = state => ({
  coreConnected: isCoreConnected(state),
});

const actionCreators = { openModal };

/**
 * Send Page
 *
 * @class Send
 * @extends {Component}
 */
@connect(
  mapStateToProps,
  actionCreators
)
class Send extends Component {
  /**
   * Component Mount Callback
   *
   * @memberof Send
   */
  componentDidMount() {
    window.addEventListener('contextmenu', this.setupcontextmenu, false);
    GA.SendScreen('Send');
  }

  /**
   * Component Unmount Callback
   *
   * @memberof Send
   */
  componentWillUnmount() {
    window.removeEventListener('contextmenu', this.setupcontextmenu);
  }

  /**
   * Set up the context menu
   *
   * @param {*} e
   * @memberof Send
   */
  setupcontextmenu(e) {
    e.preventDefault();
    const contextmenu = new ContextMenuBuilder().defaultContext;
    //build default
    let defaultcontextmenu = remote.Menu.buildFromTemplate(contextmenu);
    defaultcontextmenu.popup(remote.getCurrentWindow());
  }

  /**
   * Opens the Move NXS between account modal
   *
   * @memberof Send
   */
  moveBetweenAccounts = () => {
    this.props.openModal(MoveBetweenAccountsModal);
  };

  /**
   * Component's Renderable JSX
   *
   * @returns
   * @memberof Send
   */
  render() {
    return (
      <Panel
        icon={sendIcon}
        title={__('Send NXS')}
        controls={
          this.props.coreConnected && (
            <Tooltip.Trigger tooltip={__('Move NXS between accounts')}>
              <Button
                square
                skin="primary"
                className="relative"
                onClick={this.moveBetweenAccounts}
              >
                <Icon icon={swapIcon} />
              </Button>
            </Tooltip.Trigger>
          )
        }
      >
        {!this.props.coreConnected ? (
          <WaitingMessage>
            {__('Connecting to Nexus Core')}
            ...
          </WaitingMessage>
        ) : (
          <SendForm />
        )}
      </Panel>
    );
  }
}
export default Send;
