From 099a282fb930c7d079e31147281217b86df17d2b Mon Sep 17 00:00:00 2001 From: Yemel Jardi Date: Mon, 23 Jun 2014 17:34:54 -0300 Subject: [PATCH] Add directive to render address from the book with a tooltip --- index.html | 14 ++++++++++---- js/directives.js | 17 +++++++++++++++++ test/unit/directives/directivesSpec.js | 25 +++++++++++++++++++++++++ 3 files changed, 52 insertions(+), 4 deletions(-) diff --git a/index.html b/index.html index f3f2a79a7..f0dc4934b 100644 --- a/index.html +++ b/index.html @@ -372,7 +372,7 @@ ng-click="selectAddress(addr)" ng-class="{selected : addr.address == selectedAddr.address}"> - {{addr.address}} + change @@ -441,7 +441,9 @@
{{out.value | number}} {{$root.unitName}}
-
{{out.address}}
+
+ +
@@ -566,7 +568,9 @@
{{vin.value| number}} {{$root.unitName}} -

{{vin.addr}}

+

+ +

@@ -575,7 +579,9 @@
{{vout.value| number}} {{$root.unitName}} -

{{vout.addr}}

+

+ +

diff --git a/js/directives.js b/js/directives.js index c8ef3c573..c72ffc970 100644 --- a/js/directives.js +++ b/js/directives.js @@ -122,6 +122,23 @@ angular.module('copayApp.directives') } } }) + .directive('contact', function() { + return { + restrict: 'E', + link:function(scope, element, attrs) { + if (!scope.wallet) return; + + var address = attrs.address; + var contact = scope.wallet.addressBook[address]; + if (contact) { + element.append(contact.label); + attrs['tooltip'] = attrs.address; + } else { + element.append(address); + } + } + }; + }) .directive('highlightOnChange', function() { return { restrict: 'A', diff --git a/test/unit/directives/directivesSpec.js b/test/unit/directives/directivesSpec.js index d7186c41f..755281893 100644 --- a/test/unit/directives/directivesSpec.js +++ b/test/unit/directives/directivesSpec.js @@ -80,6 +80,31 @@ describe("Unit: Testing Directives", function() { }); }); + describe('Contact directive', function() { + var element1, element2; + + beforeEach(inject(function($compile, $rootScope) { + $rootScope.wallet = { + addressBook: {'2MtBXKLtZuXGDshUcyH6yq7aZ33Snbb49pT': {label: ':)'}} + } + element1 = angular.element( + '' + ); + element2 = angular.element( + '' + ); + $compile(element1)($rootScope); + $compile(element2)($rootScope); + $rootScope.$digest(); + })); + + it('should replace the content', function() { + expect(element1.html()).to.equal(':)'); + expect(element2.html()).to.equal('2MvCKdnwEMiaexi247gi738U6pwUFZxbhXn'); + }); + + }); + describe('Password strength', function() { beforeEach(inject(function($compile, $rootScope) { $scope = $rootScope;