copay/js/controllers/home.js

43 lines
1.2 KiB
JavaScript
Raw Normal View History

2014-03-26 05:18:42 -07:00
'use strict';
angular.module('copay.home').controller('HomeController',
function($scope, $rootScope, $location, Socket, controllerUtils) {
2014-03-26 05:18:42 -07:00
$scope.title = 'Home';
2014-03-26 13:56:11 -07:00
2014-03-26 14:07:28 -07:00
$scope.oneAtATime = true;
2014-04-16 14:01:37 -07:00
$scope.addrBalance = {};
2014-04-16 14:01:37 -07:00
var _getBalance = function() {
$scope.addrs.forEach(function(addr) {
2014-04-17 12:42:27 -07:00
$rootScope.wallet.getBalance([addr], function(balance) {
2014-04-16 14:01:37 -07:00
$scope.addrBalance[addr] = balance;
$scope.$digest();
});
});
};
2014-03-26 14:07:28 -07:00
if (!$rootScope.wallet || !$rootScope.wallet.id) {
$location.path('signin');
2014-04-16 14:01:37 -07:00
} else {
2014-04-15 14:23:35 -07:00
$scope.addrs = $rootScope.wallet.getAddressesStr();
$scope.selectedAddr = $scope.addrs[0];
2014-04-16 14:01:37 -07:00
_getBalance();
var socket = Socket($scope);
socket.on('connect', controllerUtils.handleTransactionByAddress($scope));
}
$scope.newAddr = function() {
2014-04-16 14:01:37 -07:00
var a = $rootScope.wallet.generateAddress().toString();
$scope.addrs.push(a);
_getBalance();
var socket = Socket($scope);
socket.on('connect', controllerUtils.handleTransactionByAddress($scope));
};
$scope.selectAddr = function(addr) {
$scope.selectedAddr = addr;
};
2014-03-26 05:18:42 -07:00
});