From ac2eda367055bb0e290d75ec3a0ff2bf040c6953 Mon Sep 17 00:00:00 2001 From: Gustavo Cortez Date: Mon, 7 Jul 2014 14:53:34 -0300 Subject: [PATCH] Fixes typos and re-factory throw errors --- js/controllers/send.js | 25 +++++++++--------------- js/models/core/Wallet.js | 42 ++++++++++++++++------------------------ 2 files changed, 26 insertions(+), 41 deletions(-) diff --git a/js/controllers/send.js b/js/controllers/send.js index dc9518351..914e6e54e 100644 --- a/js/controllers/send.js +++ b/js/controllers/send.js @@ -186,26 +186,19 @@ angular.module('copayApp.controllers').controller('SendController', }, 500); }; - $scope.addressbook = {}; - $scope.verifyAddressbookSignature = function(key) { - if (key) { - $timeout(function() { - var w = $rootScope.wallet; - var signature = w.verfifyAddressbookSignature(key); - $scope.addressbook[key] = signature; - if (!signature) { - notification.error('Wrong signature', 'Entry of Addressbooks was deleted'); - } - }, 10); - } + $timeout(function() { + var w = $rootScope.wallet; + var isValid = w.verfifyAddressbookSignature(key); + if (!isValid) { + notification.error('Wrong signature', 'Entry of Addressbooks was deleted'); + } + }, 10); }; $scope.toggleAddressBookEntry = function(key) { - if (key) { - var w = $rootScope.wallet; - w.toggleAddressBookEntry(key); - } + var w = $rootScope.wallet; + w.toggleAddressBookEntry(key); }; $scope.copyAddress = function(address) { diff --git a/js/models/core/Wallet.js b/js/models/core/Wallet.js index 7bd375377..910b7d5ad 100644 --- a/js/models/core/Wallet.js +++ b/js/models/core/Wallet.js @@ -853,35 +853,27 @@ Wallet.prototype.setAddressBook = function(key, label) { }; Wallet.prototype.verfifyAddressbookSignature = function(key) { - if (key) { - var signature = this.addressBook[key].signature; - var payload = { - address: key, - label: this.addressBook[key].label, - copayerId: this.addressBook[key].copayerId, - createdTs: this.addressBook[key].createdTs - }; - var isVerified = this.verifySignedObject(payload, signature); - if (!isVerified) { - // remove wrong signed entry - delete this.addressBook[key]; - this.store(); - } - return isVerified; - } - else { - throw new Error('Key is required'); + if (!key) throw new Error('Key is required'); + var signature = this.addressBook[key].signature; + var payload = { + address: key, + label: this.addressBook[key].label, + copayerId: this.addressBook[key].copayerId, + createdTs: this.addressBook[key].createdTs + }; + var isVerified = this.verifySignedObject(payload, signature); + if (!isVerified) { + // remove wrong signed entry + delete this.addressBook[key]; + this.store(); } + return isVerified; } Wallet.prototype.toggleAddressBookEntry = function(key) { - if (key) { - this.addressBook[key].hidden = !this.addressBook[key].hidden; - this.store(); - } - else { - throw new Error('Key is required'); - } + if (!key) throw new Error('Key is required'); + this.addressBook[key].hidden = !this.addressBook[key].hidden; + this.store(); }; Wallet.prototype.isReady = function() {