got address book working with bitcoin cash addresses
This commit is contained in:
parent
1d3da45e32
commit
1c8990fc08
10 changed files with 41 additions and 23 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
'use strict';
|
'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;
|
var contacts;
|
||||||
|
|
||||||
|
|
@ -15,10 +15,18 @@ angular.module('copayApp.controllers').controller('addressbookListController', f
|
||||||
|
|
||||||
contacts = [];
|
contacts = [];
|
||||||
lodash.each(ab, function(v, k) {
|
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({
|
contacts.push({
|
||||||
name: lodash.isObject(v) ? v.name : v,
|
name: lodash.isObject(v) ? v.name : v,
|
||||||
address: k,
|
address: a,
|
||||||
email: lodash.isObject(v) ? v.email : null
|
email: lodash.isObject(v) ? v.email : null,
|
||||||
|
coin: c
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
'use strict';
|
'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 config = configService.getSync();
|
||||||
var defaults = configService.getDefaults();
|
var defaults = configService.getDefaults();
|
||||||
|
|
@ -14,7 +14,7 @@ angular.module('copayApp.controllers').controller('addressbookAddController', fu
|
||||||
'address': $stateParams.addressbookEntry || '',
|
'address': $stateParams.addressbookEntry || '',
|
||||||
'name': '',
|
'name': '',
|
||||||
'email': '',
|
'email': '',
|
||||||
'coin': 'btc'
|
'coin': 'bch'
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.onQrCodeScannedAddressBook = function(data, addressbookForm) {
|
$scope.onQrCodeScannedAddressBook = function(data, addressbookForm) {
|
||||||
|
|
@ -31,6 +31,10 @@ angular.module('copayApp.controllers').controller('addressbookAddController', fu
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.add = function(addressbook) {
|
$scope.add = function(addressbook) {
|
||||||
|
if ($scope.addressbookEntry.coin == 'bch') {
|
||||||
|
var translated = bitcoinCashJsService.readAddress(addressbook.address);
|
||||||
|
addressbook.address = translated.legacy;
|
||||||
|
}
|
||||||
$timeout(function() {
|
$timeout(function() {
|
||||||
addressbookService.add(addressbook, function(err, ab) {
|
addressbookService.add(addressbook, function(err, ab) {
|
||||||
if (err) {
|
if (err) {
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
'use strict';
|
'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 config = configService.getSync();
|
||||||
var defaults = configService.getDefaults();
|
var defaults = configService.getDefaults();
|
||||||
|
|
@ -24,8 +24,15 @@ angular.module('copayApp.controllers').controller('addressbookViewController', f
|
||||||
$ionicHistory.removeBackView();
|
$ionicHistory.removeBackView();
|
||||||
$state.go('tabs.send');
|
$state.go('tabs.send');
|
||||||
$timeout(function() {
|
$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', {
|
$state.transitionTo('tabs.send.amount', {
|
||||||
toAddress: $scope.addressbookEntry.address,
|
toAddress: to,
|
||||||
toName: $scope.addressbookEntry.name,
|
toName: $scope.addressbookEntry.name,
|
||||||
toEmail: $scope.addressbookEntry.email,
|
toEmail: $scope.addressbookEntry.email,
|
||||||
coin: $scope.addressbookEntry.coin
|
coin: $scope.addressbookEntry.coin
|
||||||
|
|
|
||||||
|
|
@ -63,11 +63,8 @@ angular.module('copayApp.controllers').controller('addressesController', functio
|
||||||
a.translatedAddresses = bitcoinCashJsService.translateAddresses(a.address);
|
a.translatedAddresses = bitcoinCashJsService.translateAddresses(a.address);
|
||||||
});
|
});
|
||||||
|
|
||||||
var cashaddrDate = new Date(2018, 0, 15);
|
|
||||||
var currentDate = new Date();
|
|
||||||
|
|
||||||
$scope.addressType = {
|
$scope.addressType = {
|
||||||
type: currentDate >= cashaddrDate ? 'cashaddr' : 'legacy'
|
type: 'cashaddr'
|
||||||
};
|
};
|
||||||
$scope.showAddressTypes = true;
|
$scope.showAddressTypes = true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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) {
|
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 listeners = [];
|
||||||
var cashaddrDate = new Date(2018, 0, 15);
|
$scope.bchAddressType = 'cashaddr';
|
||||||
var currentDate = new Date();
|
|
||||||
$scope.bchAddressType = currentDate >= cashaddrDate ? 'cashaddr' : 'legacy';
|
|
||||||
var bchAddresses = {};
|
var bchAddresses = {};
|
||||||
|
|
||||||
$scope.isCordova = platformInfo.isCordova;
|
$scope.isCordova = platformInfo.isCordova;
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
angular.module('copayApp.directives')
|
angular.module('copayApp.directives')
|
||||||
.directive('validAddress', ['$rootScope', 'bitcore', 'bitcoreCash',
|
.directive('validAddress', ['$rootScope', 'bitcore', 'bitcoreCash', 'bitcoinCashJsService',
|
||||||
function($rootScope, bitcore, bitcoreCash) {
|
function($rootScope, bitcore, bitcoreCash, bitcoinCashJsService) {
|
||||||
return {
|
return {
|
||||||
require: 'ngModel',
|
require: 'ngModel',
|
||||||
link: function(scope, elem, attrs, ctrl) {
|
link: function(scope, elem, attrs, ctrl) {
|
||||||
|
|
@ -15,6 +15,10 @@ angular.module('copayApp.directives')
|
||||||
|
|
||||||
var validator = function(value) {
|
var validator = function(value) {
|
||||||
|
|
||||||
|
if (value.indexOf('bitcoincash:') >= 0 || value[0] == 'C' || value[0] == 'H') {
|
||||||
|
value = bitcoinCashJsService.readAddress(value).legacy;
|
||||||
|
}
|
||||||
|
|
||||||
// Regular url
|
// Regular url
|
||||||
if (/^https?:\/\//.test(value)) {
|
if (/^https?:\/\//.test(value)) {
|
||||||
ctrl.$setValidity('validAddress', true);
|
ctrl.$setValidity('validAddress', true);
|
||||||
|
|
|
||||||
|
|
@ -620,7 +620,7 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.state('tabs.addressbook.view', {
|
.state('tabs.addressbook.view', {
|
||||||
url: '/view/:address/:email/:name',
|
url: '/view/:address/:email/:name/:coin',
|
||||||
views: {
|
views: {
|
||||||
'tab-settings@tabs': {
|
'tab-settings@tabs': {
|
||||||
templateUrl: 'views/addressbook.view.html',
|
templateUrl: 'views/addressbook.view.html',
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
'use strict';
|
'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 root = {};
|
||||||
|
|
||||||
var getNetwork = function(address) {
|
var getNetwork = function(address) {
|
||||||
|
|
@ -53,8 +53,8 @@ angular.module('copayApp.services').factory('addressbookService', function($log,
|
||||||
if (ab) ab = JSON.parse(ab);
|
if (ab) ab = JSON.parse(ab);
|
||||||
ab = ab || {};
|
ab = ab || {};
|
||||||
if (lodash.isArray(ab)) ab = {}; // No array
|
if (lodash.isArray(ab)) ab = {}; // No array
|
||||||
if (ab[entry.address]) return cb('Entry already exist');
|
if (ab[entry.coin + entry.address]) return cb('Entry already exist');
|
||||||
ab[entry.address] = entry;
|
ab[entry.coin + entry.address] = entry;
|
||||||
storageService.setAddressbook(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) {
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,7 @@
|
||||||
<ion-list>
|
<ion-list>
|
||||||
<ion-item ng-repeat="addrEntry in addressbook"
|
<ion-item ng-repeat="addrEntry in addressbook"
|
||||||
class="item-icon-right item-avatar"
|
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">
|
<img src="img/contact-placeholder.svg" class="bg"/ ng-if="isChromeApp">
|
||||||
<gravatar name="{{addrEntry.name}}" width="50" email="{{addrEntry.email}}" ng-if="!isChromeApp"></gravatar>
|
<gravatar name="{{addrEntry.name}}" width="50" email="{{addrEntry.email}}" ng-if="!isChromeApp"></gravatar>
|
||||||
<h2>{{addrEntry.name}}</h2>
|
<h2>{{addrEntry.name}}</h2>
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@
|
||||||
<span class="address-book-field-label" translate>Email</span>
|
<span class="address-book-field-label" translate>Email</span>
|
||||||
<span>{{addressbookEntry.email}}</span>
|
<span>{{addressbookEntry.email}}</span>
|
||||||
</div>
|
</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 class="address-book-field-label" translate>Address</span>
|
||||||
<span>{{addressbookEntry.address}}</span>
|
<span>{{addressbookEntry.address}}</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue