From d5b04d7ad84b28ac03c93c4168e9648f3e2cfcf9 Mon Sep 17 00:00:00 2001 From: Ivan Socolsky Date: Tue, 28 Oct 2014 15:18:25 -0300 Subject: [PATCH] removed backup step in wallet creation --- js/controllers/copayers.js | 39 +------------------ js/models/PublicKeyRing.js | 66 +------------------------------- js/models/Wallet.js | 27 +------------ test/PublicKeyRing.js | 52 ------------------------- views/copayers.html | 78 +------------------------------------- 5 files changed, 6 insertions(+), 256 deletions(-) diff --git a/js/controllers/copayers.js b/js/controllers/copayers.js index 2dc5398be..fecc482c9 100644 --- a/js/controllers/copayers.js +++ b/js/controllers/copayers.js @@ -1,35 +1,9 @@ 'use strict'; angular.module('copayApp.controllers').controller('CopayersController', - function($scope, $rootScope, $location, backupService, controllerUtils) { - $scope.isSafari = Object.prototype.toString.call(window.HTMLElement).indexOf('Constructor') > 0; - $scope.hideAdv = true; + function($scope, $rootScope, $location, controllerUtils) { $rootScope.title = 'Copayers'; - $scope.skipBackup = function() { - var w = $rootScope.wallet; - w.setBackupReady(true); - }; - - $scope.backup = function() { - var w = $rootScope.wallet; - if ($scope.isSafari) { - $scope.viewBackup(w); - } else { - w.setBackupReady(); - $scope.downloadBackup(w); - } - }; - - $scope.downloadBackup = function(w) { - backupService.walletDownload(w); - }; - - $scope.viewBackup = function(w) { - $scope.backupPlainText = backupService.walletEncrypted(w); - $scope.hideViewBackup = true; - }; - $scope.goToWallet = function() { controllerUtils.updateAddressList(); $location.path('/receive'); @@ -41,15 +15,4 @@ angular.module('copayApp.controllers').controller('CopayersController', } return $scope.copayers; } - - $scope.isBackupReady = function(copayer) { - if ($rootScope.wallet) { - return $rootScope.wallet.publicKeyRing.isBackupReady(copayer.copayerId); - } - } - - $scope.deleteWallet = function() { - controllerUtils.deleteWallet($scope); - } - }); diff --git a/js/models/PublicKeyRing.js b/js/models/PublicKeyRing.js index da9d745f1..cd89652db 100644 --- a/js/models/PublicKeyRing.js +++ b/js/models/PublicKeyRing.js @@ -23,7 +23,6 @@ var HDParams = require('./HDParams'); * @param {Object[]} [opts.indexes] - an array to be deserialized using {@link HDParams#fromList} * (defaults to all indexes in zero) * @param {Object=} opts.nicknameFor - nicknames for other copayers - * @param {boolean[]} [opts.copayersBackup] - whether other copayers have backed up their wallets */ function PublicKeyRing(opts) { opts = opts || {}; @@ -43,7 +42,6 @@ function PublicKeyRing(opts) { this.publicKeysCache = {}; this.nicknameFor = opts.nicknameFor || {}; this.copayerIds = []; - this.copayersBackup = opts.copayersBackup || []; this.addressToPath = {}; }; @@ -63,7 +61,6 @@ function PublicKeyRing(opts) { * @param {Object[]} data.indexes - an array of objects that can be turned into * an array of HDParams * @param {Object} data.nicknameFor - a registry of nicknames for other copayers - * @param {boolean[]} data.copayersBackup - whether copayers have backed up their wallets * @param {string[]} data.copayersExtPubKeys - the extended public keys of copayers * @returns {Object} a trimmed down version of PublicKeyRing that can be used * as a parameter @@ -71,7 +68,7 @@ function PublicKeyRing(opts) { PublicKeyRing.trim = function(data) { var opts = {}; ['walletId', 'networkName', 'requiredCopayers', 'totalCopayers', - 'indexes', 'nicknameFor', 'copayersBackup', 'copayersExtPubKeys' + 'indexes', 'nicknameFor', 'copayersExtPubKeys' ].forEach(function(k) { opts[k] = data[k]; }); @@ -119,7 +116,6 @@ PublicKeyRing.prototype.toObj = function() { requiredCopayers: this.requiredCopayers, totalCopayers: this.totalCopayers, indexes: HDParams.serialize(this.indexes), - copayersBackup: this.copayersBackup, copayersExtPubKeys: this.copayersHK.map(function(b) { return b.extendedPublicKeyString(); @@ -685,48 +681,6 @@ PublicKeyRing.prototype._mergePubkeys = function(inPKR) { return hasChanged; }; -/** - * @desc - * Mark backup as done for us - * - * @TODO: REVIEW FUNCTIONALITY - it used to have a parameter that was not used at all! - * - * @return {boolean} true if everybody has backed up their wallet - */ -PublicKeyRing.prototype.setBackupReady = function() { - if (this.isBackupReady()) return false; - - var cid = this.myCopayerId(); - this.copayersBackup.push(cid); - return true; -}; - -/** - * @desc returns true if a copayer has backed up his wallet - * @param {string=} copayerId - the pubkey of a copayer, defaults to our own's - * @return {boolean} if this copayer has backed up - */ -PublicKeyRing.prototype.isBackupReady = function(copayerId) { - var cid = copayerId || this.myCopayerId(); - return this.copayersBackup.indexOf(cid) != -1; -}; - -/** - * @desc returns true if all copayers have backed up their wallets - * @return {boolean} - */ -PublicKeyRing.prototype.isFullyBackup = function() { - return this.remainingBackups() == 0; -}; - -/** - * @desc returns the amount of backups remaining - * @return {boolean} - */ -PublicKeyRing.prototype.remainingBackups = function() { - return this.totalCopayers - this.copayersBackup.length; -}; - /** * @desc * Merges this public key ring with another one, optionally ignoring the @@ -742,7 +696,6 @@ PublicKeyRing.prototype.merge = function(inPKR, ignoreId) { var hasChanged = false; hasChanged |= this.mergeIndexes(inPKR.indexes); hasChanged |= this._mergePubkeys(inPKR); - hasChanged |= this._mergeBackups(inPKR.copayersBackup); return !!hasChanged; }; @@ -768,22 +721,5 @@ PublicKeyRing.prototype.mergeIndexes = function(indexes) { return !!hasChanged } -/** - * @desc merges information about backups done by another copy of PublicKeyRing - * @param {string[]} backups - another copy of backups - * @return {boolean} true if the internal state has changed - */ -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 = PublicKeyRing; diff --git a/js/models/Wallet.js b/js/models/Wallet.js index 723cf1181..8b71acbef 100644 --- a/js/models/Wallet.js +++ b/js/models/Wallet.js @@ -94,13 +94,6 @@ function Wallet(opts) { this.lastTimestamp = opts.lastTimestamp || 0; this.lastMessageFrom = {}; - //to avoid confirmation of copayer's backups if is imported from a file - this.isImported = opts.isImported || false; - - - //to avoid waiting others copayers to make a backup and login immediatly - this.forcedLogin = opts.forcedLogin || false; - this.paymentRequests = opts.paymentRequests || {}; var networkName = Wallet.obtainNetworkName(opts); @@ -153,7 +146,6 @@ Wallet.PERSISTED_PROPERTIES = [ 'txProposals', 'privateKey', 'addressBook', - 'backupOffered', 'lastTimestamp', 'secretNumber', ]; @@ -1000,7 +992,6 @@ Wallet.fromUntrustedObj = function(obj, readOpts) { * * @param readOpts.network * @param readOpts.blockchain - * @param readOpts.isImported {boolean} - tag wallet as 'imported' (skip forced backup step) * @param readOpts.{string[]} skipFields - parameters to ignore when importing */ Wallet.fromObj = function(o, readOpts) { @@ -1071,7 +1062,6 @@ Wallet.fromObj = function(o, readOpts) { opts.blockchainOpts = readOpts.blockchainOpts; opts.networkOpts = readOpts.networkOpts; - opts.isImported = readOpts.isImported || false; return new Wallet(opts); }; @@ -2617,24 +2607,11 @@ Wallet.prototype.requiresMultipleSignatures = function() { }; /** - * @desc Returns true if the keyring is complete and all users have backed up the wallet + * @desc Returns true if the keyring is complete * @return {boolean} */ Wallet.prototype.isReady = function() { - var ret = this.publicKeyRing.isComplete() && (this.publicKeyRing.isFullyBackup() || this.isImported || this.forcedLogin); - return ret; -}; - -/** - * @desc Mark that our backup is ready and send a sync to other users. - * - * Also backs up the wallet - */ -Wallet.prototype.setBackupReady = function(forcedLogin) { - this.forcedLogin = forcedLogin; - this.publicKeyRing.setBackupReady(); - this.sendPublicKeyRing(); - this.emitAndKeepAlive('txProposalsUpdated'); + return this.publicKeyRing.isComplete(); }; /** diff --git a/test/PublicKeyRing.js b/test/PublicKeyRing.js index 77cd47b88..f255a9d38 100644 --- a/test/PublicKeyRing.js +++ b/test/PublicKeyRing.js @@ -191,58 +191,6 @@ describe('PublicKeyRing model', function() { w.getHDParams(k.pub).getReceiveIndex().should.equal(2); }); - it('should set backup ready', function() { - var w = getCachedW().w; - w.isBackupReady().should.equal(false); - w.setBackupReady(); - w.isBackupReady().should.equal(true); - }); - - - it('should check for other backups', function() { - var w = createW().w; - w.remainingBackups().should.equal(5); - w.isFullyBackup().should.equal(false); - - w.setBackupReady(); - w.remainingBackups().should.equal(4); - w.isFullyBackup().should.equal(false); - - w.copayersBackup = ["a", "b", "c", "d", "e"]; - w.remainingBackups().should.equal(0); - w.isFullyBackup().should.equal(true); - }); - - it('should merge backup', function() { - var w = getCachedW().w; - var hasChanged; - - w.copayersBackup = ["a", "b"]; - hasChanged = w._mergeBackups(["b", "c"]); - w.copayersBackup.length.should.equal(3); - hasChanged.should.equal(true); - - w.copayersBackup = ["a", "b", "c"]; - hasChanged = w._mergeBackups(["b", "c"]); - w.copayersBackup.length.should.equal(3); - hasChanged.should.equal(false); - }); - - it('should merge backup tests', function() { - var w = createW().w; - - var w2 = new PublicKeyRing({ - networkName: 'livenet', - walletId: w.walletId, - }); - w.merge(w2).should.equal(false); - w.remainingBackups().should.equal(5); - - w2.setBackupReady(); - w.merge(w2).should.equal(true); - w.remainingBackups().should.equal(4); - }); - it('#merge index tests', function() { var k = createW(); var w = k.w; diff --git a/views/copayers.html b/views/copayers.html index 6f6613482..12342f945 100644 --- a/views/copayers.html +++ b/views/copayers.html @@ -3,7 +3,7 @@
-
+

Waiting copayers for {{$root.wallet.getName()}} @@ -18,20 +18,10 @@

-

- Wallet {{$root.wallet.getName()}} - {{$root.wallet.requiredCopayers}}-{{'of'|translate}}-{{$root.wallet.totalCopayers}} - created -

-

- Creating and storing a backup will allow you to recover wallet funds -

-
+
-
-
-
- - Waiting for other copayers to make a Backup -
-
-
-
- Delete wallet - - - - Skip Backup - - - -
-
- - Copy to clipboard -
-
- -
-
Copy this text as it is in a safe place (notepad or email)
-
-