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.
102 lines
2.7 KiB
102 lines
2.7 KiB
7 years ago
|
import React from 'react'
|
||
|
import PropTypes from 'prop-types'
|
||
|
import styles from './ConnectManually.scss'
|
||
|
|
||
|
class ConnectManually extends React.Component {
|
||
|
render() {
|
||
|
const {
|
||
|
manualSearchQuery,
|
||
|
|
||
7 years ago
|
manualFormIsValid,
|
||
|
updateManualFormErrors,
|
||
|
|
||
|
openSubmitChannelForm,
|
||
|
updateManualFormSearchQuery,
|
||
|
|
||
|
setNode,
|
||
|
|
||
|
showErrors
|
||
7 years ago
|
} = this.props
|
||
|
|
||
7 years ago
|
const formSubmitted = () => {
|
||
|
if (!manualFormIsValid.isValid) {
|
||
|
updateManualFormErrors(manualFormIsValid.errors)
|
||
7 years ago
|
|
||
7 years ago
|
return
|
||
|
}
|
||
7 years ago
|
// clear any existing errors
|
||
|
updateManualFormErrors({ manualInput: null })
|
||
|
|
||
|
const [pub_key, addr] = manualSearchQuery && manualSearchQuery.split('@')
|
||
|
|
||
|
// the SubmitChannel component is expecting a node object that looks like the following
|
||
|
// {
|
||
|
// pub_key: 'some_string',
|
||
|
// addresses: [
|
||
|
// {
|
||
|
// addr: 'some_host_address'
|
||
|
// }
|
||
|
// ]
|
||
|
// }
|
||
|
// knowing this we will set the node object with the known format and plug in the pubkey + host accordingly
|
||
|
setNode({ pub_key, addresses: [{ addr }] })
|
||
|
|
||
|
// now we close the ConnectManually form and open the SubmitChannel form by chaning the channelFormType
|
||
|
openSubmitChannelForm()
|
||
7 years ago
|
}
|
||
7 years ago
|
|
||
|
return (
|
||
|
<div className={styles.content}>
|
||
|
<header className={styles.header}>
|
||
|
<h1>Connect Manually</h1>
|
||
7 years ago
|
<p>Please enter the peer's pubkey@host</p>
|
||
7 years ago
|
</header>
|
||
|
|
||
|
<section className={styles.peer}>
|
||
|
<div className={styles.input}>
|
||
|
<input
|
||
7 years ago
|
type="text"
|
||
|
placeholder="pubkey@host"
|
||
7 years ago
|
value={manualSearchQuery}
|
||
|
onChange={event => updateManualFormSearchQuery(event.target.value)}
|
||
|
/>
|
||
|
</div>
|
||
|
</section>
|
||
7 years ago
|
|
||
7 years ago
|
<section
|
||
|
className={`${styles.errorMessage} ${showErrors.manualInput ? styles.active : undefined}`}
|
||
|
>
|
||
7 years ago
|
{showErrors.manualInput && (
|
||
|
<span>{manualFormIsValid && manualFormIsValid.errors.manualInput}</span>
|
||
|
)}
|
||
7 years ago
|
</section>
|
||
|
|
||
|
<section className={styles.submit}>
|
||
7 years ago
|
<div
|
||
7 years ago
|
className={`${styles.button} ${manualFormIsValid.isValid ? styles.active : undefined}`}
|
||
7 years ago
|
onClick={formSubmitted}
|
||
|
>
|
||
7 years ago
|
Submit
|
||
|
</div>
|
||
|
</section>
|
||
7 years ago
|
</div>
|
||
|
)
|
||
|
}
|
||
|
}
|
||
|
|
||
7 years ago
|
ConnectManually.propTypes = {
|
||
|
manualSearchQuery: PropTypes.string.isRequired,
|
||
|
|
||
|
manualFormIsValid: PropTypes.object.isRequired,
|
||
|
updateManualFormErrors: PropTypes.func.isRequired,
|
||
|
|
||
|
openSubmitChannelForm: PropTypes.func.isRequired,
|
||
|
updateManualFormSearchQuery: PropTypes.func.isRequired,
|
||
|
|
||
|
setNode: PropTypes.func.isRequired,
|
||
|
|
||
7 years ago
|
showErrors: PropTypes.object.isRequired
|
||
7 years ago
|
}
|
||
7 years ago
|
|
||
|
export default ConnectManually
|