diff --git a/js/controllers/import.js b/js/controllers/import.js index 639f6a4a1..2157b4f00 100644 --- a/js/controllers/import.js +++ b/js/controllers/import.js @@ -6,21 +6,16 @@ angular.module('copayApp.controllers').controller('ImportController', var reader = new FileReader(); var _importBackup = function(encryptedObj) { Passphrase.getBase64Async($scope.password, function(passphrase){ - var w, errMsg; - try { - w = walletFactory.fromEncryptedObj(encryptedObj, passphrase); - } catch(e) { - errMsg = e.message; - } - if (!w) { - $scope.loading = false; - $rootScope.$flashMessage = { message: errMsg || 'Wrong password', type: 'error'}; - $rootScope.$digest(); - return; - } - $rootScope.wallet = w; - - controllerUtils.startNetwork($rootScope.wallet, $scope); + walletFactory.import(encryptedObj, passphrase, function(err, w) { + if (err) { + $scope.loading = false; + $rootScope.$flashMessage = { message: err.errMsg || 'Wrong password', type: 'error'}; + $rootScope.$digest(); + return; + } + $rootScope.wallet = w; + controllerUtils.startNetwork($rootScope.wallet, $scope); + }); }); }; diff --git a/js/models/core/WalletFactory.js b/js/models/core/WalletFactory.js index b84233e4e..8576bb901 100644 --- a/js/models/core/WalletFactory.js +++ b/js/models/core/WalletFactory.js @@ -71,14 +71,19 @@ WalletFactory.prototype.fromEncryptedObj = function(base64, password) { var walletObj = this.storage.import(base64); if (!walletObj) return false; var w = this.fromObj(walletObj); - var self = this; - w.updateIndexes(function(err) { - if (err) throw err; - self.log('Indexes updated'); - }); return w; }; +WalletFactory.prototype.import = function(base64, password, cb) { + var self = this; + var w = self.fromEncryptedObj(base64, password); + w.updateIndexes(function(err) { + if (err) return cb(err); + self.log('Indexes updated'); + cb(null, w); + }); +} + WalletFactory.prototype.read = function(walletId) { if (!this._checkRead(walletId)) return false;