diff --git a/css/src/main.css b/css/src/main.css index e83fc982d..dbffed1bd 100644 --- a/css/src/main.css +++ b/css/src/main.css @@ -1492,6 +1492,32 @@ a.text-warning:hover {color: #FD7262;} width: 50%; margin-left: -25%; } + dialog.large, .reveal-modal.large { + max-height: 70%; + overflow-y: auto; + width: 80%; + margin-left: -40%; + } +} + +@media only screen and (max-width: 40em) { + dialog.large, .reveal-modal.large { + height: 100%; + overflow-y: auto; + padding: 1.25rem 0.25rem; + } + + dialog.large span.address-size, .reveal-modal.large span.address-size { + font-size: 12px; + } + + dialog.large table, .reveal-modal.large table { + margin: 0; + box-shadow: none; + -webkit-box-shadow: none; + -moz-box-shadow: none; + -o-box-shadow: none; + } } @media (max-height: 380px) { @@ -1642,6 +1668,15 @@ a.text-warning:hover {color: #FD7262;} text-align: center; } +.addressbook-entry td { + display: block; + cursor: pointer; +} + +.addressbook-disabled td, .addressbook-disabled td a { + color: #8597A7; +} + /*/////////////////////////////////////////////////*/ .session-expired { diff --git a/js/controllers/send.js b/js/controllers/send.js index bf52a5be8..d8912de06 100644 --- a/js/controllers/send.js +++ b/js/controllers/send.js @@ -3,7 +3,7 @@ var bitcore = require('bitcore'); var preconditions = require('preconditions').singleton(); angular.module('copayApp.controllers').controller('SendController', - function($scope, $rootScope, $window, $timeout, $modal, $filter, isMobile, notification, rateService) { + function($scope, $rootScope, $window, $timeout, $modal, $filter, $location, isMobile, notification, rateService) { var w = $rootScope.wallet; preconditions.checkState(w); preconditions.checkState(w.settings.unitToSatoshi); @@ -96,13 +96,9 @@ angular.module('copayApp.controllers').controller('SendController', $scope.init = function() { - // Empty + // Empty }; - $scope.showAddressBook = function() { - return w && _.keys(w.addressBook).length > 0; - }; - navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia; window.URL = window.URL || window.webkitURL || window.mozURL || window.msURL; @@ -308,62 +304,6 @@ angular.module('copayApp.controllers').controller('SendController', }); } - $scope.toggleAddressBookEntry = function(key) { - w.toggleAddressBookEntry(key); - }; - - $scope.copyAddress = function(address) { - $scope.address = address; - }; - - $scope.openAddressBookModal = function() { - var modalInstance = $modal.open({ - templateUrl: 'views/modals/address-book.html', - windowClass: 'tiny', - controller: function($scope, $modalInstance) { - - $scope.submitAddressBook = function(form) { - if (form.$invalid) { - return; - } - var entry = { - "address": form.newaddress.$modelValue, - "label": form.newlabel.$modelValue - }; - form.newaddress.$pristine = form.newlabel.$pristine = true; - $modalInstance.close(entry); - }; - - $scope.cancel = function() { - $modalInstance.dismiss('cancel'); - }; - }, - }); - - modalInstance.result.then(function(entry) { - - $timeout(function() { - $scope.loading = false; - var errorMsg; - try { - w.setAddressBook(entry.address, entry.label); - } catch (e) { - errorMsg = e.message; - } - - // TODO change this notifications - if (errorMsg) { - notification.error('Error', errorMsg); - } else { - notification.success('Success', 'New entry has been created'); - } - $rootScope.$digest(); - }, 500); - // reset fields - $scope.newaddress = $scope.newlabel = null; - }); - }; - $scope.setTopAmount = function() { $scope.amount = $rootScope.topAmount; }; @@ -597,6 +537,81 @@ angular.module('copayApp.controllers').controller('SendController', var value; var pp = $rootScope.pendingPayment; _onChanged(pp); - } + } + + $scope.openAddressBook = function() { + var modalInstance = $modal.open({ + templateUrl: 'views/modals/address-book.html', + windowClass: 'large', + controller: function($scope, $modalInstance) { + + $scope.showForm = null; + $scope.addressBook = w.addressBook; + + $scope.hasEntry = function() { + return _.keys($scope.addressBook).length > 0 ? true : false; + }; + + $scope.toggleAddressBookEntry = function(key) { + w.toggleAddressBookEntry(key); + }; + + $scope.copyToSend = function(addr) { + $modalInstance.close(addr); + }; + + $scope.cancel = function() { + $scope.error = $scope.success = null; + $scope.toggleForm(); + }; + + $scope.toggleForm = function() { + $scope.showForm = !$scope.showForm; + }; + + $scope.submitAddressBook = function(form) { + if (form.$invalid) { + return; + } + $timeout(function() { + var errorMsg; + var entry = { + "address": form.newaddress.$modelValue, + "label": form.newlabel.$modelValue + }; + try { + w.setAddressBook(entry.address, entry.label); + } catch (e) { + console.log('[send.js:583]',e); //TODO + errorMsg = e.message; + } + + if (errorMsg) { + $scope.error = errorMsg; + } else { + $scope.toggleForm(); + $scope.success = 'New entry has been created'; + } + $rootScope.$digest(); + }, 500); + + $timeout(function() { + $scope.error = $scope.success = null; + }, 5000); + + return; + + }; + + $scope.close = function() { + $modalInstance.dismiss('cancel'); + }; + }, + }); + + modalInstance.result.then(function(addr) { + $scope.address = addr; + }); + }; }); diff --git a/test/unit/controllers/controllersSpec.js b/test/unit/controllers/controllersSpec.js index 21dd6dd05..80c1151a4 100644 --- a/test/unit/controllers/controllersSpec.js +++ b/test/unit/controllers/controllersSpec.js @@ -222,10 +222,6 @@ describe("Unit: Controllers", function() { expect(scope.title).equal('Create Transaction Proposal'); }); - it('should return true if wallet has addressBook', function() { - expect(scope.showAddressBook()).equal(true); - }); - it('should validate address with network', function() { form.newaddress.$setViewValue('mkfTyEk7tfgV611Z4ESwDDSZwhsZdbMpVy'); expect(form.newaddress.$invalid).to.equal(false); diff --git a/views/modals/address-book.html b/views/modals/address-book.html index 994c9be8c..2e72c35a1 100644 --- a/views/modals/address-book.html +++ b/views/modals/address-book.html @@ -1,33 +1,90 @@ -

Address Book

-
-
- - - - Not valid - - -
-
- - -
- -