Merge pull request #234 from cmgustavo/ref/design-16
Fix addressbook. Modal can be opened from anywhere
This commit is contained in:
commit
9c6ccd3ede
7 changed files with 172 additions and 117 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
<ion-modal-view>
|
<ion-modal-view ng-controller="addressbookModalController" ng-init="initAddressbook()">
|
||||||
<ion-header-bar align-title="center" class="bar-stable">
|
<ion-header-bar align-title="center" class="bar-stable">
|
||||||
<button class="button button-clear button-positive"
|
<button class="button button-clear button-positive"
|
||||||
ng-click="closeAddressbookModal()">
|
ng-click="closeAddressbookModal()">
|
||||||
|
|
@ -22,14 +22,17 @@
|
||||||
<i class="icon ion-ios-search placeholder-icon"></i>
|
<i class="icon ion-ios-search placeholder-icon"></i>
|
||||||
<input type="search"
|
<input type="search"
|
||||||
placeholder="Search"
|
placeholder="Search"
|
||||||
ng-model="search"
|
ng-model="addrSearch"
|
||||||
ng-change="findContact(search, {onlyContacts: true})" ng-model-onblur>
|
ng-change="findAddressbook(addrSearch)" ng-model-onblur>
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div ng-show="!addAddressbookEntry">
|
<div ng-show="!addAddressbookEntry">
|
||||||
<ion-list>
|
<ion-list>
|
||||||
<ion-item ng-repeat="addrEntry in list" class="item-icon-left" ng-show="!addrEntry.isWallet" ng-click="goToAmount(addrEntry)">
|
<ion-item ng-repeat="addrEntry in addressbook"
|
||||||
|
class="item-icon-left"
|
||||||
|
ng-show="!addrEntry.isWallet"
|
||||||
|
ng-click="sendTo(addrEntry)">
|
||||||
<i class="icon ion-ios-person-outline"></i>
|
<i class="icon ion-ios-person-outline"></i>
|
||||||
<h2>{{addrEntry.label}}</h2>
|
<h2>{{addrEntry.label}}</h2>
|
||||||
<p>{{addrEntry.address}}</p>
|
<p>{{addrEntry.address}}</p>
|
||||||
|
|
@ -50,8 +53,6 @@
|
||||||
|
|
||||||
<form name="addressbookForm" ng-show="addAddressbookEntry" no-validate>
|
<form name="addressbookForm" ng-show="addAddressbookEntry" no-validate>
|
||||||
|
|
||||||
<div class="padding-vertical assertive" ng-show="error">{{error|translate}}</div>
|
|
||||||
|
|
||||||
<div class="list">
|
<div class="list">
|
||||||
|
|
||||||
<label class="item item-input item-stacked-label">
|
<label class="item item-input item-stacked-label">
|
||||||
|
|
@ -63,7 +64,7 @@
|
||||||
ng-show="addressbookForm.address.$invalid && addressbookEntry.address"></i>
|
ng-show="addressbookForm.address.$invalid && addressbookEntry.address"></i>
|
||||||
</div>
|
</div>
|
||||||
<div class="qr-scan-icon">
|
<div class="qr-scan-icon">
|
||||||
<qr-scanner on-scan="onQrCodeScanned(data)"></qr-scanner>
|
<qr-scanner on-scan="onQrCodeScanned(data, addressbookForm)"></qr-scanner>
|
||||||
<input type="text"
|
<input type="text"
|
||||||
id="address"
|
id="address"
|
||||||
name="address"
|
name="address"
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@
|
||||||
<h3>Contacts & Wallets</h3>
|
<h3>Contacts & Wallets</h3>
|
||||||
</div>
|
</div>
|
||||||
<div class="col col-20 text-right">
|
<div class="col col-20 text-right">
|
||||||
<a class="button button-light" ng-click="openAddressbookModal(list)">
|
<a class="button button-light" ng-click="openAddressbookModal()">
|
||||||
<i class="size-36 icon ion-person-add"></i>
|
<i class="size-36 icon ion-person-add"></i>
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
124
src/js/controllers/modals/addressbook.js
Normal file
124
src/js/controllers/modals/addressbook.js
Normal file
|
|
@ -0,0 +1,124 @@
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
angular.module('copayApp.controllers').controller('addressbookModalController', function($scope, $log, $state, $timeout, $ionicPopup, addressbookService, lodash) {
|
||||||
|
|
||||||
|
var contacts;
|
||||||
|
|
||||||
|
// An alert dialog
|
||||||
|
var showAlert = function(title, msg, cb) {
|
||||||
|
$log.warn(title + ": " + msg);
|
||||||
|
var alertPopup = $ionicPopup.alert({
|
||||||
|
title: title,
|
||||||
|
template: msg
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!cb) cb = function() {};
|
||||||
|
|
||||||
|
alertPopup.then(cb);
|
||||||
|
};
|
||||||
|
|
||||||
|
$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) {
|
||||||
|
showAlert(err);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$scope.initAddressbook();
|
||||||
|
$scope.toggleAddAddressbookEntry();
|
||||||
|
$scope.$digest();
|
||||||
|
});
|
||||||
|
}, 100);
|
||||||
|
};
|
||||||
|
|
||||||
|
$scope.remove = function(addr) {
|
||||||
|
$timeout(function() {
|
||||||
|
addressbookService.remove(addr, function(err, ab) {
|
||||||
|
if (err) {
|
||||||
|
showAlert(err);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$scope.initAddressbook();
|
||||||
|
$scope.$digest();
|
||||||
|
});
|
||||||
|
}, 100);
|
||||||
|
};
|
||||||
|
|
||||||
|
$scope.$on('$destroy', function() {
|
||||||
|
$scope.addressbookModal.remove();
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
@ -4,15 +4,6 @@ angular.module('copayApp.controllers').controller('tabSendController', function(
|
||||||
|
|
||||||
var originalList;
|
var originalList;
|
||||||
|
|
||||||
|
|
||||||
// An alert dialog
|
|
||||||
var showAlert = function(title, msg) {
|
|
||||||
$log.warn(title + ": " + msg);
|
|
||||||
var alertPopup = $ionicPopup.alert({
|
|
||||||
title: title,
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
$scope.init = function() {
|
$scope.init = function() {
|
||||||
originalList = [];
|
originalList = [];
|
||||||
|
|
||||||
|
|
@ -32,8 +23,6 @@ angular.module('copayApp.controllers').controller('tabSendController', function(
|
||||||
addressbookService.list(function(err, ab) {
|
addressbookService.list(function(err, ab) {
|
||||||
if (err) $log.error(err);
|
if (err) $log.error(err);
|
||||||
|
|
||||||
$scope.isEmptyList = lodash.isEmpty(ab);
|
|
||||||
|
|
||||||
var contacts = [];
|
var contacts = [];
|
||||||
lodash.each(ab, function(v, k) {
|
lodash.each(ab, function(v, k) {
|
||||||
contacts.push({
|
contacts.push({
|
||||||
|
|
@ -50,10 +39,7 @@ angular.module('copayApp.controllers').controller('tabSendController', function(
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
$scope.findContact = function(search) {
|
||||||
|
|
||||||
$scope.findContact = function(search, opts) {
|
|
||||||
opts = opts || {};
|
|
||||||
|
|
||||||
if (incomingData.redir(search)) {
|
if (incomingData.redir(search)) {
|
||||||
return;
|
return;
|
||||||
|
|
@ -67,8 +53,7 @@ angular.module('copayApp.controllers').controller('tabSendController', function(
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var result = lodash.filter($scope.list, function(item) {
|
var result = lodash.filter(originalList, function(item) {
|
||||||
if (opts && opts.onlyContacts && item.isWallet) return;
|
|
||||||
var val = item.label || item.alias || item.name;
|
var val = item.label || item.alias || item.name;
|
||||||
return lodash.includes(val.toLowerCase(), search.toLowerCase());
|
return lodash.includes(val.toLowerCase(), search.toLowerCase());
|
||||||
});
|
});
|
||||||
|
|
@ -87,82 +72,17 @@ angular.module('copayApp.controllers').controller('tabSendController', function(
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
|
||||||
* Modal Addressbook
|
|
||||||
*/
|
|
||||||
|
|
||||||
$ionicModal.fromTemplateUrl('views/modals/addressbook.html', {
|
|
||||||
scope: $scope
|
|
||||||
}).then(function(modal) {
|
|
||||||
$scope.addressbookModal = modal;
|
|
||||||
});
|
|
||||||
|
|
||||||
$scope.openAddressbookModal = function() {
|
$scope.openAddressbookModal = function() {
|
||||||
$scope.addressbookModal.show();
|
$ionicModal.fromTemplateUrl('views/modals/addressbook.html', {
|
||||||
|
scope: $scope
|
||||||
|
}).then(function(modal) {
|
||||||
|
$scope.addressbookModal = modal;
|
||||||
|
$scope.addressbookModal.show();
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.closeAddressbookModal = function() {
|
$scope.$on('modal.hidden', function() {
|
||||||
$scope.cleanAddressbookEntry();
|
$scope.init();
|
||||||
$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) {
|
|
||||||
$log.error(err);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
$scope.init();
|
|
||||||
$scope.toggleAddAddressbookEntry();
|
|
||||||
$scope.$digest();
|
|
||||||
});
|
|
||||||
}, 100);
|
|
||||||
};
|
|
||||||
|
|
||||||
$scope.remove = function(addr) {
|
|
||||||
$timeout(function() {
|
|
||||||
addressbookService.remove(addr, function(err, ab) {
|
|
||||||
if (err) {
|
|
||||||
$scope.error = err;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
$scope.init();
|
|
||||||
$scope.$digest();
|
|
||||||
});
|
|
||||||
}, 100);
|
|
||||||
};
|
|
||||||
|
|
||||||
$scope.$on('$destroy', function() {
|
|
||||||
$scope.addressbookModal.remove();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
$scope.$watch('')
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -72,6 +72,6 @@ angular.module('copayApp.directives')
|
||||||
},
|
},
|
||||||
controller: controller,
|
controller: controller,
|
||||||
replace: true,
|
replace: true,
|
||||||
template: '<a ng-click="openScanner()"><i class="icon ion-qr-scanner"></i></a>'
|
template: '<a on-tap="openScanner()"><i class="icon ion-qr-scanner"></i></a>'
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,18 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
angular.module('copayApp.services').factory('addressbookService', function($stateParams, storageService, profileService, lodash) {
|
angular.module('copayApp.services').factory('addressbookService', function(bitcore, storageService, lodash) {
|
||||||
var root = {};
|
var root = {};
|
||||||
|
|
||||||
|
var getNetwork = function(addr) {
|
||||||
|
var Address = bitcore.Address;
|
||||||
|
if (Address.isValid(addr, 'livenet')) {
|
||||||
|
return 'livenet';
|
||||||
|
}
|
||||||
|
if (Address.isValid(addr, 'testnet')) {
|
||||||
|
return 'testnet';
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
root.getLabel = function(addr, cb) {
|
root.getLabel = function(addr, cb) {
|
||||||
storageService.getAddressbook('testnet', function(err, ab) {
|
storageService.getAddressbook('testnet', function(err, ab) {
|
||||||
if (ab && ab[addr]) return cb(ab[addr]);
|
if (ab && ab[addr]) return cb(ab[addr]);
|
||||||
|
|
@ -31,13 +41,14 @@ angular.module('copayApp.services').factory('addressbookService', function($stat
|
||||||
};
|
};
|
||||||
|
|
||||||
root.add = function(entry, cb) {
|
root.add = function(entry, cb) {
|
||||||
var wallet = profileService.getWallet($stateParams.walletId);
|
var network = getNetwork(entry.address);
|
||||||
root.list(function(err, ab) {
|
storageService.getAddressbook(network, function(err, ab) {
|
||||||
if (err) return cb(err);
|
if (err) return cb(err);
|
||||||
if (!ab) ab = {};
|
if (ab) ab = JSON.parse(ab);
|
||||||
|
ab = ab || {};
|
||||||
if (ab[entry.address]) return cb('Entry already exist');
|
if (ab[entry.address]) return cb('Entry already exist');
|
||||||
ab[entry.address] = entry.label;
|
ab[entry.address] = entry.label;
|
||||||
storageService.setAddressbook(wallet.credentials.network, JSON.stringify(ab), function(err, ab) {
|
storageService.setAddressbook(network, JSON.stringify(ab), function(err, ab) {
|
||||||
if (err) return cb('Error adding new entry');
|
if (err) return cb('Error adding new entry');
|
||||||
root.list(function(err, ab) {
|
root.list(function(err, ab) {
|
||||||
return cb(err, ab);
|
return cb(err, ab);
|
||||||
|
|
@ -47,13 +58,15 @@ angular.module('copayApp.services').factory('addressbookService', function($stat
|
||||||
};
|
};
|
||||||
|
|
||||||
root.remove = function(addr, cb) {
|
root.remove = function(addr, cb) {
|
||||||
var wallet = profileService.getWallet($stateParams.walletId);
|
var network = getNetwork(addr);
|
||||||
root.list(function(err, ab) {
|
storageService.getAddressbook(network, function(err, ab) {
|
||||||
if (err) return cb(err);
|
if (err) return cb(err);
|
||||||
if (!ab) return;
|
if (ab) ab = JSON.parse(ab);
|
||||||
|
ab = ab || {};
|
||||||
|
if (lodash.isEmpty(ab)) return cb('Addressbook is empty');
|
||||||
if (!ab[addr]) return cb('Entry does not exist');
|
if (!ab[addr]) return cb('Entry does not exist');
|
||||||
delete ab[addr];
|
delete ab[addr];
|
||||||
storageService.setAddressbook(wallet.credentials.network, JSON.stringify(ab), function(err) {
|
storageService.setAddressbook(network, JSON.stringify(ab), function(err) {
|
||||||
if (err) return cb('Error deleting entry');
|
if (err) return cb('Error deleting entry');
|
||||||
root.list(function(err, ab) {
|
root.list(function(err, ab) {
|
||||||
return cb(err, ab);
|
return cb(err, ab);
|
||||||
|
|
@ -63,10 +76,11 @@ angular.module('copayApp.services').factory('addressbookService', function($stat
|
||||||
};
|
};
|
||||||
|
|
||||||
root.removeAll = function() {
|
root.removeAll = function() {
|
||||||
var wallet = profileService.getWallet($stateParams.walletId);
|
storageService.removeAddressbook('livenet', function(err) {
|
||||||
storageService.removeAddressbook(wallet.credentials.network, function(err) {
|
storageService.removeAddressbook('testnet', function(err) {
|
||||||
if (err) return cb('Error deleting addressbook');
|
if (err) return cb('Error deleting addressbook');
|
||||||
return cb();
|
return cb();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -450,14 +450,10 @@ ul.wallet-selection.wallets {
|
||||||
margin-right: 10px;
|
margin-right: 10px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.qr-scan-icon {
|
|
||||||
position: relative;
|
|
||||||
}
|
|
||||||
|
|
||||||
.qr-scan-icon a {
|
.qr-scan-icon a {
|
||||||
display: block;
|
display: block;
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: 0;
|
top: 25px;
|
||||||
right: 0;
|
right: 0;
|
||||||
padding: 0 10px;
|
padding: 0 10px;
|
||||||
font-size: 24px;
|
font-size: 24px;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue