import React from 'react' import PropTypes from 'prop-types' import { FormattedMessage, injectIntl } from 'react-intl' import get from 'lodash.get' import { Bar, Form, Header, TextArea } from 'components/UI' import messages from './messages' class BtcPayServer extends React.Component { static propTypes = { wizardApi: PropTypes.object, wizardState: PropTypes.object, connectionString: PropTypes.string.isRequired, setConnectionString: PropTypes.func.isRequired, startLndHostError: PropTypes.string } static defaultProps = { wizardApi: {}, wizardState: {} } componentDidUpdate(prevProps) { const { startLndHostError } = this.props if (startLndHostError && startLndHostError !== prevProps.startLndHostError) { this.formApi.setError('connectionString', startLndHostError) } } handleSubmit = values => { const { setConnectionString } = this.props setConnectionString(values.connectionString) } handleConnectionStringChange = () => { this.formApi.setError('connectionString', null) } validateConnectionString = value => { const { intl } = this.props let config = {} try { config = JSON.parse(value) } catch (e) { return intl.formatMessage({ ...messages.btcpay_error }) } const configs = get(config, 'configurations', []) const params = configs.find(c => c.type === 'grpc' && c.cryptoCode === 'BTC') || {} const { host, port, macaroon } = params if (!host || !port || !macaroon) { return intl.formatMessage({ ...messages.btcpay_error }) } } setFormApi = formApi => { this.formApi = formApi } render() { const { wizardApi, wizardState, intl, connectionString, setConnectionString, startLndHostError, ...rest } = this.props const { getApi, onChange, preSubmit, onSubmit, onSubmitFailure } = wizardApi const { currentItem } = wizardState return (
) } } export default injectIntl(BtcPayServer)