diff --git a/index.html b/index.html index 2f0ca75c5..b9f10e7ce 100644 --- a/index.html +++ b/index.html @@ -64,7 +64,7 @@ One key is - missing. Share this secret with your other copayers for them to join your wallet: {{$root.wallet.network.peerId}} + missing. Share this secret with your other copayers for them to join your wallet: {{$root.wallet.getMyPeerId()}} diff --git a/js/controllers/signin.js b/js/controllers/signin.js index 2a210b42a..ac079ca29 100644 --- a/js/controllers/signin.js +++ b/js/controllers/signin.js @@ -1,6 +1,3 @@ -'use strict'; - - angular.module('copay.signin').controller('SigninController', function($scope, $rootScope, $location, walletFactory, controllerUtils) { @@ -20,22 +17,29 @@ angular.module('copay.signin').controller('SigninController', $scope.open = function(walletId, opts) { $scope.loading = true; +console.log('[signin.js.23:walletId:]',walletId); //TODO var w = walletFactory.open(walletId, opts); controllerUtils.setupUxHandlers(w); + w.netStart(); }; - $scope.join = function(cid) { + $scope.join = function(secret) { $scope.loading = true; - walletFactory.network.on('openError', function() { - controllerUtils.onError($scope); - $rootScope.$digest(); + + + walletFactory.network.on('joinError', function() { + controllerUtils.onErrorDigest($scope); }); - walletFactory.connectTo(cid, function(data) { - $scope.open(data.walletId, data.opts); + + walletFactory.joinCreateSession(secret, function(w) { +console.log('[signin.js.33] joinCreateSession RETURN', w); //TODO + controllerUtils.setupUxHandlers(w); + w.setupNetHandlers(); }); }; + // // if (cid) { // var w = walletFactory.(walletId); diff --git a/js/models/core/PublicKeyRing.js b/js/models/core/PublicKeyRing.js index 122fb7da5..32cd4d5c9 100644 --- a/js/models/core/PublicKeyRing.js +++ b/js/models/core/PublicKeyRing.js @@ -83,8 +83,11 @@ PublicKeyRing.prototype.getCopayerId = function(i, prefix) { buf = Buffer.concat([prefix, buf]); } return util.ripe160(buf).toString('hex'); -} +}; +PublicKeyRing.prototype.myCopayerId = function(i, prefix) { + return this.getCopayerId(0,prefix); +}; PublicKeyRing.prototype.registeredCopayers = function () { return this.copayersBIP32.length; diff --git a/js/models/core/Wallet.js b/js/models/core/Wallet.js index 9d17ed5ec..8a5d2193b 100644 --- a/js/models/core/Wallet.js +++ b/js/models/core/Wallet.js @@ -97,6 +97,7 @@ Wallet.prototype._handleTxProposals = function(senderId, data, isInbound) { }; Wallet.prototype._handleData = function(senderId, data, isInbound) { +console.log('_handleData: senderId:',senderId); //TODO if (this.id !== data.walletId) { this.emit('badMessage',senderId); @@ -136,19 +137,27 @@ Wallet.prototype._optsToObj = function () { }; -Wallet.prototype.generatePeerId = function(index) { - var idBuf = new Buffer(this.id); - if (typeof index === 'undefined') { - // return my own peerId - var gen = this.privateKey.getId(idBuf); - return gen; - } +Wallet.prototype.getPeerId = function(index) { + // if (typeof index === 'undefined') { + // // return my own peerId + // var gen = this.privateKey.getId(idBuf); + // return gen; + // } // return peer number 'index' peerId - return this.publicKeyRing.getCopayerId(index, idBuf); + // + var idBuf; +// TODO idBuf DISABLED FOR NOW +//idBuf = new Buffer(this.id); + return this.publicKeyRing.getCopayerId(index || 0, idBuf); +}; + +Wallet.prototype.getMyPeerId = function() { + return this.getPeerId(0); }; Wallet.prototype.netStart = function() { +console.log('[Wallet.js.159:netStart:]'); //TODO var self = this; var net = this.network; net.removeAllListeners(); @@ -162,15 +171,17 @@ Wallet.prototype.netStart = function() { net.on('close', function() { self.emit('close'); }); + + var myPeerId = self.getMyPeerId(); var startOpts = { - peerId: self.generatePeerId() - } - net.start(function(peerId) { + peerId: myPeerId + }; + net.start(function() { +console.log('[Wallet.js.177] NET START: emit CREATED'); //TODO self.emit('created'); - var myId = self.generatePeerId(); for (var i=0; i