<commit_before>import React from 'react'
import PropTypes from 'prop-types'
import { FormattedMessage, injectIntl } from 'react-intl'
import { Box, Flex } from 'rebass'
import { Bar, Button, DataRow, Form, Input, Label, Range, Text, Toggle } from 'components/UI'
import * as yup from 'yup'
import messages from './messages'

class WalletSettingsFormLocal extends React.Component {
  static propTypes = {
    wallet: PropTypes.object.isRequired,
    startLnd: PropTypes.func.isRequired
  }

  resetAutopilotSettings = () => {
    const defaults = {
      autopilotMaxchannels: 5,
      autopilotMinchansize: 20000,
      autopilotMaxchansize: 16777215,
      autopilotAllocation: 60
    }
    Object.entries(defaults).forEach(([field, value]) => {
      this.formApi.setValue(field, value)
    })
  }

  validateAutopilot = value => {
    try {
      yup.boolean().validateSync(value)
    } catch (error) {
      return error.message
    }
  }

  preSubmit = values => {
    if (values.autopilotAllocation) {
      values.autopilotAllocation = values.autopilotAllocation / 100
    }
    return values
  }

  onSubmit = async values => {
    const { startLnd } = this.props
    return startLnd(values)
  }

  setFormApi = formApi => {
    this.formApi = formApi
  }

  render() {
    const { intl, wallet, startLnd, ...rest } = this.props

    return (
      <Form
        getApi={this.setFormApi}
        preSubmit={this.preSubmit}
        onSubmit={this.onSubmit}
        {...rest}
        initialValues={wallet}
        wallet={wallet}
      >
        {({ formState }) => (
          <React.Fragment>
            <Box mb={4} as="section">
              <Text fontWeight="normal">
                <FormattedMessage {...messages.section_basic_title} />
              </Text>
              <Bar mt={2} mb={4} />

              <DataRow
                py={2}
                left={<FormattedMessage {...messages.chain} />}
                right={wallet.chain}
              />
              <DataRow
                py={2}
                left={<FormattedMessage {...messages.network} />}
                right={wallet.network}
              />
            </Box><commit_msg>fix(home): do not mutate autopilot allocation<commit_after>import React from 'react'
import PropTypes from 'prop-types'
import { FormattedMessage, injectIntl } from 'react-intl'
import { Box, Flex } from 'rebass'
import { Bar, Button, DataRow, Form, Input, Label, Range, Text, Toggle } from 'components/UI'
import * as yup from 'yup'
import messages from './messages'

class WalletSettingsFormLocal extends React.Component {
  static propTypes = {
    wallet: PropTypes.object.isRequired,
    startLnd: PropTypes.func.isRequired
  }

  resetAutopilotSettings = () => {
    const defaults = {
      autopilotMaxchannels: 5,
      autopilotMinchansize: 20000,
      autopilotMaxchansize: 16777215,
      autopilotAllocation: 60
    }
    Object.entries(defaults).forEach(([field, value]) => {
      this.formApi.setValue(field, value)
    })
  }

  validateAutopilot = value => {
    try {
      yup.boolean().validateSync(value)
    } catch (error) {
      return error.message
    }
  }

  onSubmit = async values => {
    const { startLnd } = this.props

    // Lnd expects the autopilot allocation to be a decimal.
    values.autopilotAllocation = values.autopilotAllocation / 100

    return startLnd(values)
  }

  setFormApi = formApi => {
    this.formApi = formApi
  }

  render() {
    const { intl, wallet, startLnd, ...rest } = this.props

    return (
      <Form
        getApi={this.setFormApi}
        onSubmit={this.onSubmit}
        {...rest}
        initialValues={wallet}
        wallet={wallet}
      >
        {({ formState }) => (
          <React.Fragment>
            <Box mb={4} as="section">
              <Text fontWeight="normal">
                <FormattedMessage {...messages.section_basic_title} />
              </Text>
              <Bar mt={2} mb={4} />

              <DataRow
                py={2}
                left={<FormattedMessage {...messages.chain} />}
                right={wallet.chain}
              />
              <DataRow
                py={2}
                left={<FormattedMessage {...messages.network} />}
                right={wallet.network}
              />
            </Box>
{'fraction_non_alphanumeric': 0.1229413129204361, 'fraction_numerical': 0.011134307585247043, 'mean_word_length': 2.0473498233215546, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 40, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7050496', 'n_tokens_mistral': 1346, 'n_tokens_neox': 1285, 'n_words': 270}