<commit_before>/**
 * @fileOverview WalletCtrl angular controller
 */
'use strict';

define(['./module', 'darkwallet', 'frontend/port'],
function (controllers, DarkWallet, Port) {
  'use strict';

  /**
   * Controller
   */
  controllers.controller('WalletCtrl',
  ['$scope', '$location', 'clipboard', 'modals', '$wallet', '$animate', '$tabs',
      function($scope, $location, clipboard, modals, $wallet, $animate, $tabs) {

  // Scope variables
  $scope.rates = {};
  $scope.totalBalance = 0;
  $scope.forms = {readOnlyArray: []};
  $scope.identityName = false;

  $scope.allReadOnly = {};

  // Global scope utils
  $scope.modals = modals;
  $scope.clipboard = clipboard;

  $scope.openWallet = $tabs.openWallet;
 
  /**
   * Wallet Port
   * Sends notifications about wallet state and identity change
   */
  Port.connectNg('wallet', $scope, function(data) {
      if (data.type == 'ready') {
          var updated = identityLoaded(DarkWallet.getIdentity());
          if(updated && !$scope.$$phase) {
              $scope.$apply();
          }
      }
      else if (data.type == 'rename') {
          $scope.identityName = data.newName;
          $scope.availableIdentities = DarkWallet.getKeyRing().availableIdentities;
      }
      else if (data.type == 'height') {
          $scope.currentHeight = data.value;
      }
      else if (data.type == 'ticker') {
          $scope.rates[data.currency] = data.rate;
      }
      else if (data.type == 'address') {
          var identity = DarkWallet.getIdentity();
          var walletAddress = identity.wallet.getAddress(data.index);
          if (walletAddress) {
              $wallet.addToScope(walletAddress);
          }
      }
  });


  /**
   * Check if a route is active
   */
  $scope.isActive = function(route) {
    return route === $location.path().slice(0, route.length);
  };

  $scope.updateReadOnly = function(identity) {
      $scope.allReadOnly = identity.wallet.pockets.pockets.readonly;
  };

  $scope.updateReadOnlyPockets = function(identity) {
      this.updateReadOnly(identity);
      $scope.forms.readOnlyArray.splice(0, $scope.forms.readOnlyArray.length);
      var keys = Object.keys($scope.allReadOnly);
      keys.forEach(function(pocketId) {
          $scope.forms.readOnlyArray.push($scope.allReadOnly[pocketId]);
      });
  };

  /**
   * Link given identity to the scope
   */
  function linkIdentity(identity) {
      // Link pockets and funds
      $scope.hdPockets = identity.wallet.pockets.hdPockets;
      $scope.allFunds = identity.wallet.multisig.funds;

      // Sync read only pockets
      $scope.updateReadOnly(identity);

      // set some links
      $scope.availableIdentities = DarkWallet.getKeyRing().availableIdentities;
      $scope.settings = identity.settings;

      // get the balance for the wallet<commit_msg>Fix updating watch pockets in inverse way.<commit_after>/**
 * @fileOverview WalletCtrl angular controller
 */
'use strict';

define(['./module', 'darkwallet', 'frontend/port'],
function (controllers, DarkWallet, Port) {
  'use strict';

  /**
   * Controller
   */
  controllers.controller('WalletCtrl',
  ['$scope', '$location', 'clipboard', 'modals', '$wallet', '$animate', '$tabs',
      function($scope, $location, clipboard, modals, $wallet, $animate, $tabs) {

  // Scope variables
  $scope.rates = {};
  $scope.totalBalance = 0;
  $scope.forms = {readOnlyArray: []};
  $scope.identityName = false;

  $scope.allReadOnly = {};

  // Global scope utils
  $scope.modals = modals;
  $scope.clipboard = clipboard;

  $scope.openWallet = $tabs.openWallet;
 
  /**
   * Wallet Port
   * Sends notifications about wallet state and identity change
   */
  Port.connectNg('wallet', $scope, function(data) {
      if (data.type == 'ready') {
          var updated = identityLoaded(DarkWallet.getIdentity());
          if(updated && !$scope.$$phase) {
              $scope.$apply();
          }
      }
      else if (data.type == 'rename') {
          $scope.identityName = data.newName;
          $scope.availableIdentities = DarkWallet.getKeyRing().availableIdentities;
      }
      else if (data.type == 'height') {
          $scope.currentHeight = data.value;
      }
      else if (data.type == 'ticker') {
          $scope.rates[data.currency] = data.rate;
      }
      else if (data.type == 'address') {
          var identity = DarkWallet.getIdentity();
          var walletAddress = identity.wallet.getAddress(data.index);
          if (walletAddress) {
              $wallet.addToScope(walletAddress);
          }
      }
  });


  /**
   * Check if a route is active
   */
  $scope.isActive = function(route) {
    return route === $location.path().slice(0, route.length);
  };

  $scope.updateReadOnly = function(identity) {
      $scope.allReadOnly = identity.wallet.pockets.pockets.readonly;
      this.updateReadOnlyPockets(identity);
  };

  $scope.updateReadOnlyPockets = function(identity) {
      $scope.forms.readOnlyArray.splice(0, $scope.forms.readOnlyArray.length);
      var keys = Object.keys($scope.allReadOnly);
      keys.forEach(function(pocketId) {
          $scope.forms.readOnlyArray.push($scope.allReadOnly[pocketId]);
      });
  };

  /**
   * Link given identity to the scope
   */
  function linkIdentity(identity) {
      // Link pockets and funds
      $scope.hdPockets = identity.wallet.pockets.hdPockets;
      $scope.allFunds = identity.wallet.multisig.funds;

      // Sync read only pockets
      $scope.updateReadOnly(identity);

      // set some links
      $scope.availableIdentities = DarkWallet.getKeyRing().availableIdentities;
      $scope.settings = identity.settings;

      // get the balance for the wallet
{'fraction_non_alphanumeric': 0.145444952514949, 'fraction_numerical': 0.001055223355610271, 'mean_word_length': 2.7712201591511936, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '7037886', 'n_tokens_mistral': 1721, 'n_tokens_neox': 1726, 'n_words': 337}