<commit_before>const React = window.React = require('react');
import Stellarify from '../../lib/Stellarify';
import Printify from '../../lib/Printify';
import AssetCard from '../AssetCard.jsx';
import _ from 'lodash';

export default class AddTrustRow extends React.Component {
  constructor(props) {
    super(props);

    this.state = {
      status: 'ready', // ready, error, or pending
    }

    this.handleSubmitTrust = (event) => {
      event.preventDefault();
      this.setState({status: 'pending'})
      this.props.d.handlers.addTrust(this.props.asset.getCode(), this.props.asset.getIssuer())
      .then((result) => {
        this.forceUpdate();
        this.setState({status: 'ready'})
      })
      .catch(error => {
        this.setState({status: 'error'})
      })
    }
  }
  render() {
    let found = false;
    _.each(this.props.d.session.account.balances, balance => {
      if (balance.asset_code === this.props.asset.getCode() && balance.asset_issuer === this.props.asset.getIssuer()) {
        found = true;
      }
    });

    let button;
    if (this.state.status === 'pending') {
      button = <button className="s-button" disabled={true} onClick={(e) => this.handleSubmitTrust(e)}>Creating trust line for {this.props.asset.getCode()}...</button>
    } else if (this.state.status === 'error') {
      button = <button className="s-button" onClick={(e) => this.handleSubmitTrust(e)}>Error creating trust line for {this.props.asset.getCode()}</button>
    } else {
      if (found) {
        button = <span className="AddTrustRow__exists">Trust line for {this.props.asset.getCode()} exists</span>
      } else {
        button = <button className="s-button" onClick={(e) => this.handleSubmitTrust(e)}>Create trust line for {this.props.asset.getCode()}</button>
      }
    }

    return <div className="row">
      <div className="row__fixedAsset">
        <AssetCard asset={this.props.asset} fixed={true}></AssetCard><commit_msg>Add error messaging for adding trust with not enough in reserve<commit_after>const React = window.React = require('react');
import Stellarify from '../../lib/Stellarify';
import Printify from '../../lib/Printify';
import AssetCard from '../AssetCard.jsx';
import _ from 'lodash';

export default class AddTrustRow extends React.Component {
  constructor(props) {
    super(props);

    this.state = {
      status: 'ready', // ready, error, or pending
      errorType: '', // 'unknown' | 'lowReserve'
    }

    this.handleSubmitTrust = (event) => {
      event.preventDefault();
      this.setState({status: 'pending'})
      this.props.d.handlers.addTrust(this.props.asset.getCode(), this.props.asset.getIssuer())
      .then((result) => {
        this.forceUpdate();
        this.setState({status: 'ready'})
      })
      .catch(error => {
        console.log(error)
        let errorType = 'unkonwn';
        if (error.extras.result_codes.operations[0] === 'op_low_reserve') {
          errorType = 'lowReserve';
        }

        this.setState({
          status: 'error',
          errorType,
        })
      })
    }
  }
  render() {
    let found = false;
    _.each(this.props.d.session.account.balances, balance => {
      if (balance.asset_code === this.props.asset.getCode() && balance.asset_issuer === this.props.asset.getIssuer()) {
        found = true;
      }
    });

    let button;
    if (this.state.status === 'pending') {
      button = <button className="s-button" disabled={true} onClick={(e) => this.handleSubmitTrust(e)}>Creating trust line for {this.props.asset.getCode()}...</button>
    } else if (this.state.status === 'error') {
      if (this.state.errorType === 'lowReserve') {
        button = <button className="s-button" onClick={(e) => this.handleSubmitTrust(e)}>Error: Not enough lumens for reserve</button>
      } else {
        button = <button className="s-button" onClick={(e) => this.handleSubmitTrust(e)}>Error creating trust line for {this.props.asset.getCode()}</button>
      }
    } else {
      if (found) {
        button = <span className="AddTrustRow__exists">Trust line for {this.props.asset.getCode()} exists</span>
      } else {
        button = <button className="s-button" onClick={(e) => this.handleSubmitTrust(e)}>Create trust line for {this.props.asset.getCode()}</button>
      }
    }

    return <div className="row">
      <div className="row__fixedAsset">
        <AssetCard asset={this.props.asset} fixed={true}></AssetCard>
{'fraction_non_alphanumeric': 0.1674523007856341, 'fraction_numerical': 0.0002244668911335578, 'mean_word_length': 2.989256938227395, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 44, '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': '5511295', 'n_tokens_mistral': 1368, 'n_tokens_neox': 1350, 'n_words': 273}