From 089ca1fec6698a4fb4e2e69e8fd04e4a8b7fc32c Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Wed, 1 Apr 2015 16:10:03 -0300 Subject: [PATCH] refactor update pkr --- lib/model/wallet.js | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/lib/model/wallet.js b/lib/model/wallet.js index 3439321..284d829 100644 --- a/lib/model/wallet.js +++ b/lib/model/wallet.js @@ -89,15 +89,20 @@ Wallet.prototype.isShared = function() { return this.n > 1; }; + +Wallet.prototype._updatePublicKeyRing = function() { + this.publicKeyRing = _.map(this.copayers, function(copayer) { + return _.pick(copayer, ['xPubKey', 'requestPubKey', 'isTemporaryRequestKey']); + }); +}; + Wallet.prototype.addCopayer = function(copayer) { - this.copayers.push(copayer); + this.copayers.push(copayer); if (this.copayers.length < this.n) return; this.status = 'complete'; - this.publicKeyRing = _.map(this.copayers, function(copayer) { - return _.pick(copayer, ['xPubKey', 'requestPubKey', 'isTemporaryRequestKey']); - }); + this._updatePublicKeyRing(); }; Wallet.prototype.updateCopayerRequestKey = function(copayerId, requestPubKey) { @@ -108,13 +113,11 @@ Wallet.prototype.updateCopayerRequestKey = function(copayerId, requestPubKey) { }); $.checkState(c) - .checkState(c.isTemporaryRequestKey); + .checkState(c.isTemporaryRequestKey); c.requestPubKey = requestPubKey; c.isTemporaryRequestKey = false; - this.publicKeyRing = _.map(this.copayers, function(copayer) { - return _.pick(copayer, ['xPubKey', 'requestPubKey', 'isTemporaryRequestKey']); - }); + this._updatePublicKeyRing(); }; Wallet.prototype.getCopayer = function(copayerId) {