<commit_before>import React from 'react'
import {connect} from 'react-redux'
import {Button, Col, Container, Jumbotron, Form, FormGroup, Input, Label, Row} from 'reactstrap'

import signClaim from 'bitcoin/signClaim'
import db from 'db'
import {getOwnClaims} from 'redux/actions'

const context = {
  familyName: 'http://schema.org/familyName',
  givenName: 'http://schema.org/givenName'
}

const handleSubmit = (did, dispatch, wallet) => async (e) => {
  e.preventDefault()
  const firstname = e.target.firstname.value.trim()
  const lastname = e.target.lastname.value.trim()

  if (firstname === '' && lastname === '') {
    return
  }

  const claim = {
    '@context': context,
    '@id': `did:btcr:${did}`
  }

  if (lastname !== '') {
    claim.familyName = lastname
  }

  if (firstname !== '') {
    claim.givenName = firstname
  }

  const walletRoot = wallet.root
  const controlAccount = Number(process.env.controlAccount)
  const ownerRoot = walletRoot.derivePath("m/44'/0'")
  .deriveHardened(controlAccount)
  .derive(0)

  const rotationIx = 0
  try {
    const signedDocument = await signClaim(claim, ownerRoot, rotationIx)
    await db.claims.add({
      subject: did,
      signedDocument: JSON.stringify(signedDocument),
      signers: [
        {did, status: 'signed'}
      ]
    })
    dispatch(getOwnClaims(did))
  } catch (e) {
    console.error(e)
  }
}

const GenerateClaim = ({did, dispatch, wallet}) => (
  <Container fluid>
    <Row className='mt-3'>
      <Col md='6' className='mx-auto'>
        <Jumbotron>
          <p className='lead text-center'>
            <strong>
              Generate a claim about yourself
            </strong>
          </p>
        </Jumbotron>
      </Col>
    </Row>
    <Form onSubmit={handleSubmit(did.did, dispatch, wallet)}>
      <Row>
        <Col md='6' className='mx-auto'>
          <FormGroup><commit_msg>Improve ui for claims submission form<commit_after>import React from 'react'
import {connect} from 'react-redux'
import {Button, Col, Container, Jumbotron, Form, FormGroup, Input, Label, Row} from 'reactstrap'
import {NotificationManager} from 'react-notifications'

import signClaim from 'bitcoin/signClaim'
import db from 'db'
import {getOwnClaims} from 'redux/actions'

const context = {
  familyName: 'http://schema.org/familyName',
  givenName: 'http://schema.org/givenName'
}

const handleSubmit = (did, dispatch, wallet) => async (e) => {
  e.preventDefault()
  const form = e.target
  const firstname = form.firstname.value.trim()
  const lastname = form.lastname.value.trim()

  if (firstname === '' && lastname === '') {
    return
  }

  const claim = {
    '@context': context,
    '@id': `did:btcr:${did}`
  }

  if (lastname !== '') {
    claim.familyName = lastname
  }

  if (firstname !== '') {
    claim.givenName = firstname
  }

  const walletRoot = wallet.root
  const controlAccount = Number(process.env.controlAccount)
  const ownerRoot = walletRoot.derivePath("m/44'/0'")
  .deriveHardened(controlAccount)
  .derive(0)

  const rotationIx = 0
  try {
    const signedDocument = await signClaim(claim, ownerRoot, rotationIx)
    await db.claims.add({
      subject: did,
      signedDocument: JSON.stringify(signedDocument),
      signers: [
        {did, status: 'signed'}
      ]
    })
    dispatch(getOwnClaims(did))
    NotificationManager.success('', 'Claim generated', 5000)
  } catch (e) {
    NotificationManager.success('', 'Claim genration failed', 5000)
    console.error(e)
    return
  }
  form.reset()
}

const GenerateClaim = ({did, dispatch, wallet}) => (
  <Container fluid>
    <Row className='mt-3'>
      <Col md='6' className='mx-auto'>
        <Jumbotron>
          <p className='lead text-center'>
            <strong>
              Generate a claim about yourself
            </strong>
          </p>
        </Jumbotron>
      </Col>
    </Row>
    <Form onSubmit={handleSubmit(did.did, dispatch, wallet)}>
      <Row>
        <Col md='6' className='mx-auto'>
          <FormGroup>
{'fraction_non_alphanumeric': 0.1451733599401347, 'fraction_numerical': 0.005986530306809678, 'mean_word_length': 3.0019960079840318, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 39, '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': '2982994', 'n_tokens_mistral': 1302, 'n_tokens_neox': 1277, 'n_words': 304}