new backup/import encrypted methods

This commit is contained in:
Mario Colque 2014-05-01 18:33:36 -03:00
parent c995f039c2
commit 76df93ab10
3 changed files with 14 additions and 7 deletions

View File

@ -187,7 +187,9 @@
<div ng-controller="ImportController">
<h3>{{title}}</h3>
<div class="large-6 columns">
<input type="file" class="form-control" placeholder="Select a backup file" ng-model="backupFile" autofocus="" ng-file-select>
<input type="password" class="form-control" placeholder="Your wallet password" ng-model="password" autofocus>
<input type="file" class="form-control" placeholder="Select a backup file" ng-model="backupFile" ng-file-select>
<button class="button primary expand radius" ng-click="import()">Import backup</button>
</div>
</div>
</script>

View File

@ -8,7 +8,7 @@ angular.module('copay.backup').controller('BackupController',
// TODO: get the real encrypted wallet.
var _getEncryptedWallet = function() {
var wallet = JSON.stringify($rootScope.wallet.toObj());
var wallet = $rootScope.wallet.toEncryptedObj();
return wallet;
};

View File

@ -1,7 +1,7 @@
'use strict';
angular.module('copay.import').controller('ImportController',
function($scope, $rootScope, walletFactory, controllerUtils) {
function($scope, $rootScope, walletFactory, controllerUtils, Passphrase) {
$scope.title = 'Import a backup';
$scope.getFile = function() {
@ -10,13 +10,18 @@ angular.module('copay.import').controller('ImportController',
// If we use onloadend, we need to check the readyState.
reader.onloadend = function(evt) {
if (evt.target.readyState == FileReader.DONE) { // DONE == 2
var obj = JSON.parse(evt.target.result);
$rootScope.wallet = walletFactory.fromObj(obj);
var encryptedObj = evt.target.result;
var passphrase = Passphrase.getBase64($scope.password);
$rootScope.wallet = walletFactory.fromEncryptedObj(encryptedObj, passphrase);
controllerUtils.startNetwork($rootScope.wallet);
}
};
reader.readAsBinaryString($scope.file);
$scope.import = function() {
if ($scope.password != '') {
reader.readAsBinaryString($scope.file);
}
};
};
});