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

define(['./module', 'darkwallet', 'frontend/port'], function (controllers, DarkWallet, Port) {
  controllers.controller('OverviewCtrl', ['$scope', function($scope) {

  $scope.allPockets = [];

  /**
   * Select a pocket from the grid
   */
  $scope.selectGridPocket = function(pocket) {
      if (pocket.type == 'pocket') {
          $scope.selectPocket(pocket.name, pocket.index);
      } else if (pocket.type == 'fund') {
          $scope.selectFund(pocket.fund, pocket.index);
      }
  };

  /**
   * Update a pocket's information in place
   */
  var updatePocket = function(newData, position) {
      var found = $scope.allPockets.filter(function(pocket) {return (newData.type == pocket.type && newData.name == pocket.name)});
      if (found.length) {
          Object.keys(newData).forEach(function(key) {
              found[key] = newData[key];
          });
      } else if (position) {
          $scope.allPockets.splice(position, 0, newData);
      } else {
          $scope.allPockets.push(newData);
      }
  }

  /**
   * Calculate all balances
   */
  var calculateBalances = function() {
      var identity = DarkWallet.getIdentity();

      var total = {confirmed: 0, unconfirmed: 0};

      identity.wallet.pockets.hdPockets.forEach(function(pocket, i) {
          if (!pocket) {
              return;
          }
          var balance = identity.wallet.getBalance(i*2);
          total.confirmed += balance.confirmed;
          total.unconfirmed += balance.unconfirmed;
          updatePocket({name: pocket.name, mixing: pocket.mixing, balance: balance, type: 'pocket', index: i});
      });
      identity.wallet.multisig.funds.forEach(function(fund, i) {
          if (!fund) {
              return;
          }
          var balance = identity.wallet.getBalance(fund.address);
          total.confirmed += balance.confirmed;
          total.unconfirmed += balance.unconfirmed;
          updatePocket({name: fund.name, mixing: fund.mixing, balance: balance, type: 'fund', fund: fund, index: i});
      });
      updatePocket({name: 'Total', balance: total, type: 'total'}, identity.wallet.pockets.hdPockets.length-1);
 
  };
<commit_msg>Add change balance in the overview.<commit_after>/**
 * @fileOverview OverviewCtrl angular controller
 */
'use strict';

define(['./module', 'darkwallet', 'frontend/port'], function (controllers, DarkWallet, Port) {
  controllers.controller('OverviewCtrl', ['$scope', function($scope) {

  $scope.allPockets = [];

  /**
   * Select a pocket from the grid
   */
  $scope.selectGridPocket = function(pocket) {
      if (pocket.type == 'pocket') {
          $scope.selectPocket(pocket.name, pocket.index);
      } else if (pocket.type == 'fund') {
          $scope.selectFund(pocket.fund, pocket.index);
      }
  };

  /**
   * Update a pocket's information in place
   */
  var updatePocket = function(newData, position) {
      var found = $scope.allPockets.filter(function(pocket) {return (newData.type == pocket.type && newData.name == pocket.name)});
      if (found.length) {
          Object.keys(newData).forEach(function(key) {
              found[key] = newData[key];
          });
      } else if (position) {
          $scope.allPockets.splice(position, 0, newData);
      } else {
          $scope.allPockets.push(newData);
      }
  }

  /**
   * Calculate all balances
   */
  var calculateBalances = function() {
      var identity = DarkWallet.getIdentity();

      var total = {confirmed: 0, unconfirmed: 0};

      identity.wallet.pockets.hdPockets.forEach(function(pocket, i) {
          if (!pocket) {
              return;
          }
          var balance = identity.wallet.getBalance(i*2);
          var balance2 = identity.wallet.getBalance((i*2)+1);
          balance.confirmed += balance2.confirmed;
          balance.unconfirmed += balance2.unconfirmed;
          total.confirmed += balance.confirmed;
          total.unconfirmed += balance.unconfirmed;
          updatePocket({name: pocket.name, mixing: pocket.mixing, balance: balance, type: 'pocket', index: i});
      });
      identity.wallet.multisig.funds.forEach(function(fund, i) {
          if (!fund) {
              return;
          }
          var balance = identity.wallet.getBalance(fund.address);
          total.confirmed += balance.confirmed;
          total.unconfirmed += balance.unconfirmed;
          updatePocket({name: fund.name, mixing: fund.mixing, balance: balance, type: 'fund', fund: fund, index: i});
      });
      updatePocket({name: 'Total', balance: total, type: 'total'}, identity.wallet.pockets.hdPockets.length-1);
 
  };

{'fraction_non_alphanumeric': 0.1457533077251387, 'fraction_numerical': 0.003201024327784891, 'mean_word_length': 2.6026133743274404, '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': '4494466', 'n_tokens_mistral': 1429, 'n_tokens_neox': 1370, 'n_words': 284}