Refresh balance on new block

This commit is contained in:
Yemel Jardi 2014-06-23 14:57:23 -03:00
parent 26c829f6de
commit e1dc275ddd
2 changed files with 13 additions and 0 deletions

View File

@ -292,6 +292,15 @@ angular.module('copayApp.services')
});
});
});
if (!$rootScope.wallet.spendUnconfirmed && !Socket.isListeningBlocks()) {
Socket.emit('subscribe', 'inv');
Socket.on('block', function(block) {
root.updateBalance(function() {
$rootScope.$digest();
});
});
}
};
return root;
});

View File

@ -38,6 +38,7 @@ angular.module('copayApp.services').factory('Socket',
var ret = {};
var addrList = listeners
.filter(function(i) { return i.event != 'block'; })
.map(function(i) {return i.event;});
for (var i in addrList) {
@ -45,6 +46,9 @@ angular.module('copayApp.services').factory('Socket',
}
return ret;
},
isListeningBlocks: function() {
return listeners.filter(function(i) { return i.event == 'block'; }).length > 0;
},
emit: function(event, data, callback) {
socket.emit(event, data, function() {
var args = arguments;