fix import

This commit is contained in:
Matias Alejo Garcia 2015-08-24 17:09:59 -03:00
commit 1ab9d8507f
6 changed files with 205 additions and 37 deletions

View file

@ -1,7 +1,7 @@
'use strict';
angular.module('copayApp.controllers').controller('importController',
function($scope, $rootScope, $location, $timeout, $log, profileService, notification, go, isMobile, isCordova, sjcl, gettext) {
function($scope, $rootScope, $location, $timeout, $log, profileService, notification, go, isMobile, isCordova, sjcl, gettext, lodash) {
var self = this;
@ -11,15 +11,22 @@ angular.module('copayApp.controllers').controller('importController',
window.ignoreMobilePause = true;
$scope.$on('$destroy', function() {
$timeout(function(){
$timeout(function() {
window.ignoreMobilePause = false;
}, 100);
});
var _import = function(str, opts) {
this.setType = function(type) {
$scope.type = type;
$timeout(function() {
$rootScope.$apply();
});
};
var _importBlob = function(str, opts) {
var str2, err;
try {
str2 = sjcl.decrypt(self.password, str);
str2 = sjcl.decrypt(self.password, str);
} catch (e) {
err = gettext('Could not decrypt file, check your password');
$log.warn(e);
@ -27,7 +34,9 @@ angular.module('copayApp.controllers').controller('importController',
if (err) {
self.error = err;
$rootScope.$apply();
$timeout(function() {
$rootScope.$apply();
});
return;
}
@ -41,8 +50,7 @@ angular.module('copayApp.controllers').controller('importController',
self.loading = false;
if (err) {
self.error = err;
}
else {
} else {
$rootScope.$emit('Local/WalletImported', walletId);
go.walletHome();
notification.success(gettext('Success'), gettext('Your wallet has been imported correctly'));
@ -51,19 +59,54 @@ angular.module('copayApp.controllers').controller('importController',
}, 100);
};
var _importMnemonic = function(words, passphrase, opts) {
self.loading = true;
console.log('[import.js.64:opts:]', opts); //TODO
$timeout(function() {
profileService.importWalletMnemonic(words, {
passphrase: passphrase,
}, function(err, ret) {
console.log('[import.js.70:err:]',err, ret); //TODO
self.loading = false;
if (err) {
self.error = err;
return $timeout(function() {
$scope.$apply();
});
}
return
$rootScope.$emit('Local/WalletImported', walletId);
notification.success(gettext('Success'), gettext('Your wallet has been imported correctly'));
go.walletHome();
});
}, 100);
};
// {
// network: opts.network,
// m: opts.m,
// n: opts.n,
// publicKeyRing: opts.publicKeyRing,
// },
//
$scope.getFile = function() {
// If we use onloadend, we need to check the readyState.
reader.onloadend = function(evt) {
if (evt.target.readyState == FileReader.DONE) { // DONE == 2
_import(evt.target.result);
_importBlob(evt.target.result);
}
}
};
this.import = function(form) {
this.importBlob = function(form) {
if (form.$invalid) {
this.error = gettext('There is an error in the form');
$scope.$apply();
$timeout(function() {
$scope.$apply();
});
return;
}
@ -73,14 +116,48 @@ angular.module('copayApp.controllers').controller('importController',
if (!backupFile && !backupText) {
this.error = gettext('Please, select your backup file');
$scope.$apply();
$timeout(function() {
$scope.$apply();
});
return;
}
if (backupFile) {
reader.readAsBinaryString(backupFile);
} else {
_import(backupText);
_importBlob(backupText);
}
};
this.importMnemonic = function(form) {
if (form.$invalid) {
this.error = gettext('There is an error in the form');
$timeout(function() {
$scope.$apply();
});
return;
}
var opts = {};
var passphrase = form.passphrase.$modelValue;
var words = form.words.$modelValue;
if (!words || words.split(' ').map(function(v) {
return lodash.trim(v);
}).length != 12) {
this.error = gettext('Please input 12 backup words');
$timeout(function() {
$scope.$apply();
});
return;
}
opts.passphrase = form.passphrase.$modelValue || null;
_importMnemonic(words, passphrase, opts);
};
});

View file

@ -1164,7 +1164,7 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
this.sendAll = function(amount, feeStr, feeRate) {
var self = this;
var msg = gettextCatalog.getString("{{fee}} will be discounted for bitcoin networking fees", {
var msg = gettextCatalog.getString("{{fee}} will be deducted for bitcoin networking fees", {
fee: feeStr
});