From bd0ddf5c8cb47117fa79599fe698b6a3ce0a8ac7 Mon Sep 17 00:00:00 2001 From: Ivan Socolsky Date: Wed, 3 Dec 2014 19:20:51 -0300 Subject: [PATCH 1/2] returning error when allet already exists in profile --- js/controllers/join.js | 4 ++++ js/models/Identity.js | 5 +++++ js/models/Wallet.js | 5 ++++- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/js/controllers/join.js b/js/controllers/join.js index 1b7478712..15ddf50c7 100644 --- a/js/controllers/join.js +++ b/js/controllers/join.js @@ -125,11 +125,14 @@ angular.module('copayApp.controllers').controller('JoinController', privateHex: $scope.private, }, function(err) { $scope.loading = false; + console.log(err); if (err) { if (err === 'joinError') notification.error('Fatal error connecting to Insight server'); else if (err === 'walletFull') notification.error('The wallet is full'); + else if (err === 'walletAlreadyExists') + notification.error('Wallet already exists', 'Cannot join again from the same profile'); else if (err === 'badNetwork') notification.error('Network Error', 'Wallet network configuration missmatch'); else if (err === 'badSecret') @@ -138,6 +141,7 @@ angular.module('copayApp.controllers').controller('JoinController', notification.error('Error', err.message || err); } } + $timeout(function () { $scope.$digest(); }, 1); }); } }); diff --git a/js/models/Identity.js b/js/models/Identity.js index 3799e329f..9cd225953 100644 --- a/js/models/Identity.js +++ b/js/models/Identity.js @@ -575,6 +575,11 @@ Identity.prototype.createWallet = function(opts, cb) { var self = this; var w = new walletClass(opts); + + if (_.contains(_.keys(self.wallets), w.getId())) { + return cb('walletAlreadyExists'); + } + self.wallets[w.getId()] = w; self.updateFocusedTimestamp(w.getId()); self.bindWallet(w); diff --git a/js/models/Wallet.js b/js/models/Wallet.js index c9aa01342..44543c349 100644 --- a/js/models/Wallet.js +++ b/js/models/Wallet.js @@ -2550,7 +2550,10 @@ Wallet.prototype.isComplete = function() { * @param {string} version - the new version for the wallet */ Wallet.prototype.setVersion = function(version) { - this.version = this.opts.version = version; + this.version = version; + if (this.opts) { + this.opts.version = version; + } }; /** From ec2c45ac2ea841567ffa6e6ee87d60963bd7604f Mon Sep 17 00:00:00 2001 From: Ivan Socolsky Date: Thu, 4 Dec 2014 12:32:06 -0300 Subject: [PATCH 2/2] fixed test seed data --- js/controllers/join.js | 1 - js/models/Identity.js | 2 ++ test/Identity.js | 3 ++- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/js/controllers/join.js b/js/controllers/join.js index 15ddf50c7..7fac1b45a 100644 --- a/js/controllers/join.js +++ b/js/controllers/join.js @@ -125,7 +125,6 @@ angular.module('copayApp.controllers').controller('JoinController', privateHex: $scope.private, }, function(err) { $scope.loading = false; - console.log(err); if (err) { if (err === 'joinError') notification.error('Fatal error connecting to Insight server'); diff --git a/js/models/Identity.js b/js/models/Identity.js index 9cd225953..d08b53087 100644 --- a/js/models/Identity.js +++ b/js/models/Identity.js @@ -576,6 +576,8 @@ Identity.prototype.createWallet = function(opts, cb) { var self = this; var w = new walletClass(opts); + console.log(_.keys(self.wallets)); + console.log(w.getId()); if (_.contains(_.keys(self.wallets), w.getId())) { return cb('walletAlreadyExists'); } diff --git a/test/Identity.js b/test/Identity.js index caecc3f03..daaddb78e 100644 --- a/test/Identity.js +++ b/test/Identity.js @@ -77,9 +77,10 @@ describe('Identity model', function() { return params; } + var wid = 0; function getNewWallet(args) { var w = sinon.stub(); - w.getId = sinon.stub().returns('wid'); + w.getId = sinon.stub().returns('wid' + (++wid)); w.getStorageKey = sinon.stub().returns('wkey'); w.toObj = sinon.stub().returns({ obj: 1