From 4ae374841480c1f7f08fa29d3057163b549d3778 Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Mon, 9 Jun 2014 21:00:28 -0300 Subject: [PATCH] checks network match when joining a wallet --- js/controllers/signin.js | 2 ++ js/models/core/PublicKeyRing.js | 2 +- js/models/core/Wallet.js | 13 +++++++++++-- js/models/core/WalletFactory.js | 6 ++++++ js/services/controllerUtils.js | 8 ++++++-- 5 files changed, 26 insertions(+), 5 deletions(-) diff --git a/js/controllers/signin.js b/js/controllers/signin.js index b2c9a9381..86468b1f1 100644 --- a/js/controllers/signin.js +++ b/js/controllers/signin.js @@ -57,6 +57,8 @@ angular.module('copayApp.controllers').controller('SigninController', $rootScope.$flashMessage = { message: 'Can not find peer'}; else if (err === 'walletFull') $rootScope.$flashMessage = { message: 'The wallet is full', type: 'error'}; + else if (err === 'badNetwork') + $rootScope.$flashMessage = { message: 'The wallet your are trying to join uses a different Bitcoin Network. Check your settings.', type: 'error'}; else if (err === 'badSecret') $rootScope.$flashMessage = { message: 'Bad secret secret string', type: 'error'}; else diff --git a/js/models/core/PublicKeyRing.js b/js/models/core/PublicKeyRing.js index f6f3909a0..f449158cc 100644 --- a/js/models/core/PublicKeyRing.js +++ b/js/models/core/PublicKeyRing.js @@ -248,7 +248,7 @@ PublicKeyRing.prototype._checkInPKR = function(inPKR, ignoreId) { } if (this.network.name !== inPKR.network.name) { - throw new Error('inPKR network mismatch. Should be '+this.network.name + + throw new Error('Network mismatch. Should be '+this.network.name + ' and found '+inPKR.network.name); } diff --git a/js/models/core/Wallet.js b/js/models/core/Wallet.js index 2d8c79a7b..e6d45201c 100644 --- a/js/models/core/Wallet.js +++ b/js/models/core/Wallet.js @@ -87,7 +87,15 @@ Wallet.prototype._handlePublicKeyRing = function(senderId, data, isInbound) { var inPKR = copay.PublicKeyRing.fromObj(data.publicKeyRing); var wasIncomplete = !this.publicKeyRing.isComplete(); - var hasChanged = this.publicKeyRing.merge(inPKR, true); + var hasChanged; + + try{ + hasChanged = this.publicKeyRing.merge(inPKR, true); + } catch (e){ + console.log('## WALLET ERROR', e); //TODO + this.emit('connectionError', e.message); + return; + } if (hasChanged) { if (wasIncomplete) { @@ -381,7 +389,8 @@ Wallet.prototype.sendWalletId = function(recipients) { this.network.send(recipients, { type: 'walletId', walletId: this.id, - opts: this._optsToObj() + opts: this._optsToObj(), + networkName: this.getNetworkName(), }); }; diff --git a/js/models/core/WalletFactory.js b/js/models/core/WalletFactory.js index 6547c2ff0..1aaa5f460 100644 --- a/js/models/core/WalletFactory.js +++ b/js/models/core/WalletFactory.js @@ -220,6 +220,12 @@ WalletFactory.prototype.joinCreateSession = function(secret, nickname, passphras }); self.network.on('data', function(sender, data) { if (data.type ==='walletId') { + +console.log('[WalletFactory.js.223]', data.networkName, self.networkName); //TODO + if (data.networkName !== self.networkName ){ + return cb('badNetwork'); + } + data.opts.privateKey = privateKey; data.opts.nickname = nickname; data.opts.passphrase = passphrase; diff --git a/js/services/controllerUtils.js b/js/services/controllerUtils.js index ff5018bbf..501adbd66 100644 --- a/js/services/controllerUtils.js +++ b/js/services/controllerUtils.js @@ -32,8 +32,12 @@ angular.module('copayApp.services') root.logout(); } - root.onErrorDigest = function(scope) { + root.onErrorDigest = function(scope, msg) { root.onError(scope); + if (msg) $rootScope.$flashMessage = { + type: 'error', + message: msg + }; $rootScope.$digest(); } @@ -81,7 +85,7 @@ angular.module('copayApp.services') }); }); w.on('connectionError', function(msg) { - root.onErrorDigest(msg); + root.onErrorDigest(null, msg); }); w.on('connect', function(peerID) { if (peerID && !config.disableVideo) {