<commit_before>import { Component, View, CORE_DIRECTIVES, FORM_DIRECTIVES, EventEmitter} from 'angular2/angular2';
import { RouterLink } from "angular2/router";
import { Client } from '../../../../services/api';
import { Material } from '../../../../directives/material';
import { MindsWalletResponse } from '../../../../interfaces/responses';
import { MindsUserSearchResponse } from '../../../../interfaces/responses';
import { MindsBoostResponse } from '../../../../interfaces/responses';
import { MindsBoostRateResponse } from '../../../../interfaces/responses';

@Component({
  selector: 'minds-boost-full-network',
  viewBindings: [ Client ],
  properties: ['object'],
  events: ['_done: done']
})
@View({
  templateUrl: 'src/controllers/boosts/boost/full-network/full-network.html',
  directives: [ FORM_DIRECTIVES, CORE_DIRECTIVES, Material, RouterLink]
})

export class BoostFullNetwork{

  _done: EventEmitter<any> = new EventEmitter();

  activity : any;
  data = {
    destination: '',
    points: 0,
    impressions: 0
  };
  rate : any = {
    balance: 0,
    rate: 1,
    min: 10,
    cap: 1000
  }

  inProgress : boolean = false;
  error : string = "";

  constructor(public client: Client){
    //get the rates and balance
    this.client.get('api/v1/boost/rates', { cb: Date.now() })
      .then((success : MindsBoostRateResponse) => {
        this.rate = success;
      });
  }

  set object(value: any) {
    this.activity = value;
  }

  boost() {
    var self =  this;
    this.inProgress = true;
    this.error = "";

    if (this.data.points % 1 !== 0) {
      this.data.points = Math.round(this.data.points);
      this.error = 'Sorry, you must enter a whole point.';
      this.inProgress = false;
      return false;
    }

    if (this.data.points === 0 || !this.data.points) {
      this.data.points = 1;
      this.error ='Sorry, you must enter a whole point.';
      this.inProgress = false;
      return false;
    }

    if (this.data.impressions === 0 || Math.round(this.data.impressions) === 0) {
      this.error = 'Sorry, you must have at least 1 impression.';
      this.inProgress = false;
      return false;
    }

    if (!this.checkBalance())
      return false;

    //commence the boost
    this.client.post( 'api/v1/boost/newsfeed/' + this.activity.guid + '/' + this.activity.owner_guid,
      {
        impressions: this.data.impressions,
        destination: this.data.destination
      })
      .then((success : MindsBoostResponse) => {
        self.inProgress = false;

        //?
        self._done.next(true);
      })
      .catch((e) => {
        self.handleErrorMessage('Sorry, something went wrong.');
        return false;
      });

  }

  handleErrorMessage(message : string){
    this.error = message;
    this.inProgress = false;
  }

  checkBalance(){
    if (this.rate.balance < this.data.points) {
      this.handleErrorMessage('Ooops! You don\'t have enough points');
      return false;
    }
<commit_msg>(fix): prevent double click for submitting a boost<commit_after>import { Component, View, CORE_DIRECTIVES, FORM_DIRECTIVES, EventEmitter} from 'angular2/angular2';
import { RouterLink } from "angular2/router";
import { Client } from '../../../../services/api';
import { Material } from '../../../../directives/material';
import { WalletService } from '../../../../services/wallet';
import { MindsWalletResponse } from '../../../../interfaces/responses';
import { MindsUserSearchResponse } from '../../../../interfaces/responses';
import { MindsBoostResponse } from '../../../../interfaces/responses';
import { MindsBoostRateResponse } from '../../../../interfaces/responses';

@Component({
  selector: 'minds-boost-full-network',
  viewBindings: [ Client ],
  properties: ['object'],
  events: ['_done: done']
})
@View({
  templateUrl: 'src/controllers/boosts/boost/full-network/full-network.html',
  directives: [ FORM_DIRECTIVES, CORE_DIRECTIVES, Material, RouterLink]
})

export class BoostFullNetwork{

  _done: EventEmitter<any> = new EventEmitter();

  activity : any;
  data = {
    destination: '',
    points: 0,
    impressions: 0
  };
  rate : any = {
    balance: 0,
    rate: 1,
    min: 10,
    cap: 1000
  }

  inProgress : boolean = false;
  error : string = "";

  constructor(public client: Client, public wallet: WalletService){
    //get the rates and balance
    this.client.get('api/v1/boost/rates', { cb: Date.now() })
      .then((success : MindsBoostRateResponse) => {
        this.rate = success;
      });
  }

  set object(value: any) {
    this.activity = value;
  }

  boost() {

    if(this.inProgress)
      return;
    this.inProgress = true;
    this.error = "";

    if (this.data.points % 1 !== 0) {
      this.data.points = Math.round(this.data.points);
      this.error = 'Sorry, you must enter a whole point.';
      this.inProgress = false;
      return false;
    }

    if (this.data.points === 0 || !this.data.points) {
      this.data.points = 1;
      this.error ='Sorry, you must enter a whole point.';
      this.inProgress = false;
      return false;
    }

    if (this.data.impressions === 0 || Math.round(this.data.impressions) === 0) {
      this.error = 'Sorry, you must have at least 1 impression.';
      this.inProgress = false;
      return false;
    }

    if (!this.checkBalance())
      return false;

    //commence the boost
    this.client.post( 'api/v1/boost/newsfeed/' + this.activity.guid + '/' + this.activity.owner_guid,
      {
        impressions: this.data.impressions,
        destination: this.data.destination
      })
      .then((success : MindsBoostResponse) => {
        this.inProgress = false;
        this.wallet.decrement(this.data.points);

        //?
        this._done.next(true);
      })
      .catch((e) => {
        this.error = 'Sorry, something went wrong.';
        this.inProgress = false;
      });

  }

  handleErrorMessage(message : string){
    this.error = message;
    this.inProgress = false;
  }

  checkBalance(){
    if (this.rate.balance < this.data.points) {
      this.handleErrorMessage('Ooops! You don\'t have enough points');
      return false;
    }

{'fraction_non_alphanumeric': 0.16115365813915594, 'fraction_numerical': 0.007169626853511487, 'mean_word_length': 2.568604651162791, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, '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': '2368056', 'n_tokens_mistral': 1960, 'n_tokens_neox': 1921, 'n_words': 435}