Hold on backup page until all copayers made a full backup

This commit is contained in:
Yemel Jardi 2014-07-07 18:35:44 -03:00
commit 49ac6dfcf4
4 changed files with 48 additions and 11 deletions

View file

@ -140,10 +140,11 @@
<div class="large-12 columns">
<div class="line-dashed"></div>
<button class="button primary radius right"
ng-click="backupAndOpen()"
ng-click="backup()"
ng-show="!$root.wallet.publicKeyRing.isBackupReady()"
ng-disabled="!$root.wallet.publicKeyRing.isComplete()">
<span ng-show="$root.wallet.publicKeyRing.isComplete()" >
Backup keys and continue
Backup keys
</span>
<span ng-show="!$root.wallet.publicKeyRing.isComplete()" >
<span ng-show="$root.wallet.publicKeyRing.totalCopayers - $root.wallet.publicKeyRing.registeredCopayers()>1">
@ -154,10 +155,12 @@
</span>
yet to join.
</span>
</button>
<!-- <a href="" class="db p10t left" ng-disabled="!$root.wallet.publicKeyRing.isComplete()">Skip Backup</a> -->
<button class="button primary radius right"
disabled="disabled"
ng-show="$root.wallet.publicKeyRing.isBackupReady()">
Waiting for copayers to backup
</button>
</div>
</div>
</div>

View file

@ -87,10 +87,10 @@ angular.module('copayApp.controllers').controller('HeaderController',
window.onbeforeunload = undefined;
});
$scope.backupAndOpen = function() {
$scope.backup = function() {
var w = $rootScope.wallet;
w.offerBackup();
backupService.download(w);
w.setBackupReady();
};
$scope.getVideoURL = function(copayer) {

View file

@ -30,6 +30,7 @@ function PublicKeyRing(opts) {
this.publicKeysCache = opts.publicKeysCache || {};
this.nicknameFor = opts.nicknameFor || {};
this.copayerIds = [];
this.copayersBackup = opts.copayersBackup || [];
this.addressToPath = {};
}
@ -59,6 +60,7 @@ PublicKeyRing.prototype.toObj = function() {
requiredCopayers: this.requiredCopayers,
totalCopayers: this.totalCopayers,
indexes: AddressIndex.serialize(this.indexes),
copayersBackup: this.copayersBackup,
copayersExtPubKeys: this.copayersHK.map(function(b) {
return b.extendedPublicKeyString();
@ -350,12 +352,30 @@ PublicKeyRing.prototype._mergePubkeys = function(inPKR) {
return hasChanged;
};
PublicKeyRing.prototype.setBackupReady = function(copayerId) {
if (this.isBackupReady()) return false;
var cid = this.myCopayerId();
this.copayersBackup.push(cid);
return true;
}
PublicKeyRing.prototype.isBackupReady = function(copayerId) {
var cid = this.myCopayerId();
return this.copayersBackup.indexOf(cid) != -1;
}
PublicKeyRing.prototype.isFullyBackup = function(copayerId) {
return this.copayersBackup.length == this.totalCopayers;
}
PublicKeyRing.prototype.merge = function(inPKR, ignoreId) {
this._checkInPKR(inPKR, ignoreId);
var hasChanged = false;
hasChanged |= this.mergeIndexes(inPKR.indexes);
hasChanged |= this._mergePubkeys(inPKR);
hasChanged |= this.mergeBackups(inPKR.copayersBackup);
return !!hasChanged;
};
@ -372,4 +392,18 @@ PublicKeyRing.prototype.mergeIndexes = function(indexes) {
return !!hasChanged
}
PublicKeyRing.prototype.mergeBackups = function(backups) {
var self = this;
var hasChanged = false;
backups.forEach(function(cid) {
var isNew = self.copayersBackup.indexOf(cid) == -1;
if (isNew) self.copayersBackup.push(cid);
hasChanged |= isNew;
});
return !!hasChanged
}
module.exports = require('soop')(PublicKeyRing);

View file

@ -879,13 +879,13 @@ Wallet.prototype.toggleAddressBookEntry = function(key) {
};
Wallet.prototype.isReady = function() {
var ret = this.publicKeyRing.isComplete() && this.backupOffered;
var ret = this.publicKeyRing.isComplete() && this.publicKeyRing.isFullyBackup();
return ret;
};
Wallet.prototype.offerBackup = function() {
this.backupOffered = true;
this.store();
Wallet.prototype.setBackupReady = function() {
this.publicKeyRing.setBackupReady();
this.emit('publicKeyRingUpdated', false);
};
Wallet.prototype.signJson = function(payload) {