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
parent 8b9ad143bb
commit 0e1cdda52d
6 changed files with 38 additions and 58 deletions

View File

@ -180,8 +180,6 @@ a:hover {
.open input,
.join input,
.setup input,
.import input,
.import textarea,
.settings input {
border-radius: 2px;
background: #EDEDED;
@ -268,19 +266,6 @@ a:hover {
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 small {
color: #fff;

View File

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

View File

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

View File

@ -1,4 +1,4 @@
'use strict';
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 }}
</div>
<div class="row" ng-init="choosefile=0; pastetext=0" ng-show="!loading">
<div class="large-4 columns logo-setup">
<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="row" ng-show="!loading">
<div class="large-12 columns">
<div class="box-setup">
<h1 class="text-white line-sidebar-b">{{title|translate}}</h1>
<h1>{{title|translate}}</h1>
<form name="importForm" ng-submit="import(importForm)" novalidate>
<div ng-show="!is_iOS">
<legend for="backupFile" class="m10b">
@ -72,7 +67,6 @@
</button>
</div>
</form>
</div>
</div>
</div>
</div>