added the import method

This commit is contained in:
Mario Colque 2014-04-25 19:12:13 -03:00
commit 69e1bb8e37
2 changed files with 38 additions and 11 deletions

View file

@ -1,6 +1,22 @@
'use strict'; 'use strict';
angular.module('copay.import').controller('ImportController', angular.module('copay.import').controller('ImportController',
function($scope, $rootScope) { function($scope, $rootScope, walletFactory, controllerUtils) {
$scope.title = 'Import a backup'; $scope.title = 'Import a backup';
$scope.getFile = function() {
var reader = new FileReader();
// 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);
controllerUtils.startNetwork($rootScope.wallet);
}
};
reader.readAsBinaryString($scope.file);
};
}); });

View file

@ -51,16 +51,11 @@ WalletFactory.prototype._checkRead = function(walletId) {
return ret?true:false; return ret?true:false;
}; };
WalletFactory.prototype.read = function(walletId) { WalletFactory.prototype.fromObj = function(obj) {
if (! this._checkRead(walletId)) var opts = obj.opts;
return false; opts.publicKeyRing = new PublicKeyRing.fromObj(obj.publicKeyRing);
opts.txProposals = new TxProposals.fromObj(obj.txProposals);
var s = this.storage; opts.privateKey = new PrivateKey.fromObj(obj.privateKey);
var opts = s.get(walletId, 'opts');
opts.id = walletId;
opts.publicKeyRing = new PublicKeyRing.fromObj(s.get(walletId, 'publicKeyRing'));
opts.txProposals = new TxProposals.fromObj(s.get(walletId, 'txProposals'));
opts.privateKey = new PrivateKey.fromObj(s.get(walletId, 'privateKey'));
opts.storage = this.storage; opts.storage = this.storage;
opts.network = this.network; opts.network = this.network;
opts.blockchain = this.blockchain; opts.blockchain = this.blockchain;
@ -76,6 +71,22 @@ WalletFactory.prototype.read = function(walletId) {
// No really an error, just to be sure. // No really an error, just to be sure.
} }
this.log('### WALLET OPENED:', w.id); this.log('### WALLET OPENED:', w.id);
return w;
};
WalletFactory.prototype.read = function(walletId) {
if (! this._checkRead(walletId))
return false;
var s = this.storage;
var opts = s.get(walletId, 'opts');
opts.id = walletId;
opts.publicKeyRing = s.get(walletId, 'publicKeyRing');
opts.txProposals = s.get(walletId, 'txProposals');
opts.privateKey = s.get(walletId, 'privateKey');
w = this.formObj(opts);
return w; return w;
}; };