Initial getBalance of all your addresses. Socket-io that listening if your address receives btc.

Known bug: if you add new the address you can to recall socket-io. Socket-io should be listening on headerController.
This commit is contained in:
Gustavo Cortez 2014-04-17 06:43:30 -03:00
commit eaa1bc37e0
7 changed files with 54 additions and 10 deletions

View file

@ -1,7 +1,7 @@
'use strict';
angular.module('copay.header').controller('HeaderController',
function($scope, $rootScope, $location, walletFactory) {
function($scope, $rootScope, $location, walletFactory, Socket) {
$scope.menu = [{
'title': 'Home',
'icon': 'fi-home',
@ -24,7 +24,7 @@ angular.module('copay.header').controller('HeaderController',
'link': '#/backup'
}];
if (!$rootScope.peerId) {
if (!$rootScope.wallet || !$rootScope.wallet.id) {
$location.path('signin');
}
@ -40,6 +40,8 @@ angular.module('copay.header').controller('HeaderController',
if (w) {
w.disconnect();
delete $rootScope['wallet'];
var socket = Socket($scope);
socket.removeAllListeners();
$location.path('signin');
}
};
@ -47,4 +49,5 @@ angular.module('copay.header').controller('HeaderController',
$scope.clearFlashMessage = function() {
$rootScope.flashMessage = {};
};
});

View file

@ -1,10 +1,31 @@
'use strict';
angular.module('copay.peer').controller('PeerController',
function($scope, $rootScope, $location, $routeParams) {
function($scope, $rootScope, $location, $routeParams, Socket) {
$scope.init = function() {
//Network.connect($rootScope.masterId);
};
var addrs = $rootScope.wallet.getAddressesStr();
var socket = Socket($scope);
socket.on('connect', function() {
socket.emit('subscribe', 'inv');
for(var i=0;i<addrs.length;i++) {
socket.emit('subscribe', addrs[i]);
}
addrs.forEach(function(addr) {
socket.on(addr, function(txid) {
console.log('Received!', txid);
$rootScope.wallet.getBalance(function(balance) {
$scope.$apply(function() {
$rootScope.totalBalance = balance;
});
console.log('New balance:', balance);
});
});
});
});
});

View file

@ -17,6 +17,14 @@ angular.module('copay.signin').controller('SigninController',
w.on('created', function() {
$location.path('peer');
$rootScope.wallet = w;
// Initial getBalance
$rootScope.wallet.getBalance(function(balance) {
$scope.$apply(function() {
$rootScope.totalBalance = balance;
});
});
$rootScope.$digest();
});
w.on('refresh', function() {