intermediate screen backup

This commit is contained in:
Manuel Araoz 2014-06-25 17:14:12 -03:00
commit 1639b796cf
6 changed files with 58 additions and 20 deletions

View file

@ -1,7 +1,7 @@
'use strict';
angular.module('copayApp.controllers').controller('HeaderController',
function($scope, $rootScope, $location, notification, $http, controllerUtils) {
function($scope, $rootScope, $location, notification, $http, controllerUtils, backupService) {
$scope.menu = [{
'title': 'Addresses',
'icon': 'fi-address-book',
@ -135,4 +135,11 @@ angular.module('copayApp.controllers').controller('HeaderController',
$scope.$on('$destroy', function() {
window.onbeforeunload = undefined;
});
$scope.backupAndOpen = function() {
var w = $rootScope.wallet;
backupService.download(w);
w.offerBackup();
};
});

View file

@ -33,7 +33,7 @@ var valid_pairs = {
};
angular.module('copayApp.controllers').controller('SetupController',
function($scope, $rootScope, $location, $timeout, walletFactory, controllerUtils, Passphrase, backupService) {
function($scope, $rootScope, $location, $timeout, walletFactory, controllerUtils, Passphrase) {
$rootScope.videoInfo = {};
$scope.loading = false;
@ -84,7 +84,6 @@ angular.module('copayApp.controllers').controller('SetupController',
passphrase: passphrase,
};
var w = walletFactory.create(opts);
backupService.download(w);
controllerUtils.startNetwork(w, $scope);
});
};

View file

@ -1,7 +1,7 @@
'use strict';
angular.module('copayApp.controllers').controller('SigninController',
function($scope, $rootScope, $location, walletFactory, controllerUtils, Passphrase, backupService) {
function($scope, $rootScope, $location, walletFactory, controllerUtils, Passphrase) {
var cmp = function(o1, o2) {
var v1 = o1.show.toLowerCase(),
v2 = o2.show.toLowerCase();
@ -89,7 +89,6 @@ angular.module('copayApp.controllers').controller('SigninController',
};
controllerUtils.onErrorDigest();
} else {
backupService.download(w);
controllerUtils.startNetwork(w, $scope);
}
});

View file

@ -50,6 +50,7 @@ function Wallet(opts) {
this.network.maxPeers = this.totalCopayers;
this.registeredPeerIds = [];
this.addressBook = opts.addressBook || {};
this.backupOffered = opts.backupOffered || false;
}
Wallet.parent = EventEmitter;
@ -355,7 +356,8 @@ Wallet.prototype.toObj = function() {
publicKeyRing: this.publicKeyRing.toObj(),
txProposals: this.txProposals.toObj(),
privateKey: this.privateKey ? this.privateKey.toObj() : undefined,
addressBook: this.addressBook
addressBook: this.addressBook,
backupOffered: this.backupOffered,
};
return walletObj;
@ -364,6 +366,8 @@ Wallet.prototype.toObj = function() {
Wallet.fromObj = function(o, storage, network, blockchain) {
var opts = JSON.parse(JSON.stringify(o.opts));
opts.addressBook = o.addressBook;
opts.backupOffered = o.backupOffered;
opts.publicKeyRing = PublicKeyRing.fromObj(o.publicKeyRing);
opts.txProposals = TxProposals.fromObj(o.txProposals);
opts.privateKey = PrivateKey.fromObj(o.privateKey);
@ -850,4 +854,14 @@ Wallet.prototype.deleteAddressBook = function(key) {
}
};
Wallet.prototype.isReady = function() {
var ret = this.publicKeyRing.isComplete() && this.backupOffered;
return ret;
};
Wallet.prototype.offerBackup = function() {
this.backupOffered = true;
this.store();
};
module.exports = require('soop')(Wallet);

View file

@ -99,6 +99,7 @@ WalletFactory.prototype.read = function(walletId) {
obj.txProposals = s.get(walletId, 'txProposals');
obj.privateKey = s.get(walletId, 'privateKey');
obj.addressBook = s.get(walletId, 'addressBook');
obj.backupOffered = s.get(walletId, 'backupOffered');
var w = this.fromObj(obj);
return w;