<commit_before>import { Template } from 'meteor/templating';
import './rainbow.js';
const REWARDCOEFFICIENT = 60000000;

Template.bounties.onRendered(function(){
  Session.set('workingBounty', false);
  Meteor.setInterval(function() {
      Session.set('now', Date.now());
  }, 10);
});


Template.bounties.helpers({
  activebounty: function () {
    return [{
      _id: "23562356",
      currencyName: "Bitcoin",
      bountyType: "API",
      creationTime: 1509781011000,
      currentlyAvailable: true,
      currentUsername: null
    }];
  },
  bounties: function() {
    return [{
      _id: "23562356",
      currencyName: "Bitcoin",
      bountyType: "API",
      creationTime: 1509781011000,
      currentlyAvailable: true,
      currentUsername: null
    },
    {
      _id: "43564546",
      currencyName: "Dash",
      bountyType: "API",
      creationTime: 1509776537000,
      currentlyAvailable: false,
      currentUsername: "Roger Ver"
    }];
  }
});

Template.bountyRender.helpers({
  id: function() {
    return this._id;
  },
  bountyDetails: function () {
    return "After clicking start, you will have 30 minutes to complete this bounty. You need to: [1] find a block explorer or open node which can provide the current network hash rate, [2] construct an API call to get the current hash rate, and [3] tell Blockrazor how to consume the response so that the final result is an integer."//DB call to get bounty details for this bounty type
  },
  workingText: function () {
    if(this.currentlyAvailable == false) {
        return this.currentUsername + " is working on this right now!";
    } else { return null;}
  },
  buttonClass: function() {
    if(this.currentlyAvailable == true) {
        return "btn-outline-primary takeBounty";
    } else { return "btn-outline-secondary";}
  },
  bountyTypeHeading: function () {
    return "Find and provide API call details"; //find the description for this.bountyType bounty type in DB
  },
  problem: function () {
    return "Blockrazor doesn't know how to get the current hash power for"; //find problem description for this.bountyType from DB
  },
  solution: function () {
    return "find a block explorer or open node and provide the API call (and the response object details) so that Blockrazor can keep itself updated"; //as above
  },
  reward: function () {
    return ((Session.get('now') - this.creationTime) / REWARDCOEFFICIENT).toFixed(6);
  }
});

Template.bountyRender.events({
  'click .start': function () {
    Session.set('workingBounty', true);
    //Session.set('bountyItem', this._id);
    Cookies.set('bountyItem', this._id, { expires: 1});
    Cookies.set('bountyType', this.bountyType, { expires: 1});
    Session.set('bountyType', this.bountyType);
    //Meteor.call('startBounty', this._id); //Make a meteor call to change the status of the bounty to being worked on by <username> and add "working on bounty" to their profile so they cant take another one at the same time.
    FlowRouter.go("/bounties/" + this._id);
  },
  'click .cancel': function() {
    $('#' + this._id).hide();
    $('#takeBounty' + this._id).show();
  },
  'click .takeBounty': function() {
    $('#' + this._id).show();
    $('#takeBounty' + this._id).hide();
  }
})

Template.activeBounty.onRendered(function(){
  Session.set('bountyType', Cookies.get('bountyType'));

});

Template.activeBounty.helpers({
  thisbounty () {
    return FlowRouter.getParam("_id");
  },
  thisitem: function () {
//    console.log(this.data._id);
    return "sdfgsdfg";
  }
});
Template.activeBounty.events({});

Template.APIbounty.events({
  'click .submit': function () {
    if ($('#apiCall').val() == "https://moneroblocks.info/api/get_stats") {
      sAlert.error("Looks like you haven't updated the form and you're trying to submit the example data! Please try again.", {stack: false, position: 'top'});
    } else if (!$('#hashrate-result').text()) {
      sAlert.error("Looks like you haven't found the hashrate! Please try again.", {stack: false, position: 'top'});
    } else if (typeof parseInt($('#hashrate-result').text()) != "number") {
      sAlert.error("That hashrate doesn't looke like a number.", {stack: false, position: 'top'});
    } else {
      console.log("hashate ok");
    }
;  },
  'click .fetch': function() {
    var d = $('#apiCall').val();<commit_msg>Problem: not all API data included<commit_after>import { Template } from 'meteor/templating';
import './rainbow.js';
const REWARDCOEFFICIENT = 60000000;

Template.bounties.onRendered(function(){
  Session.set('workingBounty', false);
  Meteor.setInterval(function() {
      Session.set('now', Date.now());
  }, 10);
});


Template.bounties.helpers({
  activebounty: function () {
    return [{
      _id: "23562356",
      currencyName: "Bitcoin",
      bountyType: "API",
      creationTime: 1509781011000,
      currentlyAvailable: true,
      currentUsername: null
    }];
  },
  bounties: function() {
    return [{
      _id: "23562356",
      currencyName: "Bitcoin",
      bountyType: "API",
      creationTime: 1509781011000,
      currentlyAvailable: true,
      currentUsername: null
    },
    {
      _id: "43564546",
      currencyName: "Dash",
      bountyType: "API",
      creationTime: 1509776537000,
      currentlyAvailable: false,
      currentUsername: "Roger Ver"
    }];
  }
});

Template.bountyRender.helpers({
  id: function() {
    return this._id;
  },
  bountyDetails: function () {
    return "After clicking start, you will have 30 minutes to complete this bounty. You need to: [1] find a block explorer or open node which can provide the current network hash rate, [2] construct an API call to get the current hash rate, and [3] tell Blockrazor how to consume the response so that the final result is an integer."//DB call to get bounty details for this bounty type
  },
  workingText: function () {
    if(this.currentlyAvailable == false) {
        return this.currentUsername + " is working on this right now!";
    } else { return null;}
  },
  buttonClass: function() {
    if(this.currentlyAvailable == true) {
        return "btn-outline-primary takeBounty";
    } else { return "btn-outline-secondary";}
  },
  bountyTypeHeading: function () {
    return "Find and provide API call details"; //find the description for this.bountyType bounty type in DB
  },
  problem: function () {
    return "Blockrazor doesn't know how to get the current hash power for"; //find problem description for this.bountyType from DB
  },
  solution: function () {
    return "find a block explorer or open node and provide the API call (and the response object details) so that Blockrazor can keep itself updated"; //as above
  },
  reward: function () {
    return ((Session.get('now') - this.creationTime) / REWARDCOEFFICIENT).toFixed(6);
  }
});

Template.bountyRender.events({
  'click .start': function () {
    Session.set('workingBounty', true);
    //Session.set('bountyItem', this._id);
    Cookies.set('bountyItem', this._id, { expires: 1});
    Cookies.set('bountyType', this.bountyType, { expires: 1});
    Session.set('bountyType', this.bountyType);
    //Meteor.call('startBounty', this._id); //Make a meteor call to change the status of the bounty to being worked on by <username> and add "working on bounty" to their profile so they cant take another one at the same time.
    FlowRouter.go("/bounties/" + this._id);
  },
  'click .cancel': function() {
    $('#' + this._id).hide();
    $('#takeBounty' + this._id).show();
  },
  'click .takeBounty': function() {
    $('#' + this._id).show();
    $('#takeBounty' + this._id).hide();
  }
})

Template.activeBounty.onRendered(function(){
  Session.set('bountyType', Cookies.get('bountyType'));

});

Template.activeBounty.helpers({
  thisbounty () {
    return FlowRouter.getParam("_id");
  },
  thisitem: function () {
//    console.log(this.data._id);
    return "sdfgsdfg";
  }
});
Template.activeBounty.events({});

Template.APIbounty.events({
  'click .submit': function () {
    //Functions to check data:
    //Hashrate
    var checkHashrateCall = function () {
      if ($('#apiCall').val() == "https://moneroblocks.info/api/get_stats") {
        sAlert.error("Looks like you haven't updated the form and you're trying to submit the example data! Please try again.", {stack: false, position: 'top'});
      } else if (!parseInt($('#hashrate-result').text())) {
        sAlert.error("Looks like you haven't found the hashrate! Please try again.", {stack: false, position: 'top'});
      } else {
        hashrateCall = true;
        apiData.apiCall = $('#apiCall').val();
        apiData.hashrate = $('#hashrate').val();
        apiData.bountyId = FlowRouter.getParam("_id");
      }
    };
    // Blockchain height
    var checkBlockchainHeight = function () {
      if ($('#height-result').text()) {
        apiData.height = $('#height').val();
      }
    };
    // Timestamp
    var checkTimestamp = function () {
      if ($('#timestamp-result').text()) {
        apiData.timestamp = $('#timestamp').val();
      }
    };
    //Block Reward
    var checkBlockReward = function () {
      if ($('#reward-result').text()) {
        apiData.reward = $('#reward').val();
        apiData.decimal = Math.pow(10, parseInt($('#decimal').val()));
      }
    };
    //Total Coins
    var checkTotalCoins = function () {
      if ($('#emission-result').text()) {
        apiData.emissions = $('#emission').val();
        apiData.decimal = Math.pow(10, parseInt($('#decimal').val()));
      }
    }

    var apiData = {};
    var hashrateCall = false;
    checkHashrateCall();
    checkBlockchainHeight();
    checkTimestamp();
    checkBlockReward();
    checkTotalCoins();
    Meteor.call('completeAPIbounty', apiData, function(error, result) {
      if (error) {
        sAlert.error(error.reason, {stack: false, position: 'top'});
      } else if (result) {
        FlowRouter.go("/mypendingbounties");
      }

    });

  },
  'click .fetch': function() {
    var d = $('#apiCall').val();
{'fraction_non_alphanumeric': 0.15264890751272076, 'fraction_numerical': 0.01656190761249127, 'mean_word_length': 3.249258160237389, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, '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': '909362', 'n_tokens_mistral': 3275, 'n_tokens_neox': 3036, 'n_words': 844}