got address book working with bitcoin cash addresses

This commit is contained in:
Kadir Sekha 2018-01-11 19:07:12 +09:00
commit 1c8990fc08
10 changed files with 41 additions and 23 deletions

View file

@ -1,6 +1,6 @@
'use strict';
angular.module('copayApp.controllers').controller('addressbookListController', function($scope, $log, $timeout, addressbookService, lodash, popupService, gettextCatalog, platformInfo) {
angular.module('copayApp.controllers').controller('addressbookListController', function($scope, $log, $timeout, addressbookService, lodash, popupService, gettextCatalog, platformInfo, bitcoinCashJsService) {
var contacts;
@ -15,10 +15,18 @@ angular.module('copayApp.controllers').controller('addressbookListController', f
contacts = [];
lodash.each(ab, function(v, k) {
var c = lodash.isObject(v) ? v.coin : null;
var a = null;
if (c && c == 'bch') {
a = bitcoinCashJsService.readAddress(v.address).cashaddr.replace('bitcoincash:', '');
} else {
a = v.address;
}
contacts.push({
name: lodash.isObject(v) ? v.name : v,
address: k,
email: lodash.isObject(v) ? v.email : null
address: a,
email: lodash.isObject(v) ? v.email : null,
coin: c
});
});

View file

@ -1,6 +1,6 @@
'use strict';
angular.module('copayApp.controllers').controller('addressbookAddController', function($scope, $state, $stateParams, $timeout, $ionicHistory, gettextCatalog, addressbookService, popupService, configService) {
angular.module('copayApp.controllers').controller('addressbookAddController', function($scope, $state, $stateParams, $timeout, $ionicHistory, gettextCatalog, addressbookService, popupService, configService, bitcoinCashJsService) {
var config = configService.getSync();
var defaults = configService.getDefaults();
@ -14,7 +14,7 @@ angular.module('copayApp.controllers').controller('addressbookAddController', fu
'address': $stateParams.addressbookEntry || '',
'name': '',
'email': '',
'coin': 'btc'
'coin': 'bch'
};
$scope.onQrCodeScannedAddressBook = function(data, addressbookForm) {
@ -31,6 +31,10 @@ angular.module('copayApp.controllers').controller('addressbookAddController', fu
};
$scope.add = function(addressbook) {
if ($scope.addressbookEntry.coin == 'bch') {
var translated = bitcoinCashJsService.readAddress(addressbook.address);
addressbook.address = translated.legacy;
}
$timeout(function() {
addressbookService.add(addressbook, function(err, ab) {
if (err) {

View file

@ -1,6 +1,6 @@
'use strict';
angular.module('copayApp.controllers').controller('addressbookViewController', function($scope, $state, $timeout, lodash, addressbookService, popupService, $ionicHistory, platformInfo, gettextCatalog, configService) {
angular.module('copayApp.controllers').controller('addressbookViewController', function($scope, $state, $timeout, lodash, addressbookService, popupService, $ionicHistory, platformInfo, gettextCatalog, configService, bitcoinCashJsService) {
var config = configService.getSync();
var defaults = configService.getDefaults();
@ -24,8 +24,15 @@ angular.module('copayApp.controllers').controller('addressbookViewController', f
$ionicHistory.removeBackView();
$state.go('tabs.send');
$timeout(function() {
var to = '';
if ($scope.addressbookEntry.coin == 'bch') {
var a = 'bitcoincash:' + $scope.addressbookEntry.address;
to = bitcoinCashJsService.readAddress(a).legacy;
} else {
to = $scope.addressbookEntry.address;
}
$state.transitionTo('tabs.send.amount', {
toAddress: $scope.addressbookEntry.address,
toAddress: to,
toName: $scope.addressbookEntry.name,
toEmail: $scope.addressbookEntry.email,
coin: $scope.addressbookEntry.coin

View file

@ -63,11 +63,8 @@ angular.module('copayApp.controllers').controller('addressesController', functio
a.translatedAddresses = bitcoinCashJsService.translateAddresses(a.address);
});
var cashaddrDate = new Date(2018, 0, 15);
var currentDate = new Date();
$scope.addressType = {
type: currentDate >= cashaddrDate ? 'cashaddr' : 'legacy'
type: 'cashaddr'
};
$scope.showAddressTypes = true;
}
@ -141,7 +138,7 @@ angular.module('copayApp.controllers').controller('addressesController', functio
if ($scope.wallet.coin == 'bch') {
_addr[0].translatedAddresses = bitcoinCashJsService.translateAddresses(_addr[0].address);
}
$scope.noBalance = [_addr[0]].concat($scope.noBalance);
$scope.latestUnused = lodash.slice($scope.noBalance, 0, UNUSED_ADDRESS_LIMIT);
$scope.viewAll = {

View file

@ -3,9 +3,7 @@
angular.module('copayApp.controllers').controller('tabReceiveController', function($rootScope, $scope, $timeout, $log, $ionicModal, $state, $ionicHistory, $ionicPopover, storageService, platformInfo, walletService, profileService, configService, lodash, gettextCatalog, popupService, bwcError, bitcoinCashJsService) {
var listeners = [];
var cashaddrDate = new Date(2018, 0, 15);
var currentDate = new Date();
$scope.bchAddressType = currentDate >= cashaddrDate ? 'cashaddr' : 'legacy';
$scope.bchAddressType = 'cashaddr';
var bchAddresses = {};
$scope.isCordova = platformInfo.isCordova;

View file

@ -1,7 +1,7 @@
'use strict';
angular.module('copayApp.directives')
.directive('validAddress', ['$rootScope', 'bitcore', 'bitcoreCash',
function($rootScope, bitcore, bitcoreCash) {
.directive('validAddress', ['$rootScope', 'bitcore', 'bitcoreCash', 'bitcoinCashJsService',
function($rootScope, bitcore, bitcoreCash, bitcoinCashJsService) {
return {
require: 'ngModel',
link: function(scope, elem, attrs, ctrl) {
@ -15,6 +15,10 @@ angular.module('copayApp.directives')
var validator = function(value) {
if (value.indexOf('bitcoincash:') >= 0 || value[0] == 'C' || value[0] == 'H') {
value = bitcoinCashJsService.readAddress(value).legacy;
}
// Regular url
if (/^https?:\/\//.test(value)) {
ctrl.$setValidity('validAddress', true);

View file

@ -620,7 +620,7 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr
}
})
.state('tabs.addressbook.view', {
url: '/view/:address/:email/:name',
url: '/view/:address/:email/:name/:coin',
views: {
'tab-settings@tabs': {
templateUrl: 'views/addressbook.view.html',

View file

@ -1,6 +1,6 @@
'use strict';
angular.module('copayApp.services').factory('addressbookService', function($log, bitcore, bitcoreCash, storageService, lodash) {
angular.module('copayApp.services').factory('addressbookService', function($log, bitcore, bitcoreCash, storageService, lodash, bitcoinCashJsService) {
var root = {};
var getNetwork = function(address) {
@ -53,8 +53,8 @@ angular.module('copayApp.services').factory('addressbookService', function($log,
if (ab) ab = JSON.parse(ab);
ab = ab || {};
if (lodash.isArray(ab)) ab = {}; // No array
if (ab[entry.address]) return cb('Entry already exist');
ab[entry.address] = entry;
if (ab[entry.coin + entry.address]) return cb('Entry already exist');
ab[entry.coin + 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) {

View file

@ -36,7 +36,7 @@
<ion-list>
<ion-item ng-repeat="addrEntry in addressbook"
class="item-icon-right item-avatar"
ui-sref="tabs.addressbook.view({address:addrEntry.address, email: addrEntry.email, name: addrEntry.name})">
ui-sref="tabs.addressbook.view({address:addrEntry.address, email: addrEntry.email, name: addrEntry.name, coin: addrEntry.coin})">
<img src="img/contact-placeholder.svg" class="bg"/ ng-if="isChromeApp">
<gravatar name="{{addrEntry.name}}" width="50" email="{{addrEntry.email}}" ng-if="!isChromeApp"></gravatar>
<h2>{{addrEntry.name}}</h2>

View file

@ -22,7 +22,7 @@
<span class="address-book-field-label" translate>Email</span>
<span>{{addressbookEntry.email}}</span>
</div>
<div class="item item-text-wrap" copy-to-clipboard="addressbookEntry.address">
<div class="item item-text-wrap" copy-to-clipboard="(addressbookEntry.coin == 'bch' ? 'bitcoincash:' : '') + addressbookEntry.address">
<span class="address-book-field-label" translate>Address</span>
<span>{{addressbookEntry.address}}</span>
</div>