fix join sync

This commit is contained in:
Matias Alejo Garcia 2014-12-02 17:32:32 -03:00
commit 8d7783cac3
4 changed files with 25 additions and 16 deletions

View file

@ -2,12 +2,15 @@
angular.module('copayApp.controllers').controller('HomeWalletController', function($scope, $rootScope) { angular.module('copayApp.controllers').controller('HomeWalletController', function($scope, $rootScope) {
$scope.init = function() { $scope.init = function() {
$rootScope.title = 'Home'; $rootScope.title = 'Home';
$scope.addr = _.last($rootScope.wallet.getReceiveAddresses()); $scope.addr = _.last($rootScope.wallet.getReceiveAddresses());
// This is necesarry, since wallet can change in homeWallet, without running init() again. // This is necesarry, since wallet can change in homeWallet, without running init() again.
$rootScope.$watch('wallet', function() { $rootScope.$watch('wallet', function() {
$scope.addr = _.last($rootScope.wallet.getReceiveAddresses()); if ($rootScope.wallet && $rootScope.wallet.isComplete()) {
$scope.addr = _.last($rootScope.wallet.getReceiveAddresses());
}
}); });
}; };
}); });

View file

@ -474,6 +474,8 @@ Identity.importFromFullJson = function(str, password, opts, cb) {
* @emits newWallet (walletId) * @emits newWallet (walletId)
*/ */
Identity.prototype.bindWallet = function(w) { Identity.prototype.bindWallet = function(w) {
preconditions.checkArgument(w && this.wallets[w.getId()]);
var self = this; var self = this;
log.debug('Binding wallet:' + w.getName()); log.debug('Binding wallet:' + w.getName());
@ -571,13 +573,10 @@ Identity.prototype.createWallet = function(opts, cb) {
opts.version = opts.version || this.version; opts.version = opts.version || this.version;
var self = this; var self = this;
var w = new walletClass(opts); var w = new walletClass(opts);
self.wallets[w.getId()] = w; self.wallets[w.getId()] = w;
self.updateFocusedTimestamp(w.getId()); self.updateFocusedTimestamp(w.getId());
self.bindWallet(w); self.bindWallet(w);
self.updateFocusedTimestamp(w.getId());
self.storeWallet(w, function(err) { self.storeWallet(w, function(err) {
if (err) return cb(err); if (err) return cb(err);

View file

@ -125,7 +125,7 @@ Wallet.TX_SIGNED_AND_BROADCASTED = 'txSignedAndBroadcasted';
Wallet.prototype.emitAndKeepAlive = function(args) { Wallet.prototype.emitAndKeepAlive = function(args) {
var args = Array.prototype.slice.call(arguments); var args = Array.prototype.slice.call(arguments);
log.debug('Wallet:'+ this.getName() + ' Emitting:', args); log.debug('Wallet:' + this.getName() + ' Emitting:', args);
this.keepAlive(); this.keepAlive();
this.emit.apply(this, arguments); this.emit.apply(this, arguments);
}; };
@ -332,14 +332,16 @@ Wallet.prototype._onPublicKeyRing = function(senderId, data) {
return; return;
} }
if (hasChanged) { if (hasChanged) {
if (wasIncomplete) { if (wasIncomplete) {
this.sendPublicKeyRing(); this.sendPublicKeyRing();
} }
if (this.publicKeyRing.isComplete()) { if (this.publicKeyRing.isComplete()) {
this._lockIncomming(); this._lockIncomming();
this.emitAndKeepAlive('ready');
} else {
this.emitAndKeepAlive('publicKeyRingUpdated');
} }
this.emitAndKeepAlive('publicKeyRingUpdated');
} }
}; };
@ -892,7 +894,7 @@ Wallet.prototype._setupBlockchainHandlers = function() {
self.blockchain.on('tx', function(tx) { self.blockchain.on('tx', function(tx) {
log.debug('Wallet:' + self.id + ' blockchain tx event'); log.debug('Wallet:' + self.id + ' blockchain tx event');
var addresses = self.getAddresses(); var addresses = self.getAddresses();
if (_.indexOf(addresses,tx.address)>=0) { if (_.indexOf(addresses, tx.address) >= 0) {
self.emitAndKeepAlive('tx', tx.address, self.addressIsChange(tx.address)); self.emitAndKeepAlive('tx', tx.address, self.addressIsChange(tx.address));
} }
}); });
@ -933,7 +935,7 @@ Wallet.prototype.netStart = function() {
self._setupBlockchainHandlers(); self._setupBlockchainHandlers();
self.netStarted= true; self.netStarted = true;
if (!this.isShared()) { if (!this.isShared()) {
self.emitAndKeepAlive('ready'); self.emitAndKeepAlive('ready');
@ -957,7 +959,7 @@ Wallet.prototype.netStart = function() {
} }
log.debug('Wallet:' + self.id + ' Starting network.'); log.debug('Wallet:' + self.id + ' Starting network.');
this.network.start(startOpts, function() { this.network.start(startOpts, function() {
self.emitAndKeepAlive('ready'); self.emitAndKeepAlive(self.isComplete() ? 'ready' : 'waitingCopayers');
}); });
}; };
@ -1400,7 +1402,8 @@ Wallet.prototype.getPendingTxProposalsCount = function() {
var txps = this.txProposals.txps; var txps = this.txProposals.txps;
var maxRejectCount = this.maxRejectCount(); var maxRejectCount = this.maxRejectCount();
var myId = this.getMyCopayerId(); var myId = this.getMyCopayerId();
var pending =0, pendingForUs = 0; var pending = 0,
pendingForUs = 0;
_.each(txps, function(inTxp, ntxid) { _.each(txps, function(inTxp, ntxid) {
if (!inTxp.isPending(maxRejectCount)) if (!inTxp.isPending(maxRejectCount))
@ -1408,7 +1411,7 @@ Wallet.prototype.getPendingTxProposalsCount = function() {
pending++; pending++;
if (!inTxp.signedBy[myId] && !inTxp.rejectedBy[myId] ) if (!inTxp.signedBy[myId] && !inTxp.rejectedBy[myId])
pendingForUs++ pendingForUs++
}); });
@ -1846,9 +1849,8 @@ Wallet.prototype._getPayProRefundOutputs = function(txp) {
var opts = JSON.parse(txp.builder.vanilla.opts); var opts = JSON.parse(txp.builder.vanilla.opts);
if (!opts.remainderOut) { if (!opts.remainderOut) {
log.warn('no remainder set. Not setting refund in PayPro'); log.warn('no remainder set. Not setting refund in PayPro');
return; return;
} }
console.log('[Wallet.js.1842:builder:]',txp.builder.vanilla.opts); //TODO
var addrStr = opts.remainderOut.address; var addrStr = opts.remainderOut.address;
var addr = new bitcore.Address(addrStr); var addr = new bitcore.Address(addrStr);
var script = bitcore.Script.createP2SH(addr.payload()).getBuffer(); var script = bitcore.Script.createP2SH(addr.payload()).getBuffer();
@ -2033,7 +2035,7 @@ Wallet.prototype.addressIsOwn = function(addrStr) {
/** /**
* @desc Returns true if a given address is a change address (remainder) * @desc Returns true if a given address is a change address (remainder)
* @param addrStr * @param addrStr
* @return {boolean} * @return {boolean}
*/ */
Wallet.prototype.addressIsChange = function(addrStr) { Wallet.prototype.addressIsChange = function(addrStr) {
return this.publicKeyRing.addressIsChange(addrStr); return this.publicKeyRing.addressIsChange(addrStr);
@ -2130,7 +2132,7 @@ Wallet.prototype.getUnspent = function(cb) {
var addresses = this.getAddresses(); var addresses = this.getAddresses();
log.debug('Wallet ' + this.getName() + ': Getting unspents from ' + addresses.length + ' addresses'); log.debug('Wallet ' + this.getName() + ': Getting unspents from ' + addresses.length + ' addresses');
this.blockchain.getUnspent(addresses, function(err, unspentList) { this.blockchain.getUnspent(addresses, function(err, unspentList) {
if (err) { if (err) {

View file

@ -164,6 +164,11 @@ angular.module('copayApp.services')
notification.error('Error', $filter('translate')('Received corrupt message from ') + peerId); notification.error('Error', $filter('translate')('Received corrupt message from ') + peerId);
} }
}); });
w.on('publicKeyRingUpdated', function() {
$rootScope.$digest();
});
w.on('ready', function() { w.on('ready', function() {
var isFocused = root.isFocused(wid); var isFocused = root.isFocused(wid);
copay.logger.debug('Wallet:' + w.getName() + ' is ready. Focused:', isFocused); copay.logger.debug('Wallet:' + w.getName() + ' is ready. Focused:', isFocused);