diff --git a/index.html b/index.html
index b6ec101e8..0381a52b0 100644
--- a/index.html
+++ b/index.html
@@ -291,7 +291,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 7fb0802d5..3ad5f5cd4 100644
--- a/js/models/core/Wallet.js
+++ b/js/models/core/Wallet.js
@@ -759,6 +759,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 e0a12ae6e..c1ffbfeb4 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 7e7e06bda..70b5baa41 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);
@@ -743,7 +742,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();
});
});
diff --git a/test/test.WalletFactory.js b/test/test.WalletFactory.js
index 860db9bd9..1201d6824 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 = {