From 96cbf8ad7bb5ebd79823808d56f6b749e801d7e1 Mon Sep 17 00:00:00 2001 From: Yemel Jardi Date: Wed, 25 Jun 2014 15:49:02 -0300 Subject: [PATCH 1/3] Add feedback while importing wallet --- index.html | 2 +- js/controllers/import.js | 15 ++++++++++++++- js/models/core/Wallet.js | 1 + js/models/core/WalletFactory.js | 1 + test/test.Wallet.js | 2 +- 5 files changed, 18 insertions(+), 3 deletions(-) diff --git a/index.html b/index.html index e7825c84c..52739204e 100644 --- a/index.html +++ b/index.html @@ -276,7 +276,7 @@
- Importing wallet... + {{ importStatus }}

{{title}}

diff --git a/js/controllers/import.js b/js/controllers/import.js index c3401862b..4ba9d0d0d 100644 --- a/js/controllers/import.js +++ b/js/controllers/import.js @@ -3,10 +3,19 @@ angular.module('copayApp.controllers').controller('ImportController', function($scope, $rootScope, walletFactory, controllerUtils, Passphrase) { $scope.title = 'Import a backup'; + $scope.importStatus = 'Importing wallet - Reading backup...'; + var reader = new FileReader(); + + var updateStatus = function(status) { + $scope.importStatus = status; + $scope.$digest(); + } + var _importBackup = function(encryptedObj) { Passphrase.getBase64Async($scope.password, function(passphrase) { - walletFactory.import(encryptedObj, passphrase, function(err, w) { + updateStatus('Importing wallet - Setting things up...'); + var w = walletFactory.import(encryptedObj, passphrase, function(err, w) { if (err) { $scope.loading = false; $rootScope.$flashMessage = { @@ -19,6 +28,10 @@ angular.module('copayApp.controllers').controller('ImportController', $rootScope.wallet = w; controllerUtils.startNetwork($rootScope.wallet, $scope); }); + + w.on('updatingIndexes', function(){ + updateStatus('Importing wallet - We are almost there...'); + }); }); }; diff --git a/js/models/core/Wallet.js b/js/models/core/Wallet.js index 0bfa3dcf4..a87ab10d1 100644 --- a/js/models/core/Wallet.js +++ b/js/models/core/Wallet.js @@ -755,6 +755,7 @@ Wallet.prototype.updateIndexes = function(callback) { if (changeIndex != -1) self.publicKeyRing.indexes.changeIndex = changeIndex + 1; + self.emit('updatingIndexes'); start = self.publicKeyRing.indexes.receiveIndex; self.indexDiscovery(start, false, 20, function(err, receiveIndex) { if (err) return callback(err); diff --git a/js/models/core/WalletFactory.js b/js/models/core/WalletFactory.js index 03d59e2ea..35a574ebd 100644 --- a/js/models/core/WalletFactory.js +++ b/js/models/core/WalletFactory.js @@ -84,6 +84,7 @@ WalletFactory.prototype.import = function(base64, password, cb) { self.log('Indexes updated'); cb(null, w); }); + return w; } WalletFactory.prototype.read = function(walletId) { diff --git a/test/test.Wallet.js b/test/test.Wallet.js index 14a7ee490..17f8b3901 100644 --- a/test/test.Wallet.js +++ b/test/test.Wallet.js @@ -743,7 +743,7 @@ describe('Wallet model', function() { var spyEmit = sinon.spy(w, 'emit'); w.updateIndexes(function(err) { sinon.assert.callCount(spyStore, 1); - sinon.assert.callCount(spyEmit, 1); + sinon.assert.callCount(spyEmit, 2); done(); }); }); From db59a1bd36ecea97dd8a5d50bdb482f173741fe9 Mon Sep 17 00:00:00 2001 From: Yemel Jardi Date: Wed, 25 Jun 2014 16:17:34 -0300 Subject: [PATCH 2/3] reduce the chance of a test failure --- test/test.Wallet.js | 1 - 1 file changed, 1 deletion(-) diff --git a/test/test.Wallet.js b/test/test.Wallet.js index 17f8b3901..ff8631ebe 100644 --- a/test/test.Wallet.js +++ b/test/test.Wallet.js @@ -331,7 +331,6 @@ describe('Wallet model', function() { var w = cachedCreateW2(); var spy = sinon.spy(w, 'scheduleConnect'); var callCount = 3; - w.reconnectDelay = 25; w.netStart(); setTimeout(function() { sinon.assert.callCount(spy, callCount); From a5a30c3ba56038b1c1479f75e4c305431dc0930d Mon Sep 17 00:00:00 2001 From: Yemel Jardi Date: Thu, 26 Jun 2014 10:08:40 -0300 Subject: [PATCH 3/3] Add wallet factory tests --- test/test.WalletFactory.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/test/test.WalletFactory.js b/test/test.WalletFactory.js index c9f8bde5c..7becea6ed 100644 --- a/test/test.WalletFactory.js +++ b/test/test.WalletFactory.js @@ -94,6 +94,29 @@ describe('WalletFactory model', function() { JSON.stringify(w.toObj()).should.equal(o); }); + it('should create wallet from encrypted object', function() { + var wf = new WalletFactory(config, '0.0.1'); + wf.storage._setPassphrase = sinon.spy(); + wf.storage.import = sinon.spy(); + + var w = wf.fromEncryptedObj("encrypted object", "password"); + should.exist(w); + wf.storage._setPassphrase.called.should.be.true; + wf.storage.import.called.should.be.true; + }); + + it('should import and update indexes', function() { + var wf = new WalletFactory(config, '0.0.1'); + var wallet = {id: "fake wallet", updateIndexes: function(cb) { cb(); }}; + wf.fromEncryptedObj = sinon.stub().returns(wallet); + var callback = sinon.spy(); + + var w = wf.import("encrypted", "password", callback); + + should.exist(w); + wallet.should.equal(w); + sinon.assert.callCount(callback, 1); + }); it('BIP32 length problem', function() { var sconfig = {