<commit_before>'use strict';
var bitcore = require('bitcore');

angular.module('copayApp.controllers').controller('SendController',
  function($scope, $rootScope, $window, $timeout, $anchorScroll, $modal, isMobile, notification, controllerUtils) {
    $scope.title = 'Send';
    $scope.loading = false;
    var satToUnit = 1 / config.unitToSatoshi;
    $scope.defaultFee = bitcore.TransactionBuilder.FEE_PER_1000B_SAT * satToUnit;
    $scope.unitToBtc = config.unitToSatoshi / bitcore.util.COIN;

    $scope.loadTxs = function() {
      var opts = {
        pending: true,
        skip: null
      };
      controllerUtils.updateTxs(opts);
      setTimeout(function() {
        $scope.loading = false;
        $rootScope.$digest();
      }, 0);
    }

    $scope.showAddressBook = function() {
      var w = $rootScope.wallet;
      var flag;
      if (w) {
        for (var k in w.addressBook) {
          if (w.addressBook[k]) {
            flag = true;
            break;
          }
        }
      }
      return flag;
    };

    if ($rootScope.pendingPayment) {
      var pp = $rootScope.pendingPayment;
      $scope.address = pp.address;
      var amount = pp.amount / config.unitToSatoshi * 100000000;
      $scope.amount = amount;
    }

    navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia;
    window.URL = window.URL || window.webkitURL || window.mozURL || window.msURL;
    $scope.isMobile = isMobile.any();

    $scope.submitForm = function(form) {
      if (form.$invalid) {
        var message = 'Unable to send transaction proposal.';
        notification.error('Error', message);
        return;
      }

      $scope.loading = true;

      var address = form.address.$modelValue;
      var amount = (form.amount.$modelValue * config.unitToSatoshi) | 0;
      var commentText = form.comment.$modelValue;

      var w = $rootScope.wallet;

      function done(ntxid, ca) {
        if (w.isShared()) {
          $scope.loading = false;
          var message = 'The transaction proposal has been created';
          if (ca) {
            message += '.\nThis payment protocol transaction'
              + 'has been verified through ' + ca;
          }
          notification.success('Success!', message);
          $scope.loadTxs();
        } else {
          w.sendTx(ntxid, function(txid, ca) {
            if (txid) {
              notification.success('Transaction broadcast', 'Transaction id: ' + txid);
              if (ca) notification.success('Root Certificate', ca);
            } else {
              notification.error('Error', 'There was an error sending the transaction.');
            }
            $scope.loading = false;
            $scope.loadTxs();
          });
        }
        $rootScope.pendingPayment = null;
      }

      var uri = address.indexOf('bitcoin:') === 0
        && copay.HDPath.parseBitcoinURI(address);
      if (uri.merchant) {
        w.createTx(uri.merchant, commentText, done);
      } else {
        w.createTx(address, amount, commentText, done);
      }

      // reset fields
      $scope.address = $scope.amount = $scope.commentText = null;
      form.address.$pristine = form.amount.$pristine = true;
    };

    // QR code Scanner
    var cameraInput;
    var video;
    var canvas;
    var $video;
    var context;
    var localMediaStream;

    var _scan = function(evt) {
      if ($scope.isMobile) {
        $scope.scannerLoading = true;
        var files = evt.target.files;

        if (files.length === 1 && files[0].type.indexOf('image/') === 0) {
          var file = files[0];

          var reader = new FileReader();<commit_msg>paypro: create real paypro txs. start potentially adding more merchant data to notifications.<commit_after>'use strict';
var bitcore = require('bitcore');

angular.module('copayApp.controllers').controller('SendController',
  function($scope, $rootScope, $window, $timeout, $anchorScroll, $modal, isMobile, notification, controllerUtils) {
    $scope.title = 'Send';
    $scope.loading = false;
    var satToUnit = 1 / config.unitToSatoshi;
    $scope.defaultFee = bitcore.TransactionBuilder.FEE_PER_1000B_SAT * satToUnit;
    $scope.unitToBtc = config.unitToSatoshi / bitcore.util.COIN;

    $scope.loadTxs = function() {
      var opts = {
        pending: true,
        skip: null
      };
      controllerUtils.updateTxs(opts);
      setTimeout(function() {
        $scope.loading = false;
        $rootScope.$digest();
      }, 0);
    }

    $scope.showAddressBook = function() {
      var w = $rootScope.wallet;
      var flag;
      if (w) {
        for (var k in w.addressBook) {
          if (w.addressBook[k]) {
            flag = true;
            break;
          }
        }
      }
      return flag;
    };

    if ($rootScope.pendingPayment) {
      var pp = $rootScope.pendingPayment;
      $scope.address = pp.address;
      var amount = pp.amount / config.unitToSatoshi * 100000000;
      $scope.amount = amount;
    }

    navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia;
    window.URL = window.URL || window.webkitURL || window.mozURL || window.msURL;
    $scope.isMobile = isMobile.any();

    $scope.submitForm = function(form) {
      if (form.$invalid) {
        var message = 'Unable to send transaction proposal.';
        notification.error('Error', message);
        return;
      }

      $scope.loading = true;

      var address = form.address.$modelValue;
      var amount = (form.amount.$modelValue * config.unitToSatoshi) | 0;
      var commentText = form.comment.$modelValue;

      var w = $rootScope.wallet;

      function done(ntxid, ca) {
        var txp = w.txProposals.txps[ntxid];
        var merchantData = txp.merchant;
        if (w.isShared()) {
          $scope.loading = false;
          var message = 'The transaction proposal has been created';
          if (ca) {
            message += '.\nThis payment protocol transaction'
              + 'has been verified through ' + ca + '.';
          }
          notification.success('Success!', message);
          $scope.loadTxs();
        } else {
          w.sendTx(ntxid, function(txid, ca) {
            if (txid) {
              notification.success('Transaction broadcast', 'Transaction id: ' + txid);
              if (ca) {
                notification.success('Root Certificate', ca);
              }
            } else {
              notification.error('Error', 'There was an error sending the transaction.');
            }
            $scope.loading = false;
            $scope.loadTxs();
          });
        }
        $rootScope.pendingPayment = null;
      }

      var uri = address.indexOf('bitcoin:') === 0
        && copay.HDPath.parseBitcoinURI(address);

      if (uri && uri.merchant) {
        w.createPaymentTx({
          uri: uri.merchant,
          memo: commentText
        }, done);
      } else {
        w.createTx(address, amount, commentText, done);
      }

      // reset fields
      $scope.address = $scope.amount = $scope.commentText = null;
      form.address.$pristine = form.amount.$pristine = true;
    };

    // QR code Scanner
    var cameraInput;
    var video;
    var canvas;
    var $video;
    var context;
    var localMediaStream;

    var _scan = function(evt) {
      if ($scope.isMobile) {
        $scope.scannerLoading = true;
        var files = evt.target.files;

        if (files.length === 1 && files[0].type.indexOf('image/') === 0) {
          var file = files[0];

          var reader = new FileReader();
{'fraction_non_alphanumeric': 0.12702561421850497, 'fraction_numerical': 0.005488761108207005, 'mean_word_length': 2.123673469387755, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, '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': '6114097', 'n_tokens_mistral': 2294, 'n_tokens_neox': 2218, 'n_words': 503}