From b391344dafa3773dfc78874358d0f9ce34724f18 Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Tue, 14 Oct 2014 19:49:29 -0300 Subject: [PATCH] fix join flow --- js/controllers/copayers.js | 2 +- js/models/Async.js | 3 +++ js/models/Identity.js | 6 ++++-- js/models/Wallet.js | 33 ++++++++++++++++++--------------- 4 files changed, 26 insertions(+), 18 deletions(-) diff --git a/js/controllers/copayers.js b/js/controllers/copayers.js index 8896e7566..5ee6add64 100644 --- a/js/controllers/copayers.js +++ b/js/controllers/copayers.js @@ -1,7 +1,7 @@ 'use strict'; angular.module('copayApp.controllers').controller('CopayersController', - function($scope, $rootScope, $location, backupService, identity, controllerUtils) { + function($scope, $rootScope, $location, backupService, controllerUtils) { $scope.isSafari = Object.prototype.toString.call(window.HTMLElement).indexOf('Constructor') > 0; $scope.hideAdv = true; diff --git a/js/models/Async.js b/js/models/Async.js index 60f089030..5d5b5484d 100644 --- a/js/models/Async.js +++ b/js/models/Async.js @@ -294,11 +294,13 @@ Network.prototype.greet = function(copayerId, secretNumber) { }; Network.prototype._addCopayerMap = function(peerId, copayerId) { +console.log('[Async.js.296:_addCopayerMap:]',peerId, copayerId); //TODO if (!this.copayerForPeer[peerId]) { if (Object.keys(this.copayerForPeer).length < this.maxPeers) { this.copayerForPeer[peerId] = copayerId; } } +console.log('[Async.js.296:_addCopayerMap:]',this.copayerForPeer); //TODO }; Network.prototype._setInboundPeerAuth = function(peerId) { @@ -374,6 +376,7 @@ Network.prototype.send = function(dest, payload, cb) { dest = this.getCopayerIds(); payload.isBroadcast = 1; } +console.log('[Async.js.374:dest:]',dest); //TODO if (typeof dest === 'string') dest = [dest]; diff --git a/js/models/Identity.js b/js/models/Identity.js index f63661241..d2dcdd335 100644 --- a/js/models/Identity.js +++ b/js/models/Identity.js @@ -39,6 +39,7 @@ function Identity(email, password, opts) { this.walletDefaults = opts.walletDefaults || {}; this.version = opts.version || version; + this.email = email; // open wallets this.openWallets = []; @@ -376,7 +377,7 @@ Identity.prototype.createWallet = function(opts, cb) { }); opts.publicKeyRing.addCopayer( opts.privateKey.deriveBIP45Branch().extendedPublicKeyString(), - opts.nickname + opts.nickname || this.email ); log.debug('\t### PublicKeyRing Initialized'); @@ -605,9 +606,10 @@ Identity.prototype.joinWallet = function(opts, cb) { var walletOpts = _.clone(data.opts); walletOpts.id = data.walletId; + walletOpts.network = joinNetwork; walletOpts.privateKey = privateKey; - walletOpts.nickname = opts.nickname || self.profile.name; + walletOpts.nickname = opts.nickname || this.email; if (opts.password) walletOpts.password = opts.password; diff --git a/js/models/Wallet.js b/js/models/Wallet.js index 3489df273..0b0243ccf 100644 --- a/js/models/Wallet.js +++ b/js/models/Wallet.js @@ -380,6 +380,7 @@ Wallet.prototype._onPublicKeyRing = function(senderId, data) { var inPKR = PublicKeyRing.fromObj(data.publicKeyRing); var wasIncomplete = !this.publicKeyRing.isComplete(); +console.log('[Wallet.js.382:wasIncomplete:]',wasIncomplete); //TODO var hasChanged; try { @@ -389,7 +390,7 @@ Wallet.prototype._onPublicKeyRing = function(senderId, data) { this.emit('connectionError', e.message); return; } - +console.log('[Wallet.js.393:hasChanged:]',hasChanged); //TODO if (hasChanged) { if (wasIncomplete) { this.sendPublicKeyRing(); @@ -699,10 +700,7 @@ Wallet.prototype._onData = function(senderId, data, ts) { break; case 'walletReady': - console.log('[Wallet.js.653]', this.lastMessageFrom[senderId]); //TODO if (this.lastMessageFrom[senderId] !== 'walletReady') { - - console.log('[Wallet.js.656]'); //TODO log.debug('Wallet:' + this.id + ' peer Sync received. since: ' + (data.sinceTs || 0)); this.sendPublicKeyRing(senderId); this.sendAddressBook(senderId); @@ -927,16 +925,27 @@ Wallet.prototype.netStart = function() { var self = this; var net = this.network; + net.removeAllListeners(); + net.on('connect', self._onConnect.bind(self)); + net.on('data', self._onData.bind(self)); + net.on('no messages', self._onNoMessages.bind(self)); + net.on('connect_error', function() { + self.emit('connectionError'); + }); + + if (this.publicKeyRing.isComplete()) { + this._lockIncomming(); + } + + + if (net.started) { log.debug('Wallet:' + self.id + ' Wallet networking was ready') self.emit('ready', net.getPeer()); return; } - net.removeAllListeners(); - net.on('connect', self._onConnect.bind(self)); - net.on('data', self._onData.bind(self)); - net.on('no messages', self._onNoMessages.bind(self)); + var myId = self.getMyCopayerId(); var myIdPriv = self.getMyCopayerIdPriv(); @@ -949,13 +958,6 @@ Wallet.prototype.netStart = function() { secretNumber: self.secretNumber, }; - if (this.publicKeyRing.isComplete()) { - this._lockIncomming(); - } - - net.on('connect_error', function() { - self.emit('connectionError'); - }); log.debug('Wallet:' + self.id + ' Starting networking: ' + startOpts.copayerId); net.start(startOpts, function() { @@ -1303,6 +1305,7 @@ Wallet.prototype.sendIndexes = function(recipients) { * @param {string[]} recipients - the pubkeys of the recipients */ Wallet.prototype.sendAddressBook = function(recipients) { + if ( !Object.keys(this.addressBook).length ) return; log.debug('Wallet:' + this.id + ' ### SENDING addressBook TO:', recipients || 'All', this.addressBook); this.send(recipients, { type: 'addressbook',