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.
142 lines
3.9 KiB
142 lines
3.9 KiB
7 years ago
|
import React from 'react'
|
||
|
import PropTypes from 'prop-types'
|
||
|
import ReactModal from 'react-modal'
|
||
|
import { MdClose } from 'react-icons/lib/md'
|
||
|
import { FaCircle } from 'react-icons/lib/fa'
|
||
7 years ago
|
import styles from './ContactsForm.scss'
|
||
7 years ago
|
|
||
7 years ago
|
const ContactsForm = ({
|
||
|
contactsform,
|
||
|
closeContactsForm,
|
||
|
updateContactFormSearchQuery,
|
||
7 years ago
|
openChannel,
|
||
|
|
||
|
activeChannelPubkeys,
|
||
|
nonActiveChannelPubkeys,
|
||
|
pendingOpenChannelPubkeys,
|
||
|
filteredNetworkNodes
|
||
|
}) => {
|
||
|
const renderRightSide = (node) => {
|
||
|
if (activeChannelPubkeys.includes(node.pub_key)) {
|
||
|
return (
|
||
|
<span className={`${styles.online} ${styles.inactive}`}>
|
||
|
<FaCircle style={{ verticalAlign: 'top' }} /> <span>Online</span>
|
||
|
</span>
|
||
|
)
|
||
|
}
|
||
|
|
||
|
if (nonActiveChannelPubkeys.includes(node.pub_key)) {
|
||
|
return (
|
||
|
<span className={`${styles.offline} ${styles.inactive}`}>
|
||
|
<FaCircle style={{ verticalAlign: 'top' }} /> <span>Offline</span>
|
||
|
</span>
|
||
|
)
|
||
|
}
|
||
|
|
||
|
if (pendingOpenChannelPubkeys.includes(node.pub_key)) {
|
||
|
return (
|
||
|
<span className={`${styles.pending} ${styles.inactive}`}>
|
||
|
<FaCircle style={{ verticalAlign: 'top' }} /> <span>Pending</span>
|
||
|
</span>
|
||
|
)
|
||
|
}
|
||
|
|
||
|
if (!node.addresses.length) {
|
||
|
return (
|
||
|
<span className={`${styles.private} ${styles.inactive}`}>
|
||
|
Private
|
||
|
</span>
|
||
|
)
|
||
|
}
|
||
|
|
||
|
return (
|
||
|
<span
|
||
|
className={`${styles.connect} hint--left`}
|
||
|
data-hint='Connect with 0.1 BTC'
|
||
|
onClick={() => openChannel({ pubkey: node.pub_key, host: node.addresses[0].addr, local_amt: 0.1 })}
|
||
|
>
|
||
|
Connect
|
||
|
</span>
|
||
|
)
|
||
|
}
|
||
|
|
||
|
return (
|
||
|
<div>
|
||
|
<ReactModal
|
||
7 years ago
|
isOpen={contactsform.isOpen}
|
||
7 years ago
|
contentLabel='No Overlay Click Modal'
|
||
|
ariaHideApp
|
||
|
shouldCloseOnOverlayClick
|
||
7 years ago
|
onRequestClose={() => closeContactsForm}
|
||
7 years ago
|
parentSelector={() => document.body}
|
||
|
className={styles.modal}
|
||
|
>
|
||
|
<header>
|
||
|
<div>
|
||
|
<h1>Add Contact</h1>
|
||
|
</div>
|
||
7 years ago
|
<div onClick={closeContactsForm} className={styles.modalClose}>
|
||
7 years ago
|
<MdClose />
|
||
|
</div>
|
||
|
</header>
|
||
|
|
||
|
<div className={styles.form} onKeyPress={event => event.charCode === 13 && console.log('gaaaang')}>
|
||
|
<div className={styles.search}>
|
||
|
<input
|
||
|
type='text'
|
||
7 years ago
|
placeholder='Find contact by alias or pubkey'
|
||
7 years ago
|
className={styles.searchInput}
|
||
7 years ago
|
value={contactsform.searchQuery}
|
||
|
onChange={event => updateContactFormSearchQuery(event.target.value)}
|
||
7 years ago
|
autoFocus
|
||
|
/>
|
||
|
</div>
|
||
|
|
||
|
<ul className={styles.networkResults}>
|
||
|
{
|
||
7 years ago
|
contactsform.searchQuery.length > 0 && filteredNetworkNodes.map(node => {
|
||
7 years ago
|
return (
|
||
|
<li key={node.pub_key}>
|
||
|
<section>
|
||
|
{
|
||
|
node.alias.length > 0 ?
|
||
|
<h2>
|
||
|
<span>{node.alias.trim()}</span>
|
||
|
<span>({node.pub_key.substr(0, 10)}...{node.pub_key.substr(node.pub_key.length - 10)})</span>
|
||
|
</h2>
|
||
|
:
|
||
|
<h2>
|
||
|
<span>{node.pub_key}</span>
|
||
|
</h2>
|
||
|
}
|
||
|
</section>
|
||
|
<section>
|
||
|
{renderRightSide(node)}
|
||
|
</section>
|
||
|
</li>
|
||
|
)
|
||
|
})
|
||
|
}
|
||
|
</ul>
|
||
|
</div>
|
||
|
<footer className={styles.footer}>
|
||
|
<div>
|
||
|
<span className={styles.amount}>
|
||
|
0.1
|
||
|
</span>
|
||
|
<span className={styles.caption}>
|
||
|
BTC per contact
|
||
|
</span>
|
||
|
</div>
|
||
|
</footer>
|
||
|
</ReactModal>
|
||
|
</div>
|
||
|
)
|
||
|
}
|
||
|
|
||
7 years ago
|
ContactsForm.propTypes = {
|
||
7 years ago
|
|
||
|
}
|
||
|
|
||
7 years ago
|
export default ContactsForm
|