Fixes: catch error message when importing wallet from different network

This commit is contained in:
Gustavo Cortez 2014-07-02 10:43:00 -03:00
commit f6709c4000
3 changed files with 26 additions and 18 deletions

View file

@ -15,20 +15,32 @@ angular.module('copayApp.controllers').controller('ImportController',
var _importBackup = function(encryptedObj) { var _importBackup = function(encryptedObj) {
Passphrase.getBase64Async($scope.password, function(passphrase) { Passphrase.getBase64Async($scope.password, function(passphrase) {
updateStatus('Importing wallet - Setting things up...'); updateStatus('Importing wallet - Setting things up...');
var w = walletFactory.import(encryptedObj, passphrase, function(err, w) { var w, errMsg;
try {
w = walletFactory.import(encryptedObj, passphrase);
} catch (e) {
errMsg = e.message;
}
if (!w) {
$scope.loading = false;
notification.error('Error', errMsg || 'Wrong password');
$rootScope.$digest();
return;
}
w.updateIndexes(function(err) {
updateStatus('Importing wallet - We are almost there...');
if (err) { if (err) {
$scope.loading = false; $scope.loading = false;
notification.error('Error', err.errMsg || 'Wrong password'); notification.error('Error', 'Error updating indexes: ' + err);
$rootScope.$digest();
return;
} }
$rootScope.wallet = w; $rootScope.wallet = w;
controllerUtils.startNetwork($rootScope.wallet, $scope); controllerUtils.startNetwork($rootScope.wallet, $scope);
}); });
w.on('updatingIndexes', function(){
updateStatus('Importing wallet - We are almost there...');
});
}); });
}; };
@ -54,6 +66,8 @@ angular.module('copayApp.controllers').controller('ImportController',
}; };
$scope.import = function(form) { $scope.import = function(form) {
$scope.loading = true;
if (form.$invalid) { if (form.$invalid) {
$scope.loading = false; $scope.loading = false;
notification.error('Error', 'There is an error in the form.'); notification.error('Error', 'There is an error in the form.');
@ -71,8 +85,6 @@ angular.module('copayApp.controllers').controller('ImportController',
return; return;
} }
$scope.loading = true;
if (backupFile) { if (backupFile) {
reader.readAsBinaryString(backupFile); reader.readAsBinaryString(backupFile);
} else { } else {

View file

@ -755,18 +755,19 @@ Wallet.prototype.createTxSync = function(toAddress, amountSatStr, comment, utxos
Wallet.prototype.updateIndexes = function(callback) { Wallet.prototype.updateIndexes = function(callback) {
var self = this; var self = this;
var start = self.publicKeyRing.indexes.changeIndex; var start = self.publicKeyRing.indexes.changeIndex;
self.log('Updating indexes...');
self.indexDiscovery(start, true, 20, function(err, changeIndex) { self.indexDiscovery(start, true, 20, function(err, changeIndex) {
if (err) return callback(err); if (err) return callback(err);
if (changeIndex != -1) if (changeIndex != -1)
self.publicKeyRing.indexes.changeIndex = changeIndex + 1; self.publicKeyRing.indexes.changeIndex = changeIndex + 1;
self.emit('updatingIndexes');
start = self.publicKeyRing.indexes.receiveIndex; start = self.publicKeyRing.indexes.receiveIndex;
self.indexDiscovery(start, false, 20, function(err, receiveIndex) { self.indexDiscovery(start, false, 20, function(err, receiveIndex) {
if (err) return callback(err); if (err) return callback(err);
if (receiveIndex != -1) if (receiveIndex != -1)
self.publicKeyRing.indexes.receiveIndex = receiveIndex + 1; self.publicKeyRing.indexes.receiveIndex = receiveIndex + 1;
self.log('Indexes updated');
self.emit('publicKeyRingUpdated'); self.emit('publicKeyRingUpdated');
self.store(); self.store();
callback(); callback();

View file

@ -74,16 +74,11 @@ WalletFactory.prototype.fromEncryptedObj = function(base64, password) {
return w; return w;
}; };
WalletFactory.prototype.import = function(base64, password, cb) { WalletFactory.prototype.import = function(base64, password) {
var self = this; var self = this;
var w = self.fromEncryptedObj(base64, password); var w = self.fromEncryptedObj(base64, password);
if (!w) return cb(new Error('wrong password')); if (!w) throw new Error('Wrong password');
w.updateIndexes(function(err) {
if (err) return cb(err);
self.log('Indexes updated');
cb(null, w);
});
return w; return w;
} }