import React, { Component } from 'react' import PropTypes from 'prop-types' import { btc } from 'lib/utils' import PaperPlane from 'components/Icon/PaperPlane' import ChainLink from 'components/Icon/ChainLink' import AmountInput from 'components/AmountInput' import { Button, Dropdown } from 'components/UI' import { FormattedNumber, FormattedMessage, injectIntl } from 'react-intl' import messages from './messages' import styles from './Pay.scss' class Pay extends Component { constructor(props) { super(props) this.paymentRequestInput = React.createRef() } componentDidMount() { const { setPayInput, setPayAmount } = this.props // Clear the form of any previous data. setPayInput('') setPayAmount('') // Focus the payment request input field. this.paymentRequestInput.current.focus() } componentDidUpdate(prevProps) { const { isLn, payform: { payInput }, fetchInvoice } = this.props // If LN go retrieve invoice details if (prevProps.payform.payInput !== payInput && isLn) { fetchInvoice(payInput) } } render() { const { payform: { payInput, showErrors, invoice }, nodes, ticker, isOnchain, isLn, currentAmount, fiatAmount, payFormIsValid: { errors, isValid }, currencyFilters, setPayAmount, onPayAmountBlur, setPayInput, onPayInputBlur, onPaySubmit, setCurrency, intl } = this.props const displayNodeName = pubkey => { const node = nodes.find(n => n.pub_key === pubkey) if (node && node.alias.length) { return node.alias } return pubkey ? pubkey.substring(0, 10) : '' } const onCurrencyFilterClick = currency => { if (!isLn) { // change the input amount setPayAmount(btc.convert(ticker.currency, currency, currentAmount)) } setCurrency(currency) } return (