<commit_before>import React from "react";
import ChainTypes from "components/Utility/ChainTypes";
import BindToChainState from "components/Utility/BindToChainState";
import utils from "common/utils";
import counterpart from "counterpart";
import AmountSelector from "components/Utility/AmountSelector";
import ZfApi from "react-foundation-apps/src/utils/foundation-api";

class DepositFiatOpenLedger extends React.Component {

    static propTypes = {
        account: ChainTypes.ChainAccount.isRequired,
        issuer_account: ChainTypes.ChainAccount.isRequired,
        deposit_asset: React.PropTypes.string,
        receive_asset: ChainTypes.ChainAsset.isRequired,
        rpc_url: React.PropTypes.string
    }

    constructor( props ) {
        super(props);
        this.state = {
            deposit_amount: null,
            deposit_info: null,
            deposit_error: null
        };
    }

   onDepositAmountChange( {amount, asset} ) {
      this.setState( {deposit_amount:amount} );
   }

   onSubmitDeposit() {
     let asset = this.props.receive_asset;
     let precision = utils.get_asset_precision(asset.get("precision"));
     let amount = this.state.deposit_amount.replace( /,/g, "" )
     console.log( "deposit_amount: ", amount );

     let json_rpc_request = {
      "jsonrpc": "2.0",
      "method": "getDepositAccount",
      "params": {
         "bitsharesAccountName": this.props.account.get('name'),
         "currency": this.props.deposit_asset,
         "amount": amount
      },
      "id": 1
     };

     let is_deposit_approved_promise = fetch(this.props.rpc_url,
                                             {method: 'POST',
                                              headers: new Headers({"Accept": "application/json",
                                              "content-type":"application/x-www-form-urlencoded"}),
                                              body: 'rq=' + encodeURIComponent(JSON.stringify(json_rpc_request)) })
                                          .then(response => response.json());

     is_deposit_approved_promise.then((json_response) => {
       if ('result' in json_response)
         this.setState({ deposit_info: json_response.result });
       else if ('error' in json_reponse && 'message' in json_response.error)
         this.setState({ deposit_error: json_response.error.message });
       else
         this.setState({ deposit_error: 'Unable to approve deposit, please contact OpenLedger or try again later' });
     })
     .catch((error) => {
       this.setState({ deposit_error: 'Unable to approve deposit, please contact OpenLedger or try again later' });
     });
;
   }

   onClose() {
      // reset the state so the next time the dialog is launched, it doesn't show the old data
      this.setState({
         deposit_amount: null,
         deposit_info: null,
         deposit_error: null
      });
      ZfApi.publish(this.props.modal_id, "close");
   }

    render() {
       if (this.state.deposit_error) // then we've failed to approve them
       {
          return (<form className="grid-block vertical full-width-content">
                    <div className="grid-container">
                      <div className="content-block">
                         <h3>Deposit Error</h3>
                      </div>
                      <div className="content-block">
                        <p>{ this.state.deposit_error }</p>
                      </div>
                      <div className="content-block">
                        <input type="submit" className="button"
                               onClick={this.onClose.bind(this)}
                               value="Close" />
                      </div>
                    </div>
                  </form>);
       }
       else if (this.state.deposit_info) // then they've been approved for deposit
       {
          if ('link' in this.state.deposit_info)
             return (<form className="grid-block vertical full-width-content">
                       <div className="grid-container">
                         <div className="content-block">
                            <h3>Deposit Information</h3>
                         </div>
                         <div className="content-block">
                           <p>Click <a href={this.state.deposit_info.link} rel="noopener noreferrer" target="_blank">here</a> for deposit instructions</p>

                         </div>
                         <div className="content-block">
                        <input type="submit" className="button"
                               onClick={this.onClose.bind(this)}
                               value="Close" />
                         </div>
                       </div>
                     </form>);<commit_msg>fix link in fiat deposit<commit_after>import React from "react";
import ChainTypes from "components/Utility/ChainTypes";
import BindToChainState from "components/Utility/BindToChainState";
import utils from "common/utils";
import counterpart from "counterpart";
import AmountSelector from "components/Utility/AmountSelector";
import ZfApi from "react-foundation-apps/src/utils/foundation-api";

class DepositFiatOpenLedger extends React.Component {

    static propTypes = {
        account: ChainTypes.ChainAccount.isRequired,
        issuer_account: ChainTypes.ChainAccount.isRequired,
        deposit_asset: React.PropTypes.string,
        receive_asset: ChainTypes.ChainAsset.isRequired,
        rpc_url: React.PropTypes.string
    }

    constructor( props ) {
        super(props);
        this.state = {
            deposit_amount: null,
            deposit_info: null,
            deposit_error: null
        };
    }

   onDepositAmountChange( {amount, asset} ) {
      this.setState( {deposit_amount:amount} );
   }

   onSubmitDeposit() {
     let asset = this.props.receive_asset;
     let precision = utils.get_asset_precision(asset.get("precision"));
     let amount = this.state.deposit_amount.replace( /,/g, "" )
     console.log( "deposit_amount: ", amount );

     let json_rpc_request = {
      "jsonrpc": "2.0",
      "method": "getDepositAccount",
      "params": {
         "bitsharesAccountName": this.props.account.get('name'),
         "currency": this.props.deposit_asset,
         "amount": amount
      },
      "id": 1
     };

     let is_deposit_approved_promise = fetch(this.props.rpc_url,
                                             {method: 'POST',
                                              headers: new Headers({"Accept": "application/json",
                                              "content-type":"application/x-www-form-urlencoded"}),
                                              body: 'rq=' + encodeURIComponent(JSON.stringify(json_rpc_request)) })
                                          .then(response => response.json());

     is_deposit_approved_promise.then((json_response) => {
       if ('result' in json_response)
         this.setState({ deposit_info: json_response.result });
       else if ('error' in json_reponse && 'message' in json_response.error)
         this.setState({ deposit_error: json_response.error.message });
       else
         this.setState({ deposit_error: 'Unable to approve deposit, please contact OpenLedger or try again later' });
     })
     .catch((error) => {
       this.setState({ deposit_error: 'Unable to approve deposit, please contact OpenLedger or try again later' });
     });
;
   }

   onClose() {
      // reset the state so the next time the dialog is launched, it doesn't show the old data
      this.setState({
         deposit_amount: null,
         deposit_info: null,
         deposit_error: null
      });
      ZfApi.publish(this.props.modal_id, "close");
   }

    render() {
       if (this.state.deposit_error) // then we've failed to approve them
       {
          return (<form className="grid-block vertical full-width-content">
                    <div className="grid-container">
                      <div className="content-block">
                         <h3>Deposit Error</h3>
                      </div>
                      <div className="content-block">
                        <p>{ this.state.deposit_error }</p>
                      </div>
                      <div className="content-block">
                        <input type="submit" className="button"
                               onClick={this.onClose.bind(this)}
                               value="Close" />
                      </div>
                    </div>
                  </form>);
       }
       else if (this.state.deposit_info) // then they've been approved for deposit
       {
          if ('link' in this.state.deposit_info)
             return (<form className="grid-block vertical full-width-content">
                       <div className="grid-container">
                         <div className="content-block">
                            <h3>Deposit Information</h3>
                         </div>
                         <div className="content-block">
                           <p>Click <a href="#" onClick={(e)=>{ window.open(this.state.deposit_info.link,'_blank');}} rel="noopener noreferrer" target="_blank">here</a> for deposit instructions</p>

                         </div>
                         <div className="content-block">
                        <input type="submit" className="button"
                               onClick={this.onClose.bind(this)}
                               value="Close" />
                         </div>
                       </div>
                     </form>);
{'fraction_non_alphanumeric': 0.11269510926118627, 'fraction_numerical': 0.0014568158168574402, 'mean_word_length': 1.6876398210290828, 'pattern_counts': {'":': 18, '<': 67, '<?xml version=': 0, '>': 74, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 20, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6542691', 'n_tokens_mistral': 2520, 'n_tokens_neox': 2428, 'n_words': 527}