From 9d5f2ddf16c592f8a4fdc127e42448f54eb7ec15 Mon Sep 17 00:00:00 2001 From: Yemel Jardi Date: Wed, 14 May 2014 14:24:24 -0700 Subject: [PATCH] add validation to wallet secret --- css/main.css | 3 +++ index.html | 2 +- js/directives.js | 15 +++++++++++++++ js/models/core/WalletFactory.js | 16 ++++++++++------ 4 files changed, 29 insertions(+), 7 deletions(-) diff --git a/css/main.css b/css/main.css index e6e793f09..9321a5d7f 100644 --- a/css/main.css +++ b/css/main.css @@ -496,3 +496,6 @@ a.loading { vertical-align:middle } +input.ng-invalid-wallet-secret { + background: #FFB6C1; +} diff --git a/index.html b/index.html index 57a600cda..494a4d4a7 100644 --- a/index.html +++ b/index.html @@ -190,7 +190,7 @@

Join a Wallet in Creation

- + diff --git a/js/directives.js b/js/directives.js index 78124f461..5ee0993dd 100644 --- a/js/directives.js +++ b/js/directives.js @@ -64,6 +64,21 @@ angular.module('copay.directives') }; } ]) + .directive('walletSecret', ['walletFactory', + function(walletFactory) { + return { + require: 'ngModel', + link: function(scope, elem, attrs, ctrl) { + var validator = function(value) { + ctrl.$setValidity('walletSecret', Boolean(walletFactory.decodeSecret(value))); + return value; + }; + + ctrl.$parsers.unshift(validator); + } + }; + } + ]) .directive('loading', function() { return { restrict: 'A', diff --git a/js/models/core/WalletFactory.js b/js/models/core/WalletFactory.js index 4f110a279..0db065eeb 100644 --- a/js/models/core/WalletFactory.js +++ b/js/models/core/WalletFactory.js @@ -162,16 +162,20 @@ WalletFactory.prototype.remove = function(walletId) { this.log('TODO: remove wallet contents'); }; +WalletFactory.prototype.decodeSecret = function(secret) { + try { + return Wallet.decodeSecret(secret); + } catch (e) { + return false; + } +} + WalletFactory.prototype.joinCreateSession = function(secret, nickname, passphrase, cb) { var self = this; - var s; - try { - s=Wallet.decodeSecret(secret); - } catch (e) { - return cb('badSecret'); - } + var s = self.decodeSecret(secret); + if (!s) return cb('badSecret'); //Create our PrivateK var privateKey = new PrivateKey({ networkName: this.networkName });