import a wallet inside a profile

This commit is contained in:
Gustavo Maximiliano Cortez 2014-10-16 17:39:22 -03:00 committed by Matias Alejo Garcia
commit 0e1cdda52d
6 changed files with 38 additions and 58 deletions

View file

@ -180,8 +180,6 @@ a:hover {
.open input, .open input,
.join input, .join input,
.setup input, .setup input,
.import input,
.import textarea,
.settings input { .settings input {
border-radius: 2px; border-radius: 2px;
background: #EDEDED; background: #EDEDED;
@ -268,19 +266,6 @@ a:hover {
color: #fff; color: #fff;
} }
.import fieldset, .settings fieldset {
border: 1px solid #3C5269;
}
.import fieldset legend, .settings fieldset legend {
background: transparent;
color: #fff;
font-weight: normal;
}
.import input[type="file"],
.import label,
.import label small,
.settings label, .settings label,
.settings label small { .settings label small {
color: #fff; color: #fff;

View file

@ -1,8 +1,7 @@
'use strict'; 'use strict';
angular.module('copayApp.controllers').controller('ImportController', angular.module('copayApp.controllers').controller('ImportController',
function($scope, $rootScope, $location, identity, controllerUtils, Passphrase, notification, isMobile) { function($scope, $rootScope, $location, controllerUtils, Passphrase, notification, isMobile) {
controllerUtils.redirIfLogged();
$scope.title = 'Import a backup'; $scope.title = 'Import a backup';
$scope.importStatus = 'Importing wallet - Reading backup...'; $scope.importStatus = 'Importing wallet - Reading backup...';
@ -17,38 +16,30 @@ angular.module('copayApp.controllers').controller('ImportController',
} }
var _importBackup = function(encryptedObj) { var _importBackup = function(encryptedObj) {
Passphrase.getBase64Async($scope.password, function(passphrase) { var password = $scope.password;
updateStatus('Importing wallet - Setting things up...'); updateStatus('Importing wallet - Setting things up...');
var w, errMsg; var skipFields = [];
if ($scope.skipPublicKeyRing)
skipFields.push('publicKeyRing');
var skipFields = []; if ($scope.skipTxProposals)
if ($scope.skipPublicKeyRing) skipFields.push('txProposals');
skipFields.push('publicKeyRing');
if ($scope.skipTxProposals)
skipFields.push('txProposals');
// try to import encrypted wallet with passphrase
try {
w = identity.fromEncryptedObj(encryptedObj, passphrase, skipFields);
} catch (e) {
errMsg = e.message;
}
$rootScope.iden.importWallet(encryptedObj, password, skipFields, function(err, w) {
if (!w) { if (!w) {
$scope.loading = false; $scope.loading = false;
notification.error('Error', errMsg || 'Wrong password'); notification.error('Error', err || 'Wrong password');
$rootScope.$digest(); $rootScope.$digest();
return; return;
} }
// if wallet was never used, we're done // if wallet was never used, we're done
if (!w.isReady()) { if (!w.isReady()) {
$rootScope.wallet = w; controllerUtils.installWalletHandlers($scope, w);
controllerUtils.startNetwork($rootScope.wallet, $scope); controllerUtils.setFocusedWallet(w);
return; return;
} }
// if it was used, we need to scan for indices // if it was used, we need to scan for indices
w.updateIndexes(function(err) { w.updateIndexes(function(err) {
updateStatus('Importing wallet - We are almost there...'); updateStatus('Importing wallet - We are almost there...');
@ -56,11 +47,10 @@ angular.module('copayApp.controllers').controller('ImportController',
$scope.loading = false; $scope.loading = false;
notification.error('Error', 'Error updating indexes: ' + err); notification.error('Error', 'Error updating indexes: ' + err);
} }
$rootScope.wallet = w; controllerUtils.installWalletHandlers($scope, w);
controllerUtils.startNetwork($rootScope.wallet, $scope); controllerUtils.setFocusedWallet(w);
}); });
});
});
}; };
$scope.openFileDialog = function() { $scope.openFileDialog = function() {

View file

@ -60,8 +60,8 @@ Identity._newWallet = function(opts) {
return new Wallet(opts); return new Wallet(opts);
}; };
Identity._walletFromObj = function(o, s, n, b, skip) { Identity._walletFromObj = function(o, readOpts) {
return Wallet.fromObj(o, s, n, b, skip); return Wallet.fromObj(o, readOpts);
}; };
Identity._walletRead = function(id, r, cb) { Identity._walletRead = function(id, r, cb) {
@ -299,6 +299,7 @@ Identity.prototype.close = function(cb) {
* @return {Wallet} * @return {Wallet}
*/ */
Identity.prototype.importWallet = function(base64, password, skipFields, cb) { Identity.prototype.importWallet = function(base64, password, skipFields, cb) {
var self = this;
preconditions.checkArgument(password); preconditions.checkArgument(password);
preconditions.checkArgument(cb); preconditions.checkArgument(cb);
@ -307,13 +308,22 @@ Identity.prototype.importWallet = function(base64, password, skipFields, cb) {
var obj = this.storage.decrypt(base64); var obj = this.storage.decrypt(base64);
this.storage.restorePassphrase(); this.storage.restorePassphrase();
if (!obj) return false; var readOpts = {
var w = Identity._walletFromObj(obj, this.storage, this.networkOpts, this.blockchainOpts); storage: this.storage,
console.log('[Identity.js.307:Identity:]', w); //TODO networkOpts: this.networkOpts,
blockchainOpts: this.blockchainOpts,
skipFields: skipFields
};
if (!obj) return cb(null);
var w = Identity._walletFromObj(obj, readOpts);
this._checkVersion(w.version); this._checkVersion(w.version);
this.addWallet(w, function(err) { this.addWallet(w, function(err) {
if (err) return cb(err); if (err) return cb(err, null);
w.store(cb); self.openWallets.push(w);
self.store(null, function(err) {
return cb(err, w);
});
}); });
}; };

View file

@ -98,6 +98,7 @@ Storage.prototype._decrypt = function(base64) {
decryptedStr = decrypted.toString(CryptoJS.enc.Utf8); decryptedStr = decrypted.toString(CryptoJS.enc.Utf8);
} catch (e) { } catch (e) {
// Error while decrypting // Error while decrypting
log.debug(e.message);
return null; return null;
} }
return decryptedStr; return decryptedStr;

View file

@ -1,4 +1,4 @@
'use strict'; 'use strict';
angular.module('copayApp.services') angular.module('copayApp.services')
.value('Passphrase', new copay.Passphrase(config.passphrase)); .value('Passphrase', new copay.Passphrase(config.passphraseConfig));

View file

@ -4,15 +4,10 @@
{{ importStatus|translate }} {{ importStatus|translate }}
</div> </div>
<div class="row" ng-init="choosefile=0; pastetext=0" ng-show="!loading"> <div class="row" ng-show="!loading">
<div class="large-4 columns logo-setup"> <div class="large-12 columns">
<img src="img/logo-negative-beta.svg" alt="Copay" width="146" height="59">
<div ng-include="'views/includes/version.html'"></div>
</div>
<div class="large-8 columns line-dashed-setup-v">
<div class="box-setup"> <h1>{{title|translate}}</h1>
<h1 class="text-white line-sidebar-b">{{title|translate}}</h1>
<form name="importForm" ng-submit="import(importForm)" novalidate> <form name="importForm" ng-submit="import(importForm)" novalidate>
<div ng-show="!is_iOS"> <div ng-show="!is_iOS">
<legend for="backupFile" class="m10b"> <legend for="backupFile" class="m10b">
@ -72,7 +67,6 @@
</button> </button>
</div> </div>
</form> </form>
</div>
</div> </div>
</div> </div>
</div> </div>