You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
176 lines
5.0 KiB
176 lines
5.0 KiB
7 years ago
|
import React from 'react'
|
||
|
import PropTypes from 'prop-types'
|
||
|
|
||
7 years ago
|
import FaAngleDown from 'react-icons/lib/fa/angle-down'
|
||
6 years ago
|
import FaExclamationCircle from 'react-icons/lib/fa/exclamation-circle'
|
||
7 years ago
|
|
||
7 years ago
|
import AmountInput from 'components/AmountInput'
|
||
7 years ago
|
import styles from './SubmitChannelForm.scss'
|
||
|
|
||
|
class SubmitChannelForm extends React.Component {
|
||
6 years ago
|
constructor(props) {
|
||
|
super(props)
|
||
|
this.amountInput = React.createRef()
|
||
|
}
|
||
|
|
||
|
componentDidMount() {
|
||
|
// Clear and Focus the amount input field.
|
||
|
this.amountInput.current.clearTextInput()
|
||
|
this.amountInput.current.focusTextInput()
|
||
|
}
|
||
|
|
||
7 years ago
|
render() {
|
||
|
const {
|
||
7 years ago
|
closeChannelForm,
|
||
|
closeContactsForm,
|
||
7 years ago
|
|
||
7 years ago
|
node,
|
||
7 years ago
|
contactCapacity,
|
||
|
updateContactCapacity,
|
||
7 years ago
|
openChannel,
|
||
7 years ago
|
fiatTicker,
|
||
6 years ago
|
dupeChanInfo,
|
||
7 years ago
|
|
||
7 years ago
|
ticker,
|
||
|
|
||
7 years ago
|
toggleCurrencyProps: {
|
||
|
setContactsCurrencyFilters,
|
||
|
showCurrencyFilters,
|
||
|
currencyName,
|
||
|
currentCurrencyFilters,
|
||
|
onCurrencyFilterClick,
|
||
7 years ago
|
contactFormFiatAmount
|
||
7 years ago
|
}
|
||
|
} = this.props
|
||
|
|
||
7 years ago
|
const renderTitle = () => {
|
||
|
// if the node has an alias set we will show that with the pubkey in parens
|
||
|
// if not, just show the pubkey (would look ugly with rando parens)
|
||
|
if (node.alias && node.alias.length) {
|
||
|
return `${node.alias} (${node.pub_key})`
|
||
|
}
|
||
7 years ago
|
|
||
|
return node.pub_key
|
||
7 years ago
|
}
|
||
|
|
||
6 years ago
|
const renderWarning = dupeChanInfo => {
|
||
|
const { alias, activeChannels, capacity, currencyName } = dupeChanInfo
|
||
|
|
||
|
const chansMsg =
|
||
|
activeChannels === 1 ? ' an active channel ' : ` ${activeChannels} active channels `
|
||
|
const aliasMsg = alias ? <span className={styles.alias}>{alias}</span> : ' this node '
|
||
|
|
||
|
return (
|
||
|
<p>
|
||
|
{`You currently have ${chansMsg} open to `}
|
||
|
{aliasMsg}
|
||
|
{` with a capacity of ${capacity} ${currencyName}.`}
|
||
|
</p>
|
||
|
)
|
||
|
}
|
||
|
|
||
7 years ago
|
const formSubmitted = () => {
|
||
7 years ago
|
// dont submit to LND if they havent set channel capacity amount
|
||
7 years ago
|
if (contactCapacity <= 0) {
|
||
|
return
|
||
|
}
|
||
7 years ago
|
|
||
7 years ago
|
// submit the channel to LND
|
||
7 years ago
|
openChannel({
|
||
|
pubkey: node.pub_key,
|
||
|
host: node.addresses[0].addr,
|
||
|
local_amt: contactCapacity
|
||
|
})
|
||
7 years ago
|
|
||
|
// close the ChannelForm component
|
||
|
closeChannelForm()
|
||
|
|
||
|
// close the AddChannel component
|
||
|
closeContactsForm()
|
||
|
}
|
||
7 years ago
|
|
||
|
return (
|
||
7 years ago
|
<div className={styles.content}>
|
||
|
<header className={styles.header}>
|
||
|
<h1>Add Funds to Network</h1>
|
||
7 years ago
|
<p>
|
||
7 years ago
|
Opening a channel will help you send and receive money on the Lightning Network. You
|
||
7 years ago
|
aren't spending any money, rather moving the money you plan to use onto the
|
||
|
network.
|
||
7 years ago
|
</p>
|
||
7 years ago
|
</header>
|
||
|
|
||
|
<section className={styles.title}>
|
||
|
<h2>{renderTitle()}</h2>
|
||
|
</section>
|
||
7 years ago
|
|
||
6 years ago
|
{dupeChanInfo && (
|
||
|
<section className={styles.warn}>
|
||
|
<FaExclamationCircle className={styles.exclamation} style={{ verticalAlign: 'top' }} />
|
||
|
{renderWarning(dupeChanInfo)}
|
||
|
</section>
|
||
|
)}
|
||
|
|
||
7 years ago
|
<section className={styles.amount}>
|
||
|
<div className={styles.input}>
|
||
7 years ago
|
<AmountInput
|
||
7 years ago
|
id="amount"
|
||
7 years ago
|
amount={contactCapacity}
|
||
|
currency={ticker.currency}
|
||
|
onChangeEvent={updateContactCapacity}
|
||
6 years ago
|
ref={this.amountInput}
|
||
7 years ago
|
/>
|
||
|
<div className={styles.currency}>
|
||
7 years ago
|
<section
|
||
|
className={styles.currentCurrency}
|
||
|
onClick={() => setContactsCurrencyFilters(!showCurrencyFilters)}
|
||
|
>
|
||
7 years ago
|
<span>{currencyName}</span>
|
||
|
<span>
|
||
|
<FaAngleDown />
|
||
|
</span>
|
||
7 years ago
|
</section>
|
||
7 years ago
|
<ul className={showCurrencyFilters ? styles.active : undefined}>
|
||
7 years ago
|
{currentCurrencyFilters.map(filter => (
|
||
|
<li key={filter.key} onClick={() => onCurrencyFilterClick(filter.key)}>
|
||
|
{filter.name}
|
||
|
</li>
|
||
|
))}
|
||
7 years ago
|
</ul>
|
||
7 years ago
|
</div>
|
||
7 years ago
|
</div>
|
||
|
|
||
7 years ago
|
<div className={styles.fiatAmount}>{`≈ ${contactFormFiatAmount || 0} ${fiatTicker}`}</div>
|
||
7 years ago
|
</section>
|
||
|
|
||
|
<section className={styles.submit}>
|
||
7 years ago
|
<div
|
||
7 years ago
|
className={`${styles.button} ${contactCapacity > 0 ? styles.active : undefined}`}
|
||
7 years ago
|
onClick={formSubmitted}
|
||
|
>
|
||
7 years ago
|
Submit
|
||
|
</div>
|
||
|
</section>
|
||
7 years ago
|
</div>
|
||
|
)
|
||
|
}
|
||
|
}
|
||
|
|
||
7 years ago
|
SubmitChannelForm.propTypes = {
|
||
|
closeChannelForm: PropTypes.func.isRequired,
|
||
|
closeContactsForm: PropTypes.func.isRequired,
|
||
|
|
||
|
node: PropTypes.object.isRequired,
|
||
7 years ago
|
contactCapacity: PropTypes.PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
||
7 years ago
|
updateContactCapacity: PropTypes.func.isRequired,
|
||
|
openChannel: PropTypes.func.isRequired,
|
||
7 years ago
|
fiatTicker: PropTypes.string.isRequired,
|
||
6 years ago
|
dupeChanInfo: PropTypes.object,
|
||
7 years ago
|
|
||
7 years ago
|
ticker: PropTypes.object.isRequired,
|
||
|
|
||
7 years ago
|
toggleCurrencyProps: PropTypes.object.isRequired
|
||
|
}
|
||
7 years ago
|
|
||
|
export default SubmitChannelForm
|