Known bug: if you add new the address you can to recall socket-io. Socket-io should be listening on headerController.
31 lines
873 B
JavaScript
31 lines
873 B
JavaScript
'use strict';
|
|
|
|
angular.module('copay.peer').controller('PeerController',
|
|
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);
|
|
});
|
|
});
|
|
});
|
|
});
|
|
|
|
});
|
|
|