diff --git a/public/views/addressbook.add.html b/public/views/addressbook.add.html new file mode 100644 index 000000000..c5b3762fe --- /dev/null +++ b/public/views/addressbook.add.html @@ -0,0 +1,63 @@ + + + + + + + Add entry + + + + + +
+ +
+ + + +
+ +
+ +
+ +
+
+
diff --git a/public/views/addressbook.html b/public/views/addressbook.html new file mode 100644 index 000000000..3262e0c19 --- /dev/null +++ b/public/views/addressbook.html @@ -0,0 +1,52 @@ + + + + + + + Addressbook + + + + + + + + +
+ +
+ + + + + {{addrEntry.name}} + + + + + + + + + + +
+
diff --git a/public/views/addressbook.view.html b/public/views/addressbook.view.html new file mode 100644 index 000000000..00b191e7f --- /dev/null +++ b/public/views/addressbook.view.html @@ -0,0 +1,36 @@ + + + + + + + Addressbook + + + + + +
+
+

Name

+ {{addressbookEntry.name}} +
+
+

Email

+ {{addressbookEntry.email}} +
+
+

Address

+ {{addressbookEntry.address}} +
+
+ + + +
+
diff --git a/public/views/modals/addressbook.html b/public/views/modals/addressbook.html deleted file mode 100644 index e6a434a8c..000000000 --- a/public/views/modals/addressbook.html +++ /dev/null @@ -1,96 +0,0 @@ - - - -
- Addressbook - Add entry -
- -
- - - -
- -
- -
- - - -

{{addrEntry.label}}

-

{{addrEntry.address}}

- - - - - -
- - -
- -
- -
- - - - -
- -
- -
- -
-
-
diff --git a/public/views/tab-send.html b/public/views/tab-send.html index a230be863..4da7003e1 100644 --- a/public/views/tab-send.html +++ b/public/views/tab-send.html @@ -17,15 +17,15 @@
-
+
Contacts & Wallets - +
No Wallet - Contact
- {{item.label}} + {{item.name}}
diff --git a/public/views/tab-settings.html b/public/views/tab-settings.html index 92276b712..43827c659 100644 --- a/public/views/tab-settings.html +++ b/public/views/tab-settings.html @@ -6,9 +6,10 @@
- + Address Book +
Preferences
diff --git a/src/js/controllers/addressbook.js b/src/js/controllers/addressbook.js new file mode 100644 index 000000000..d9e136901 --- /dev/null +++ b/src/js/controllers/addressbook.js @@ -0,0 +1,56 @@ +'use strict'; + +angular.module('copayApp.controllers').controller('addressbookListController', function($scope, $log, $timeout, addressbookService, lodash, popupService) { + + var contacts; + + $scope.initAddressbook = function() { + addressbookService.list(function(err, ab) { + if (err) $log.error(err); + + $scope.isEmptyList = lodash.isEmpty(ab); + + contacts = []; + lodash.each(ab, function(v, k) { + contacts.push({ + name: lodash.isObject(v) ? v.name : v, + address: k, + email: lodash.isObject(v) ? v.email : null + }); + }); + + $scope.addressbook = lodash.clone(contacts); + }); + }; + + $scope.findAddressbook = function(search) { + if (!search || search.length < 2) { + $scope.addressbook = contacts; + $timeout(function() { + $scope.$apply(); + }, 10); + return; + } + + var result = lodash.filter(contacts, function(item) { + var val = item.name; + return lodash.includes(val.toLowerCase(), search.toLowerCase()); + }); + + $scope.addressbook = result; + }; + + $scope.remove = function(addr) { + $timeout(function() { + addressbookService.remove(addr, function(err, ab) { + if (err) { + popupService.showAlert(err); + return; + } + $scope.initAddressbook(); + $scope.$digest(); + }); + }, 100); + }; + +}); diff --git a/src/js/controllers/addressbookAdd.js b/src/js/controllers/addressbookAdd.js new file mode 100644 index 000000000..8d6831076 --- /dev/null +++ b/src/js/controllers/addressbookAdd.js @@ -0,0 +1,36 @@ +'use strict'; + +angular.module('copayApp.controllers').controller('addressbookAddController', function($scope, $state, $timeout, addressbookService, popupService) { + + $scope.addressbookEntry = { + 'address': '', + 'name': '', + 'email': '' + }; + + $scope.onQrCodeScanned = function(data, addressbookForm) { + $timeout(function() { + var form = addressbookForm; + if (data && form) { + data = data.replace('bitcoin:', ''); + form.address.$setViewValue(data); + form.address.$isValid = true; + form.address.$render(); + } + $scope.$digest(); + }, 100); + }; + + $scope.add = function(addressbook) { + $timeout(function() { + addressbookService.add(addressbook, function(err, ab) { + if (err) { + popupService.showAlert(err); + return; + } + $state.go('tabs.addressbook'); + }); + }, 100); + }; + +}); diff --git a/src/js/controllers/addressbookView.js b/src/js/controllers/addressbookView.js new file mode 100644 index 000000000..a0064fad4 --- /dev/null +++ b/src/js/controllers/addressbookView.js @@ -0,0 +1,37 @@ +'use strict'; + +angular.module('copayApp.controllers').controller('addressbookViewController', function($scope, $state, $timeout, $stateParams, lodash, addressbookService, popupService) { + + var address = $stateParams.address; + + if (!address) { + $state.go('tabs.addressbook'); + return; + } + + addressbookService.get(address, function(err, obj) { + if (err) { + popupService.showAlert(err); + return; + } + if (!lodash.isObject(obj)) { + var name = obj; + obj = { + 'name': name, + 'address': address, + 'email': '' + }; + } + $scope.addressbookEntry = obj; + }); + + $scope.sendTo = function() { + $timeout(function() { + $state.transitionTo('send.amount', { + toAddress: $scope.addressbookEntry.address, + toName: $scope.addressbookEntry.name + }); + }, 100); + }; + +}); diff --git a/src/js/controllers/modals/addressbook.js b/src/js/controllers/modals/addressbook.js deleted file mode 100644 index ee63c7e75..000000000 --- a/src/js/controllers/modals/addressbook.js +++ /dev/null @@ -1,111 +0,0 @@ -'use strict'; - -angular.module('copayApp.controllers').controller('addressbookModalController', function($scope, $log, $state, $timeout, $ionicPopup, addressbookService, lodash, popupService) { - - var contacts; - - $scope.initAddressbook = function() { - addressbookService.list(function(err, ab) { - if (err) $log.error(err); - - $scope.isEmptyList = lodash.isEmpty(ab); - - contacts = []; - lodash.each(ab, function(v, k) { - contacts.push({ - label: v, - address: k - }); - }); - - $scope.addressbook = lodash.clone(contacts); - }); - }; - - $scope.findAddressbook = function(search) { - if (!search || search.length < 2) { - $scope.addressbook = contacts; - $timeout(function() { - $scope.$apply(); - }, 10); - return; - } - - var result = lodash.filter(contacts, function(item) { - var val = item.label; - return lodash.includes(val.toLowerCase(), search.toLowerCase()); - }); - - $scope.addressbook = result; - }; - - $scope.sendTo = function(item) { - $scope.closeAddressbookModal(); - $timeout(function() { - $state.transitionTo('send.amount', { toAddress: item.address, toName: item.label}) - }, 100); - }; - - $scope.closeAddressbookModal = function() { - $scope.cleanAddressbookEntry(); - $scope.addAddressbookEntry = false; - $scope.addressbookModal.hide(); - }; - - $scope.onQrCodeScanned = function(data, addressbookForm) { - $timeout(function() { - var form = addressbookForm; - if (data && form) { - data = data.replace('bitcoin:', ''); - form.address.$setViewValue(data); - form.address.$isValid = true; - form.address.$render(); - } - $scope.$digest(); - }, 100); - }; - - $scope.cleanAddressbookEntry = function() { - $scope.addressbookEntry = { - 'address': '', - 'label': '' - }; - }; - - $scope.toggleAddAddressbookEntry = function() { - $scope.cleanAddressbookEntry(); - $scope.addAddressbookEntry = !$scope.addAddressbookEntry; - }; - - $scope.add = function(addressbook) { - $timeout(function() { - addressbookService.add(addressbook, function(err, ab) { - if (err) { - popupService.showAlert(err); - return; - } - $scope.initAddressbook(); - $scope.toggleAddAddressbookEntry(); - $scope.$digest(); - }); - }, 100); - }; - - $scope.remove = function(addr) { - $timeout(function() { - addressbookService.remove(addr, function(err, ab) { - if (err) { - popupService.showAlert(err); - return; - } - $scope.initAddressbook(); - $scope.$digest(); - }); - }, 100); - }; - - $scope.$on('$destroy', function() { - $scope.addressbookModal.remove(); - }); - -}); diff --git a/src/js/controllers/tab-send.js b/src/js/controllers/tab-send.js index ae2d6ceeb..a9756e008 100644 --- a/src/js/controllers/tab-send.js +++ b/src/js/controllers/tab-send.js @@ -1,6 +1,6 @@ 'use strict'; -angular.module('copayApp.controllers').controller('tabSendController', function($scope, $ionicModal, $log, $timeout, addressbookService, profileService, lodash, $state, walletService, incomingData) { +angular.module('copayApp.controllers').controller('tabSendController', function($scope, $log, $timeout, addressbookService, profileService, lodash, $state, walletService, incomingData ) { var originalList; @@ -14,7 +14,7 @@ angular.module('copayApp.controllers').controller('tabSendController', function( lodash.each(wallets, function(v) { originalList.push({ color: v.color, - label: v.name, + name: v.name, isWallet: true, getAddress: function(cb) { walletService.getAddress(v, false, cb); @@ -28,7 +28,7 @@ angular.module('copayApp.controllers').controller('tabSendController', function( var contacts = []; lodash.each(ab, function(v, k) { contacts.push({ - label: v, + name: lodash.isObject(v) ? v.name : v, address: k, getAddress: function(cb) { return cb(null, k); @@ -60,7 +60,7 @@ angular.module('copayApp.controllers').controller('tabSendController', function( } var result = lodash.filter(originalList, function(item) { - var val = item.label || item.alias || item.name; + var val = item.name; return lodash.includes(val.toLowerCase(), search.toLowerCase()); }); @@ -73,23 +73,14 @@ angular.module('copayApp.controllers').controller('tabSendController', function( $log.error(err); return; } - $log.debug('Got toAddress:' + addr + ' | ' + item.label); + $log.debug('Got toAddress:' + addr + ' | ' + item.name); return $state.transitionTo('send.amount', { toAddress: addr, - toName: item.label + toName: item.name }) }); }; - $scope.openAddressbookModal = function() { - $ionicModal.fromTemplateUrl('views/modals/addressbook.html', { - scope: $scope - }).then(function(modal) { - $scope.addressbookModal = modal; - $scope.addressbookModal.show(); - }); - }; - $scope.$on('modal.hidden', function() { $scope.init(); }); diff --git a/src/js/controllers/tab-settings.js b/src/js/controllers/tab-settings.js index e4ce0e833..b779d5f87 100644 --- a/src/js/controllers/tab-settings.js +++ b/src/js/controllers/tab-settings.js @@ -1,6 +1,6 @@ 'use strict'; -angular.module('copayApp.controllers').controller('tabSettingsController', function($scope, $rootScope, $log, $ionicModal, $window, lodash, configService, uxLanguage, platformInfo, pushNotificationsService, profileService, feeService) { +angular.module('copayApp.controllers').controller('tabSettingsController', function($scope, $rootScope, $log, $window, lodash, configService, uxLanguage, platformInfo, pushNotificationsService, profileService, feeService) { $scope.init = function() { @@ -38,17 +38,6 @@ angular.module('copayApp.controllers').controller('tabSettingsController', funct $scope.wallets = profileService.getWallets(); }; - $scope.openAddressbookModal = function() { - - $ionicModal.fromTemplateUrl('views/modals/addressbook.html', { - scope: $scope - }).then(function(modal) { - $scope.addressbookModal = modal; - $scope.addressbookModal.show(); - }); - }; - - $scope.openSettings = function() { cordova.plugins.diagnostic.switchToSettings(function() { $log.debug('switched to settings'); diff --git a/src/js/routes.js b/src/js/routes.js index 9138cb306..0c2158085 100644 --- a/src/js/routes.js +++ b/src/js/routes.js @@ -490,6 +490,41 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr } }) + /* + * + * Addressbook + * + */ + + + .state('tabs.addressbook', { + url: '/addressbook', + views: { + 'tab-settings': { + templateUrl: 'views/addressbook.html', + controller: 'addressbookListController' + } + } + }) + .state('tabs.addressbook.add', { + url: '/add', + views: { + 'tab-settings@tabs': { + templateUrl: 'views/addressbook.add.html', + controller: 'addressbookAddController' + } + } + }) + .state('tabs.addressbook.view', { + url: '/view/:address', + views: { + 'tab-settings@tabs': { + templateUrl: 'views/addressbook.view.html', + controller: 'addressbookViewController' + } + } + }) + /* * *TO DO diff --git a/src/js/services/addressbookService.js b/src/js/services/addressbookService.js index 74fe7edcc..edd3237d1 100644 --- a/src/js/services/addressbookService.js +++ b/src/js/services/addressbookService.js @@ -3,12 +3,16 @@ angular.module('copayApp.services').factory('addressbookService', function(bitcore, storageService, lodash) { var root = {}; - root.getLabel = function(addr, cb) { + root.get = function(addr, cb) { storageService.getAddressbook('testnet', function(err, ab) { - if (ab && ab[addr]) return cb(ab[addr]); + if (err) return cb(err); + if (ab) ab = JSON.parse(ab); + if (ab && ab[addr]) return cb(null, ab[addr]); - storageService.getAddressbook('livnet', function(err, ab) { - if (ab && ab[addr]) return cb(ab[addr]); + storageService.getAddressbook('livenet', function(err, ab) { + if (err) return cb(err); + if (ab) ab = JSON.parse(ab); + if (ab && ab[addr]) return cb(null, ab[addr]); return cb(); }); }); @@ -38,7 +42,7 @@ angular.module('copayApp.services').factory('addressbookService', function(bitco ab = ab || {}; if (lodash.isArray(ab)) ab = {}; // No array if (ab[entry.address]) return cb('Entry already exist'); - ab[entry.address] = entry.label; + ab[entry.address] = entry; storageService.setAddressbook(network, JSON.stringify(ab), function(err, ab) { if (err) return cb('Error adding new entry'); root.list(function(err, ab) {