Simple addressbook

This commit is contained in:
Gustavo Maximiliano Cortez 2015-10-22 18:43:32 -03:00
parent 597e9cec23
commit 6dd8b98dfc
No known key found for this signature in database
GPG Key ID: 15EDAD8D9F2EB1AF
12 changed files with 352 additions and 66 deletions

View File

@ -22,7 +22,7 @@
<span ng-show="!tx.merchant.pr.ca"><i class="fi-unlock"></i> {{tx.merchant.domain}}</span>
</span>
<span ng-if="!tx.merchant">
{{tx.toAddress}}
<contact address="{{tx.toAddress}}"></contact>
</span>
</span>
</div>

View File

@ -0,0 +1,130 @@
<div ng-init="wallets[0] ? selectedWalletsOpt = true : selectedWalletsOpts = false">
<nav class="tab-bar">
<section class="left-small">
<a ng-show="!editAddressbook" ng-click="cancel()" class="p10">
<span class="text-close" translate>Close</span>
</a>
</section>
<section class="middle tab-bar-section">
<ul class="button-group round even-2" ng-show="!editAddressbook && wallets[0]">
<li ng-class="{'selected':selectedWalletsOpt}" ng-click="selectedWalletsOpt = true"
translate>
Wallets
</li>
<li ng-class="{'selected':!selectedWalletsOpt}" ng-click="selectedWalletsOpt = false" translate>
Addressbook
</li>
</ul>
<h1 ng-show="editAddressbook || !wallets[0]" class="title ellipsis" ng-style="{'color':color}" translate>
Addressbook
</h1>
</section>
<section class="right-small" ng-show="!selectedWalletsOpt" ng-click="toggleEditAddressbook()">
<a ng-show="!editAddressbook" href class="p10">
<span class="text-close" translate>Edit</span>
</a>
<a ng-show="editAddressbook && !addAddressbookEntry" href class="p10">
<span class="text-close" translate>Done</span>
</a>
</section>
</nav>
<div class="modal-content fix-modals-touch">
<div ng-show="selectedWalletsOpt">
<div class="onGoingProcess" ng-if="gettingAddress">
<div class="onGoingProcess-content" ng-style="{'background-color':'#222'}">
<div class="spinner">
<div class="rect1"></div>
<div class="rect2"></div>
<div class="rect3"></div>
<div class="rect4"></div>
<div class="rect5"></div>
</div>
<span translate> Getting address for wallet {{selectedWalletName}} ...</span>
</div>
</div>
<div ng-if="!gettingAddress">
<ul class="no-bullet">
<li class="line-b" ng-repeat="w in wallets">
<a ng-click="selectWallet(w.id, w.name)" class="db oh">
<div class="avatar-wallet"
ng-style="{'background-color':w.color}">{{(w.name || w.id) | limitTo: 1}}</div>
<div class="ellipsis name-wallet text-bold">{{w.name || w.id}}</div>
<div class="size-12">{{w.m}} of {{w.n}}
<span ng-show="w.network=='testnet'">[Testnet]</span>
</div>
</a>
</li>
</ul>
</div>
</div>
<div ng-show="!selectedWalletsOpt" class="m20b">
<ul ng-show="!addAddressbookEntry" class="no-bullet m0" ng-init="list()">
<li class="p10 line-b" ng-repeat="(addr, label) in list">
<a ng-show="selectedAddressbook[addr]"
class="removeAddressbook"
ng-click="remove(addr)" translate>Remove</a>
<a class="selectAddressbook"
ng-show="editAddressbook"
ng-click="toggleSelectAddressbook(addr)">
<i class="fi-trash"></i></a>
<div ng-click="selectAddressbook(addr)">
{{label}}
<div class="size-10 text-gray ellipsis">{{addr}}</div>
</div>
</li>
<li class="m10t" ng-show="!editAddressbook">
<a ng-click="toggleAddAddressbookEntry()" class="p10">
<i class="fi-plus size-18 m10r"></i>
<span class="text-close size-12" translate>Add a new entry</span>
</a>
</li>
</ul>
<div ng-if="addAddressbookEntry" ng-init="addressbook.address = ''; addressbook.label = ''">
<h4 class="title m0" translate>Add a new entry</h4>
<form name="addressbookForm" class="p10" no-validate>
<div class="text-warning size-12 m10b" ng-show="error">{{error|translate}}</div>
<span ng-hide="addressbookForm.address.$pristine">
<span class="has-error right size-12" ng-show="addressbookForm.address.$invalid && addressbook.address">
<i class="icon-close-circle size-14"></i>
<span class="vm" translate>Not valid</span>
</span>
<small class="right text-primary" ng-show="!addressbookForm.address.$invalid">
<i class="icon-checkmark-circle size-14"></i>
</small>
</span>
<label translate>Address</label>
<input type="text" id="address" name="address" ng-model="addressbook.address" valid-address required>
<label translate>Label</label>
<input type="text" id="label" name="label" ng-model="addressbook.label" required>
<div class="row">
<div class="columns large-6 medium-6 small-6">
<input type="button"
class="button expand round"
ng-click="toggleAddAddressbookEntry()"
value="{{'Cancel'|translate}}">
</div>
<div class="columns large-6 medium-6 small-6">
<input type="submit"
class="button expand round"
value="{{'Save'|translate}}"
ng-disabled="!addressbookForm.$valid"
ng-style="{'background-color':color}"
ng-click="add(addressbook)">
</div>
</div>
</form>
</div>
</div>
<div class="extra-margin-bottom"></div>
</div>
</div>

View File

@ -34,7 +34,8 @@
<span ng-show="!btx.merchant.pr.ca"><i class="fi-unlock color-yellowi"></i> {{btx.merchant.domain}}</span>
</span>
<span ng-if="!btx.merchant">
<span class="enable_text_select"> {{btx.labelTo || btx.addressTo}}</span>
<span ng-show="btx.labelTo">{{btx.labelTo}}</span>
<contact ng-show="!btx.labelTo" class="enable_text_select" address="{{btx.addressTo}}"></contact>
</span>
</span>
</li>

View File

@ -18,7 +18,7 @@
class="line-b p10 oh"
ng-click="copyAddress(tx.toAddress)">
<span class="text-gray" translate>To</span>:
<span class="right enable_text_select">{{tx.toAddress}}</span>
<contact class="right enable_text_select" address="{{tx.toAddress}}"></contact>
</li>
<li class="line-b p10">
<span ng-show="tx.hasMultiplesOutputs" class="text-gray" translate>Total</span>

View File

@ -1,44 +0,0 @@
<nav class="tab-bar">
<section class="left-small">
<a ng-click="cancel()" class="p10">
<span class="text-close" translate>Close</span>
</a>
</section>
<section class="middle tab-bar-section">
<h1 class="title ellipsis" ng-style="{'color':color}" translate>
Choose a wallet to send funds
</h1>
</section>
</nav>
<div class="modal-content">
<div class="onGoingProcess" ng-if="gettingAddress">
<div class="onGoingProcess-content" ng-style="{'background-color':'#222'}">
<div class="spinner">
<div class="rect1"></div>
<div class="rect2"></div>
<div class="rect3"></div>
<div class="rect4"></div>
<div class="rect5"></div>
</div>
<span translate> Getting address for wallet {{selectedWalletName}} ...</span>
</div>
</div>
<div ng-if="!gettingAddress">
<ul class="no-bullet">
<li class="line-b" ng-repeat="w in wallets">
<a ng-click="selectWallet(w.id, w.name)" class="db oh">
<div class="avatar-wallet"
ng-style="{'background-color':w.color}">{{(w.name || w.id) | limitTo: 1}}</div>
<div class="ellipsis name-wallet text-bold">{{w.name || w.id}}</div>
<div class="size-12">{{w.m}} of {{w.n}}
<span ng-show="w.network=='testnet'">[Testnet]</span>
</div>
</a>
</li>
</ul>
</div>
<div class="extra-margin-bottom"></div>
</div>

View File

@ -320,8 +320,9 @@
</div>
<div class="input">
<input type="text" id="address" name="address" ng-disabled="home.blockUx || home.lockAddress" ng-attr-placeholder="{{'Bitcoin address'|translate}}" ng-model="_address" valid-address required ng-focus="home.formFocus('address')" ng-blur="home.formFocus(false)">
<a class="postfix size-12 m0 text-gray" ng-click="openWalletsModal(index.otherWallets)" ng-if="index.otherWallets && index.otherWallets.length>0">
<input ng-show="sendForm.address.$invalid" class="m0" type="text" id="address" name="address" ng-disabled="home.blockUx || home.lockAddress" ng-attr-placeholder="{{'Bitcoin address'|translate}}" ng-model="_address" valid-address required ng-focus="home.formFocus('address')" ng-blur="home.formFocus(false)">
<contact class="addressbook-input" ng-if="!sendForm.address.$invalid && _address" address="{{_address}}"></contact>
<a class="postfix size-12 m0 text-gray" ng-click="openDestinationAddressModal(index.otherWallets)">
<i class="icon-wallet size-18"></i>
</a>
</div>
@ -490,7 +491,8 @@
<i class="icon-arrow-right3 size-18"></i>
</div>
<div class="size-14 text-gray columns m5t" ng-if="btx.message || btx.addressTo">
{{btx.message || btx.addressTo}}
<div ng-show="btx.message">{{btx.message}}</div>
<contact ng-show="!btx.message" class="enable_text_select" address="{{btx.addressTo}}"></contact>
</div>
</div>
<div class="row m20t text-center" ng-show="index.txHistoryPaging || index.updatingTxHistory">

View File

@ -98,6 +98,50 @@ h4.title a {
border-bottom: 1px solid #E9E9EC;
}
.addressbook-input {
display: block;
margin-bottom: 1.5rem;
background-color: #E4E8EC;
padding-left: 0.5rem;
color: #2C3E50;
font-size: 13px;
height: 35px;
padding-top: 7px;
}
ul.button-group {
margin-top: 9px;
}
ul.button-group li:first-child {
border-top-left-radius: 0.2rem;
border-bottom-left-radius: 0.2rem;
border: 1px solid #DEDFE1;
}
ul.button-group li:last-child {
border-top-right-radius: 0.2rem;
border-bottom-right-radius: 0.2rem;
border: 1px solid #DEDFE1;
}
.button-group.even-2 li {
margin: 0 -3px;
}
ul.button-group li {
color: #A5B2BF;
cursor: pointer;
text-transform: uppercase;
font-size: 0.7rem;
display: block;
padding: 3px 0;
}
ul.button-group li.selected {
color: #fff;
background-color: #DEDFE1;
}
body, html{
height:100%;

View File

@ -340,6 +340,21 @@ a.missing-copayers {
padding: 1rem 0.7rem;
}
.modal-content ul li a.removeAddressbook {
background-color: white;
color: red;
margin-right: -10px;
float: right;
}
.modal-content ul li a.selectAddressbook {
float: left;
font-size: 18px;
padding: 13px 14px;
color: red;
margin-right: 10px;
}
.sidebar ul.off-canvas-list li a i {
vertical-align: middle;
opacity: 0.6;

View File

@ -1,6 +1,6 @@
'use strict';
angular.module('copayApp.controllers').controller('walletHomeController', function($scope, $rootScope, $timeout, $filter, $modal, $log, notification, txStatus, isCordova, profileService, lodash, configService, rateService, storageService, bitcore, isChromeApp, gettext, gettextCatalog, nodeWebkit, addressService, ledger, feeService, bwsError, confirmDialog, txFormatService, animationService) {
angular.module('copayApp.controllers').controller('walletHomeController', function($scope, $rootScope, $timeout, $filter, $modal, $log, notification, txStatus, isCordova, profileService, lodash, configService, rateService, storageService, bitcore, isChromeApp, gettext, gettextCatalog, nodeWebkit, addressService, ledger, feeService, bwsError, confirmDialog, txFormatService, animationService, addressbookService) {
var self = this;
$rootScope.hideMenuBar = false;
@ -136,12 +136,71 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
});
};
$scope.openWalletsModal = function(wallets) {
$scope.openDestinationAddressModal = function(wallets, address, label) {
$rootScope.modalOpened = true;
var fc = profileService.focusedClient;
self.resetForm();
var ModalInstanceCtrl = function($scope, $modalInstance) {
$scope.wallets = wallets;
$scope.editAddressbook = false;
$scope.addAddressbookEntry = false;
$scope.selectedAddressbook = {};
$scope.addressbook = { 'address' : address, 'label' : label};
$scope.color = fc.backgroundColor;
$scope.selectAddressbook = function(addr) {
$modalInstance.close(addr);
};
$scope.toggleEditAddressbook = function() {
$scope.editAddressbook = !$scope.editAddressbook;
$scope.selectedAddressbook = {};
$scope.addAddressbookEntry = false;
};
$scope.toggleSelectAddressbook = function(addr) {
$scope.selectedAddressbook[addr] = $scope.selectedAddressbook[addr] ? false : true;
};
$scope.toggleAddAddressbookEntry = function() {
$scope.addAddressbookEntry = !$scope.addAddressbookEntry;
};
$scope.list = function() {
$scope.error = null;
addressbookService.list(function(err, ab) {
if (err) {
$scope.error = err;
return;
}
$scope.list = ab;
});
};
$scope.add = function(addressbook) {
$scope.error = null;
addressbookService.add(addressbook, function(err, ab) {
if (err) {
$scope.error = err;
return;
}
$scope.list = ab;
$scope.editAddressbook = true;
$scope.toggleEditAddressbook();
});
};
$scope.remove = function(addr) {
$scope.error = null;
addressbookService.remove(addr, function(err, ab) {
if (err) {
$scope.error = err;
return;
}
$scope.list = ab;
});
};
$scope.cancel = function() {
$modalInstance.dismiss('cancel');
@ -168,7 +227,7 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
};
var modalInstance = $modal.open({
templateUrl: 'views/modals/wallets.html',
templateUrl: 'views/modals/destination-address.html',
windowClass: animationService.modalAnimated.slideUp,
controller: ModalInstanceCtrl,
});
@ -718,6 +777,9 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
},
set: function(newValue) {
$scope.__address = self.onAddressChange(newValue);
if ($scope.sendForm && $scope.sendForm.address.$valid) {
self.lockAddress = true;
}
},
enumerable: true,
configurable: true

View File

@ -162,27 +162,25 @@ angular.module('copayApp.directives')
}
}
})
.directive('contact', function() {
.directive('contact', ['addressbookService', function(addressbookService) {
return {
restrict: 'E',
link: function(scope, element, attrs) {
if (!scope.wallet) return;
var address = attrs.address;
var contact = scope.wallet.addressBook[address];
if (contact && !contact.hidden) {
element.append(contact.label);
element.attr('tooltip', attrs.address);
} else {
element.append(address);
}
var addr = attrs.address;
addressbookService.getLabel(addr, function(label) {
if (label) {
element.append(label);
} else {
element.append(addr);
}
});
element.bind('click', function() {
selectText(element[0]);
});
}
};
})
}])
.directive('highlightOnChange', function() {
return {
restrict: 'A',

View File

@ -0,0 +1,66 @@
'use strict';
angular.module('copayApp.services').factory('addressbookService', function(storageService, profileService) {
var root = {};
root.getLabel = function(addr, cb) {
var fc = profileService.focusedClient;
storageService.getAddressbook(fc.credentials.network, function(err, ab) {
if (!ab) return cb();
ab = JSON.parse(ab);
if (ab[addr]) return cb(ab[addr]);
else return cb();
});
};
root.list = function(cb) {
var fc = profileService.focusedClient;
storageService.getAddressbook(fc.credentials.network, function(err, ab) {
if (err) return cb('Could not get the Addressbook');
if (ab) ab = JSON.parse(ab);
return cb(err, ab);
});
};
root.add = function(entry, cb) {
var fc = profileService.focusedClient;
root.list(function(err, ab) {
if (err) return cb(err);
if (!ab) ab = {};
if (ab[entry.address]) return cb('Entry already exist');
ab[entry.address] = entry.label;
storageService.setAddressbook(fc.credentials.network, JSON.stringify(ab), function(err, ab) {
if (err) return cb('Error adding new entry');
root.list(function(err, ab) {
return cb(err, ab);
});
});
});
};
root.remove = function(addr, cb) {
var fc = profileService.focusedClient;
root.list(function(err, ab) {
if (err) return cb(err);
if (!ab) return;
if (!ab[addr]) return cb('Entry does not exist');
delete ab[addr];
storageService.setAddressbook(fc.credentials.network, JSON.stringify(ab), function(err) {
if (err) return cb('Error deleting entry');
root.list(function(err, ab) {
return cb(err, ab);
});
});
});
};
root.removeAll = function() {
var fc = profileService.focusedClient;
storageService.removeAddressbook(fc.credentials.network, function(err) {
if (err) return cb('Error deleting addressbook');
return cb();
});
};
return root;
});

View File

@ -204,5 +204,17 @@ angular.module('copayApp.services')
storage.remove('glideraToken-' + network, cb);
};
root.setAddressbook = function(network, addressbook, cb) {
storage.set('addressbook-' + network, addressbook, cb);
};
root.getAddressbook = function(network, cb) {
storage.get('addressbook-' + network, cb);
};
root.removeAddressbook = function(network, cb) {
storage.remove('addressbook-' + network, cb);
};
return root;
});