Browse Source

feature(contacts): add manual form

renovate/lint-staged-8.x
Jack Mallers 7 years ago
parent
commit
2c2e63235e
  1. 36
      app/components/Contacts/ContactsForm.js
  2. 36
      app/components/Contacts/ContactsForm.scss
  3. 15
      app/reducers/contactsform.js
  4. 4
      app/routes/contacts/containers/ContactsContainer.js

36
app/components/Contacts/ContactsForm.js

@ -10,7 +10,8 @@ class ContactsForm extends React.Component {
super(props) super(props)
this.state = { this.state = {
editing: false editing: false,
manualFormInput: ''
} }
} }
@ -25,10 +26,11 @@ class ContactsForm extends React.Component {
activeChannelPubkeys, activeChannelPubkeys,
nonActiveChannelPubkeys, nonActiveChannelPubkeys,
pendingOpenChannelPubkeys, pendingOpenChannelPubkeys,
filteredNetworkNodes filteredNetworkNodes,
showManualForm
} = this.props } = this.props
const { editing } = this.state const { editing, manualFormInput } = this.state
const renderRightSide = (node) => { const renderRightSide = (node) => {
if (activeChannelPubkeys.includes(node.pub_key)) { if (activeChannelPubkeys.includes(node.pub_key)) {
@ -67,7 +69,7 @@ class ContactsForm extends React.Component {
<span <span
className={`${styles.connect} hint--left`} className={`${styles.connect} hint--left`}
data-hint='Connect with 0.1 BTC' data-hint='Connect with 0.1 BTC'
onClick={() => openChannel({ pubkey: node.pub_key, host: node.addresses[0].addr, local_amt: contactsform.contactsform.contactCapacity })} onClick={() => openChannel({ pubkey: node.pub_key, host: node.addresses[0].addr, local_amt: contactsform.contactCapacity })}
> >
Connect Connect
</span> </span>
@ -80,6 +82,15 @@ class ContactsForm extends React.Component {
this.setState({ editing: true }) this.setState({ editing: true })
} }
const manualFormSubmit = () => {
if (!manualFormInput.length) { return }
if (!manualFormInput.includes('@')) { return }
const [pubkey, host] = manualFormInput && manualFormInput.split('@')
openChannel({ pubkey, host, local_amt: contactsform.contactCapacity })
}
return ( return (
<div> <div>
<ReactModal <ReactModal
@ -139,6 +150,23 @@ class ContactsForm extends React.Component {
} }
</ul> </ul>
</div> </div>
{
showManualForm &&
<div className={styles.manualForm}>
<h2>Hm, looks like we can't see that contact from here. Want to try and manually connect?</h2>
<section>
<input
type='text'
placeholder='pubkey@host'
value={manualFormInput}
onChange={event => this.setState({ manualFormInput: event.target.value })}
/>
<div className={styles.submit} onClick={manualFormSubmit}>Submit</div>
</section>
</div>
}
<footer className={styles.footer}> <footer className={styles.footer}>
<div> <div>
<span className={styles.amount}> <span className={styles.amount}>

36
app/components/Contacts/ContactsForm.scss

@ -49,7 +49,7 @@
.networkResults { .networkResults {
overflow-y: scroll; overflow-y: scroll;
height: 400px; height: 300px;
margin-top: 30px; margin-top: 30px;
padding: 20px 0; padding: 20px 0;
@ -119,6 +119,40 @@
} }
} }
.manualForm {
background: $lightgrey;
color: $darkestgrey;
padding: 30px 15px;
h2 {
font-size: 16px;
margin-bottom: 10px;
}
input {
border: 0;
outline: 0;
background: transparent;
color: $darkestgrey;
border-bottom: 1px solid $darkestgrey;
padding: 10px 5px;
width: 80%;
}
.submit {
display: inline-block;
vertical-align: middle;
width: 15%;
margin-left: 2.5%;
font-size: 12px;
&:hover {
cursor: pointer;
color: $main;
}
}
}
.footer { .footer {
padding: 10px 15px; padding: 10px 15px;
border-top: 1px solid $darkgrey; border-top: 1px solid $darkgrey;

15
app/reducers/contactsform.js

@ -73,6 +73,21 @@ contactFormSelectors.filteredNetworkNodes = createSelector(
(nodes, searchQuery) => filter(nodes, node => node.alias.includes(searchQuery) || node.pub_key.includes(searchQuery)) (nodes, searchQuery) => filter(nodes, node => node.alias.includes(searchQuery) || node.pub_key.includes(searchQuery))
) )
contactFormSelectors.showManualForm = createSelector(
searchQuerySelector,
contactFormSelectors.filteredNetworkNodes,
(searchQuery, filteredNetworkNodes) => {
if (!searchQuery.length) { return false }
const connectableNodes = filteredNetworkNodes.filter(node => node.addresses.length > 0)
console.log('connectableNodes: ', connectableNodes)
if (!filteredNetworkNodes.length || !connectableNodes.length) { return true }
return false
}
)
export { contactFormSelectors } export { contactFormSelectors }
// ------------------------------------ // ------------------------------------

4
app/routes/contacts/containers/ContactsContainer.js

@ -58,7 +58,8 @@ const mapStateToProps = state => ({
closingPendingChannels: channelsSelectors.closingPendingChannels(state), closingPendingChannels: channelsSelectors.closingPendingChannels(state),
nonActiveFilters: channelsSelectors.nonActiveFilters(state), nonActiveFilters: channelsSelectors.nonActiveFilters(state),
filteredNetworkNodes: contactFormSelectors.filteredNetworkNodes(state) filteredNetworkNodes: contactFormSelectors.filteredNetworkNodes(state),
showManualForm: contactFormSelectors.showManualForm(state)
}) })
const mergeProps = (stateProps, dispatchProps, ownProps) => { const mergeProps = (stateProps, dispatchProps, ownProps) => {
@ -70,6 +71,7 @@ const mergeProps = (stateProps, dispatchProps, ownProps) => {
contactsform: stateProps.contactsform, contactsform: stateProps.contactsform,
filteredNetworkNodes: stateProps.filteredNetworkNodes, filteredNetworkNodes: stateProps.filteredNetworkNodes,
showManualForm: stateProps.showManualForm,
activeChannelPubkeys: stateProps.activeChannelPubkeys, activeChannelPubkeys: stateProps.activeChannelPubkeys,
nonActiveChannelPubkeys: stateProps.nonActiveChannelPubkeys, nonActiveChannelPubkeys: stateProps.nonActiveChannelPubkeys,

Loading…
Cancel
Save