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)
this.state = {
editing: false
editing: false,
manualFormInput: ''
}
}
@ -25,10 +26,11 @@ class ContactsForm extends React.Component {
activeChannelPubkeys,
nonActiveChannelPubkeys,
pendingOpenChannelPubkeys,
filteredNetworkNodes
filteredNetworkNodes,
showManualForm
} = this.props
const { editing } = this.state
const { editing, manualFormInput } = this.state
const renderRightSide = (node) => {
if (activeChannelPubkeys.includes(node.pub_key)) {
@ -67,7 +69,7 @@ class ContactsForm extends React.Component {
<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: contactsform.contactsform.contactCapacity })}
onClick={() => openChannel({ pubkey: node.pub_key, host: node.addresses[0].addr, local_amt: contactsform.contactCapacity })}
>
Connect
</span>
@ -80,6 +82,15 @@ class ContactsForm extends React.Component {
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 (
<div>
<ReactModal
@ -139,6 +150,23 @@ class ContactsForm extends React.Component {
}
</ul>
</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}>
<div>
<span className={styles.amount}>

36
app/components/Contacts/ContactsForm.scss

@ -49,7 +49,7 @@
.networkResults {
overflow-y: scroll;
height: 400px;
height: 300px;
margin-top: 30px;
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 {
padding: 10px 15px;
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))
)
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 }
// ------------------------------------

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

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

Loading…
Cancel
Save