From 0993ab1553498262deb0efddf2f3fd6a06139863 Mon Sep 17 00:00:00 2001 From: lane-c-wagner Date: Wed, 24 Oct 2018 23:30:41 -0600 Subject: [PATCH 01/11] added opencap support --- src/js/controllers/tab-send.controller.js | 25 +++- src/js/services/opencapService.js | 153 ++++++++++++++++++++++ www/views/tab-send.html | 14 ++ 3 files changed, 191 insertions(+), 1 deletion(-) create mode 100644 src/js/services/opencapService.js diff --git a/src/js/controllers/tab-send.controller.js b/src/js/controllers/tab-send.controller.js index 03a9562e8..13cc84ed1 100644 --- a/src/js/controllers/tab-send.controller.js +++ b/src/js/controllers/tab-send.controller.js @@ -1,6 +1,6 @@ 'use strict'; -angular.module('copayApp.controllers').controller('tabSendController', function(bitcoinUriService, $scope, $log, $timeout, $ionicScrollDelegate, addressbookService, profileService, lodash, $state, walletService, platformInfo, sendFlowService, gettextCatalog, configService, $ionicPopup, $ionicNavBarDelegate, clipboardService, incomingDataService) { +angular.module('copayApp.controllers').controller('tabSendController', function(bitcoinUriService, $scope, $log, $timeout, $ionicScrollDelegate, addressbookService, profileService, lodash, $state, walletService, platformInfo, sendFlowService, gettextCatalog, configService, $ionicPopup, $ionicNavBarDelegate, clipboardService, incomingDataService, ionicToast, opencapService) { var clipboardHasAddress = false; var clipboardHasContent = false; var originalList; @@ -61,6 +61,29 @@ angular.module('copayApp.controllers').controller('tabSendController', function( }); }); + $scope.sendToAlias = function(alias) { + opencapService.get(alias) + .then(result => { + let msg = 'Address found! Address is secure'; + if(!result.dnssec){ + msg = 'Address found! Address doesn\'t have maximum DNS security'; + } + + let msgTime = 1000; + $scope.$apply(function () { + ionicToast.show(msg, 'bottom', false, msgTime); + }); + setTimeout(function(){ + $scope.findContact(result.address); + }, msgTime); + }) + .catch(status => { + $scope.$apply(function () { + ionicToast.show(status, 'bottom', false, 1500); + }); + }); + } + $scope.findContact = function(search) { if (!search || search.length < 1) { $scope.list = originalList; diff --git a/src/js/services/opencapService.js b/src/js/services/opencapService.js new file mode 100644 index 000000000..56ee1c7a4 --- /dev/null +++ b/src/js/services/opencapService.js @@ -0,0 +1,153 @@ +'use strict'; + +angular.module('copayApp.services').service('opencapService', function () { + + function getAddressCall(host, alias, dnssec) { + var callback = function () { + return fetch( + `https://${host}/v1/addresses?alias=${alias}`, + { + method: "GET" + }, + "application/json" + ); + }; + + return new Promise((resolve, reject) => { + callback() + .then(parseJSON) + .then(response => { + if (response.ok) { + if (typeof response.body === "undefined") { + return reject('Error contacting opencap server, no data') + } + + for (var i = 0; i < response.body.length; i++) { + if (response.body[i].address_type === "undefined") { + continue + } + if (response.body[i].address_type !== 200 && response.body[i].address_type !== 201) { + continue + } + if (response.body[i].address !== "undefined") { + return resolve({ address: response.body[i].address, dnssec }) + } + } + + return reject('Error contacting opencap server, no response'); + } + + return reject('Error contacting opencap server, bad response'); + }) + .catch(error => + reject(error.message) + ); + }); + } + + function getAliasData(domain, alias) { + var callback = function () { + return fetch( + `https://dns.google.com/resolve?name=_opencap._tcp.${domain}&type=SRV`, + { + method: "GET" + }, + "application/json" + ); + }; + + return callback() + .then(parseJSON) + .then(response => { + return new Promise((resolve, reject) => { + if (response.ok) { + if (typeof response.body.AD === "undefined") { + return reject('Error contacting google dns server, no dnnssec data') + } + let dnssec = response.body.AD; + + if (typeof response.body.Answer === "undefined") { + return reject('Error contacting google dns server, no srv data') + } + if (response.body.Answer.length < 1) { + return reject('Error contacting google dns server, not enough srv data') + } + + let record = response.body.Answer[0].data.split(' ') + if (record.length != 4) { + return reject('Error contacting google dns server, improper srv data') + } + + if (record[3].slice(-1) == '.') { + record[3] = record[3].substring(0, record[3].length - 1); + } + + return resolve({ target: record[3], alias, dnssec }) + } + + return reject('Error contacting google dns server, bad response'); + }); + }) + .then(args => + getAddressCall(args.target, args.alias, args.dnssec) + ) + .catch(function (error) { + return new Promise((resolve, reject) => { + reject(error) + }) + }) + } + + function parseJSON(response) { + return new Promise(resolve => + response.json().then(json => + resolve({ + status: response.status, + ok: response.ok, + body: json, + }) + ) + ); + } + + function validateUsername(username) { + return /^[a-z0-9._-]{1,25}$/.test(username); + } + + function validateDomain(username) { + return /^[a-z0-9.\-]+\.[a-z]{2,4}$/.test(username); + } + + function validateAlias(alias) { + let splitAlias = alias.split('$'); + if (splitAlias.length != 2) { + return { username: '', domain: '' } + } + let username = splitAlias[0]; + let domain = splitAlias[1]; + + if (!validateUsername(username)) { + return { username: '', domain: '' } + } + if (!validateDomain(domain)) { + return { username: '', domain: '' } + } + + return { username, domain } + } + + function get(alias) { + let aliasData = validateAlias(alias) + if (aliasData.username === '' || aliasData.domain === '') { + return new Promise((resolve, reject) => { + return reject('Invalid OpenCAP alias') + }) + } + + return getAliasData(aliasData.domain, alias) + } + + return { + get, + }; +}); \ No newline at end of file diff --git a/www/views/tab-send.html b/www/views/tab-send.html index 28be3f41b..0b370636c 100644 --- a/www/views/tab-send.html +++ b/www/views/tab-send.html @@ -63,6 +63,20 @@

{{fromWallet.name}}

+
+
+
+
+ +
+
+
+ +
+
From 26bb49d1cfaa4c2cdfc026ee965fdc462861e135 Mon Sep 17 00:00:00 2001 From: lane-c-wagner Date: Thu, 25 Oct 2018 08:22:19 -0600 Subject: [PATCH 02/11] fix btc bug --- src/js/controllers/tab-send.controller.js | 6 +++--- src/js/services/opencapService.js | 23 +++++++++++++++-------- www/views/tab-send.html | 2 +- 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/src/js/controllers/tab-send.controller.js b/src/js/controllers/tab-send.controller.js index 13cc84ed1..168824a36 100644 --- a/src/js/controllers/tab-send.controller.js +++ b/src/js/controllers/tab-send.controller.js @@ -62,11 +62,11 @@ angular.module('copayApp.controllers').controller('tabSendController', function( }); $scope.sendToAlias = function(alias) { - opencapService.get(alias) + opencapService.get(alias, $scope.fromWallet.coin) .then(result => { - let msg = 'Address found! Address is secure'; + let msg = `${$scope.fromWallet.coin} address found! Address is secure`; if(!result.dnssec){ - msg = 'Address found! Address doesn\'t have maximum DNS security'; + msg = `${$scope.fromWallet.coin} address found! Address doesn\'t have maximum DNS security`; } let msgTime = 1000; diff --git a/src/js/services/opencapService.js b/src/js/services/opencapService.js index 56ee1c7a4..7e76f72a0 100644 --- a/src/js/services/opencapService.js +++ b/src/js/services/opencapService.js @@ -2,7 +2,7 @@ angular.module('copayApp.services').service('opencapService', function () { - function getAddressCall(host, alias, dnssec) { + function getAddressCall(host, alias, dnssec, coin) { var callback = function () { return fetch( `https://${host}/v1/addresses?alias=${alias}`, @@ -26,11 +26,18 @@ angular.module('copayApp.services').service('opencapService', function () { if (response.body[i].address_type === "undefined") { continue } - if (response.body[i].address_type !== 200 && response.body[i].address_type !== 201) { + if (response.body[i].address === "undefined") { continue } - if (response.body[i].address !== "undefined") { - return resolve({ address: response.body[i].address, dnssec }) + if (coin == 'bch' && + (response.body[i].address_type == 200 || + response.body[i].address_type == 201)) { + return resolve({ address: response.body[i].address, dnssec }) + } + if (coin == 'btc' && + (response.body[i].address_type == 100 || + response.body[i].address_type == 101)) { + return resolve({ address: response.body[i].address, dnssec }) } } @@ -45,7 +52,7 @@ angular.module('copayApp.services').service('opencapService', function () { }); } - function getAliasData(domain, alias) { + function getAliasData(domain, alias, coin) { var callback = function () { return fetch( `https://dns.google.com/resolve?name=_opencap._tcp.${domain}&type=SRV`, @@ -89,7 +96,7 @@ angular.module('copayApp.services').service('opencapService', function () { }); }) .then(args => - getAddressCall(args.target, args.alias, args.dnssec) + getAddressCall(args.target, args.alias, args.dnssec, coin) ) .catch(function (error) { return new Promise((resolve, reject) => { @@ -136,7 +143,7 @@ angular.module('copayApp.services').service('opencapService', function () { return { username, domain } } - function get(alias) { + function get(alias, coin) { let aliasData = validateAlias(alias) if (aliasData.username === '' || aliasData.domain === '') { return new Promise((resolve, reject) => { @@ -144,7 +151,7 @@ angular.module('copayApp.services').service('opencapService', function () { }) } - return getAliasData(aliasData.domain, alias) + return getAliasData(aliasData.domain, alias, coin) } return { diff --git a/www/views/tab-send.html b/www/views/tab-send.html index 0b370636c..61199344f 100644 --- a/www/views/tab-send.html +++ b/www/views/tab-send.html @@ -64,7 +64,7 @@

{{fromWallet.name}}


-
+
Date: Wed, 31 Oct 2018 15:51:22 -0600 Subject: [PATCH 03/11] confirm to bitcoin-com style --- src/js/controllers/tab-send.controller.js | 28 ++-- src/js/services/opencap.service.js | 123 +++++++++++++++++ src/js/services/opencapService.js | 160 ---------------------- www/views/tab-send.html | 28 +++- 4 files changed, 163 insertions(+), 176 deletions(-) create mode 100644 src/js/services/opencap.service.js delete mode 100644 src/js/services/opencapService.js diff --git a/src/js/controllers/tab-send.controller.js b/src/js/controllers/tab-send.controller.js index 168824a36..55cd5a96f 100644 --- a/src/js/controllers/tab-send.controller.js +++ b/src/js/controllers/tab-send.controller.js @@ -61,26 +61,32 @@ angular.module('copayApp.controllers').controller('tabSendController', function( }); }); - $scope.sendToAlias = function(alias) { - opencapService.get(alias, $scope.fromWallet.coin) + $scope.sendToAlias = function(alias, coinType) { + let coin = coinType; + if (coin === ''){ + coin = $scope.fromWallet.coin + } + + opencapService.getAddress(alias, coin) .then(result => { - let msg = `${$scope.fromWallet.coin} address found! Address is secure`; + let msg = `${coin} address found! Address is secure`; if(!result.dnssec){ - msg = `${$scope.fromWallet.coin} address found! Address doesn\'t have maximum DNS security`; + msg = `${coin} address found! Address doesn\'t have maximum DNS security`; } let msgTime = 1000; - $scope.$apply(function () { - ionicToast.show(msg, 'bottom', false, msgTime); - }); + ionicToast.show(msg, 'bottom', false, msgTime); setTimeout(function(){ - $scope.findContact(result.address); + var params = sendFlowService.state.getClone(); + params.data = result.address; + params.coin = coin; + sendFlowService.start(params, function onError() { + return + }); }, msgTime); }) .catch(status => { - $scope.$apply(function () { - ionicToast.show(status, 'bottom', false, 1500); - }); + ionicToast.show(status, 'bottom', false, 1500); }); } diff --git a/src/js/services/opencap.service.js b/src/js/services/opencap.service.js new file mode 100644 index 000000000..f087be4ec --- /dev/null +++ b/src/js/services/opencap.service.js @@ -0,0 +1,123 @@ +'use strict'; + +(function() { + angular.module('bitcoincom.services').factory('opencapService', function($q, $http) { + function getAddress(alias, coin) { + let aliasData = validateAlias(alias); + if (aliasData.username === '' || aliasData.domain === '') { + return $q((resolve, reject) => { + return reject('Invalid OpenCAP alias'); + }); + } + + let deferred = $q.defer(); + $http + .get(`https://dns.google.com/resolve?name=_opencap._tcp.${aliasData.domain}&type=SRV`) + .then(function(response) { + deferred.resolve( + parseSRV(response.data) + .then(data => getAddresses(alias, coin, data.host, data.dnssec)) + .catch(function(error) { + return $q((resolve, reject) => { + reject(error); + }); + }) + ); + }) + .catch(function(response) { + deferred.reject('Couldn\'t find srv record for the provided domain'); + }); + return deferred.promise; + } + + var parseSRV = function(respData) { + return $q((resolve, reject) => { + let dnssec = respData.AD; + + if (typeof respData.Answer === 'undefined') { + return reject('Error contacting google dns server, no srv data'); + } + if (respData.Answer.length < 1) { + return reject('Error contacting google dns server, not enough srv data'); + } + + let record = respData.Answer[0].data.split(' '); + if (record.length != 4) { + return reject('Error contacting google dns server, improper srv data'); + } + + if (record[3].slice(-1) == '.') { + record[3] = record[3].substring(0, record[3].length - 1); + } + + return resolve({ host: record[3], dnssec }); + }); + }; + + var getAddresses = function(alias, coin, host, dnssec) { + let deferred = $q.defer(); + $http + .get(`https://${host}/v1/addresses?alias=${alias}`) + .then(function(response) { + deferred.resolve(parseAddresses(response.data, coin, dnssec).then()); + }) + .catch(function(response) { + deferred.reject('Address not found for the specified alias'); + }); + return deferred.promise; + }; + + var parseAddresses = function(respData, coin, dnssec) { + return $q((resolve, reject) => { + for (let i = 0; i < respData.length; i++) { + if (respData[i].address_type === 'undefined') { + continue; + } + if (respData[i].address === 'undefined') { + continue; + } + if (coin == 'bch' && (respData[i].address_type == 200 || respData[i].address_type == 201)) { + return resolve({ address: respData[i].address, dnssec }); + } + if (coin == 'btc' && (respData[i].address_type == 100 || respData[i].address_type == 101)) { + return resolve({ address: respData[i].address, dnssec }); + } + } + + return reject('Error contacting opencap server, no response'); + }); + }; + + function validateUsername(username) { + return /^[a-z0-9._-]{1,25}$/.test(username); + } + + function validateDomain(username) { + return /^[a-z0-9.\-]+\.[a-z]{2,4}$/.test(username); + } + + function validateAlias(alias) { + let splitAlias = alias.split('$'); + if (splitAlias.length != 2) { + return { username: '', domain: '' }; + } + let username = splitAlias[0]; + let domain = splitAlias[1]; + + if (!validateUsername(username)) { + return { username: '', domain: '' }; + } + if (!validateDomain(domain)) { + return { username: '', domain: '' }; + } + + return { username, domain }; + } + + var service = { + getAddress, + }; + + return service; + }); +})(); diff --git a/src/js/services/opencapService.js b/src/js/services/opencapService.js deleted file mode 100644 index 7e76f72a0..000000000 --- a/src/js/services/opencapService.js +++ /dev/null @@ -1,160 +0,0 @@ -'use strict'; - -angular.module('copayApp.services').service('opencapService', function () { - - function getAddressCall(host, alias, dnssec, coin) { - var callback = function () { - return fetch( - `https://${host}/v1/addresses?alias=${alias}`, - { - method: "GET" - }, - "application/json" - ); - }; - - return new Promise((resolve, reject) => { - callback() - .then(parseJSON) - .then(response => { - if (response.ok) { - if (typeof response.body === "undefined") { - return reject('Error contacting opencap server, no data') - } - - for (var i = 0; i < response.body.length; i++) { - if (response.body[i].address_type === "undefined") { - continue - } - if (response.body[i].address === "undefined") { - continue - } - if (coin == 'bch' && - (response.body[i].address_type == 200 || - response.body[i].address_type == 201)) { - return resolve({ address: response.body[i].address, dnssec }) - } - if (coin == 'btc' && - (response.body[i].address_type == 100 || - response.body[i].address_type == 101)) { - return resolve({ address: response.body[i].address, dnssec }) - } - } - - return reject('Error contacting opencap server, no response'); - } - - return reject('Error contacting opencap server, bad response'); - }) - .catch(error => - reject(error.message) - ); - }); - } - - function getAliasData(domain, alias, coin) { - var callback = function () { - return fetch( - `https://dns.google.com/resolve?name=_opencap._tcp.${domain}&type=SRV`, - { - method: "GET" - }, - "application/json" - ); - }; - - return callback() - .then(parseJSON) - .then(response => { - return new Promise((resolve, reject) => { - if (response.ok) { - if (typeof response.body.AD === "undefined") { - return reject('Error contacting google dns server, no dnnssec data') - } - let dnssec = response.body.AD; - - if (typeof response.body.Answer === "undefined") { - return reject('Error contacting google dns server, no srv data') - } - if (response.body.Answer.length < 1) { - return reject('Error contacting google dns server, not enough srv data') - } - - let record = response.body.Answer[0].data.split(' ') - if (record.length != 4) { - return reject('Error contacting google dns server, improper srv data') - } - - if (record[3].slice(-1) == '.') { - record[3] = record[3].substring(0, record[3].length - 1); - } - - return resolve({ target: record[3], alias, dnssec }) - } - - return reject('Error contacting google dns server, bad response'); - }); - }) - .then(args => - getAddressCall(args.target, args.alias, args.dnssec, coin) - ) - .catch(function (error) { - return new Promise((resolve, reject) => { - reject(error) - }) - }) - } - - function parseJSON(response) { - return new Promise(resolve => - response.json().then(json => - resolve({ - status: response.status, - ok: response.ok, - body: json, - }) - ) - ); - } - - function validateUsername(username) { - return /^[a-z0-9._-]{1,25}$/.test(username); - } - - function validateDomain(username) { - return /^[a-z0-9.\-]+\.[a-z]{2,4}$/.test(username); - } - - function validateAlias(alias) { - let splitAlias = alias.split('$'); - if (splitAlias.length != 2) { - return { username: '', domain: '' } - } - let username = splitAlias[0]; - let domain = splitAlias[1]; - - if (!validateUsername(username)) { - return { username: '', domain: '' } - } - if (!validateDomain(domain)) { - return { username: '', domain: '' } - } - - return { username, domain } - } - - function get(alias, coin) { - let aliasData = validateAlias(alias) - if (aliasData.username === '' || aliasData.domain === '') { - return new Promise((resolve, reject) => { - return reject('Invalid OpenCAP alias') - }) - } - - return getAliasData(aliasData.domain, alias, coin) - } - - return { - get, - }; -}); \ No newline at end of file diff --git a/www/views/tab-send.html b/www/views/tab-send.html index 61199344f..6258e72a0 100644 --- a/www/views/tab-send.html +++ b/www/views/tab-send.html @@ -65,15 +65,33 @@

{{fromWallet.name}}


-
-
+
+
-
- +
+
+
+
+
+ +
+
+
+ +
+
+
From 45bcde9e90eaf2e55a61168664486e1aa427d123 Mon Sep 17 00:00:00 2001 From: Lane Wagner Date: Sun, 2 Dec 2018 18:55:14 -0700 Subject: [PATCH 04/11] add cashaddr, use popover --- src/js/controllers/tab-send.controller.js | 58 +++++++++++++++-------- src/js/services/opencap.service.js | 27 +++++++---- www/templates/popoverOpencapSend.html | 21 ++++++++ www/views/tab-send.html | 36 +------------- 4 files changed, 77 insertions(+), 65 deletions(-) create mode 100644 www/templates/popoverOpencapSend.html diff --git a/src/js/controllers/tab-send.controller.js b/src/js/controllers/tab-send.controller.js index 55cd5a96f..4362bb6f8 100644 --- a/src/js/controllers/tab-send.controller.js +++ b/src/js/controllers/tab-send.controller.js @@ -1,6 +1,6 @@ 'use strict'; -angular.module('copayApp.controllers').controller('tabSendController', function(bitcoinUriService, $scope, $log, $timeout, $ionicScrollDelegate, addressbookService, profileService, lodash, $state, walletService, platformInfo, sendFlowService, gettextCatalog, configService, $ionicPopup, $ionicNavBarDelegate, clipboardService, incomingDataService, ionicToast, opencapService) { +angular.module('copayApp.controllers').controller('tabSendController', function(bitcoinUriService, $scope, $log, $timeout, $ionicScrollDelegate, $ionicPopover, addressbookService, profileService, lodash, $state, walletService, platformInfo, sendFlowService, gettextCatalog, configService, $ionicPopup, $ionicNavBarDelegate, clipboardService, incomingDataService, ionicToast, opencapService) { var clipboardHasAddress = false; var clipboardHasContent = false; var originalList; @@ -61,32 +61,46 @@ angular.module('copayApp.controllers').controller('tabSendController', function( }); }); - $scope.sendToAlias = function(alias, coinType) { - let coin = coinType; - if (coin === ''){ - coin = $scope.fromWallet.coin - } + $scope.closePopover = function() { + $scope.popover.hide(); + }; + + $scope.$on('$destroy', function() { + $scope.popover.remove(); + }); - opencapService.getAddress(alias, coin) + $scope.confirmOpenapAddress = function(address, coin){ + $scope.popover.remove(); + var params = sendFlowService.state.getClone(); + params.data = address; + params.coin = coin; + sendFlowService.start(params, function onError() { + return + }); + } + + $scope.resolveOpencapAlias = function(alias){ + opencapService.getAddress(alias) .then(result => { - let msg = `${coin} address found! Address is secure`; - if(!result.dnssec){ - msg = `${coin} address found! Address doesn\'t have maximum DNS security`; + if (typeof $scope.fromWallet !== 'undefined'){ + if ($scope.fromWallet.coin === 'bch'){ + result.addresses = {bch: result.addresses.bch}; + } + if ($scope.fromWallet.coin === 'btc'){ + result.addresses = {btc: result.addresses.btc}; + } } - let msgTime = 1000; - ionicToast.show(msg, 'bottom', false, msgTime); - setTimeout(function(){ - var params = sendFlowService.state.getClone(); - params.data = result.address; - params.coin = coin; - sendFlowService.start(params, function onError() { - return - }); - }, msgTime); + $scope.opencapAddresses = result.addresses; + $scope.opencapDnssec = result.dnssec; + $ionicPopover.fromTemplateUrl('templates/popoverOpencapSend.html', {scope: $scope}) + .then(function(popover) { + $scope.popover = popover; + popover.show(angular.element(document.querySelector('#search-input'))) + }); }) .catch(status => { - ionicToast.show(status, 'bottom', false, 1500); + // do nothing because they may have been typing }); } @@ -99,6 +113,8 @@ angular.module('copayApp.controllers').controller('tabSendController', function( return; } + $scope.resolveOpencapAlias(search); + var params = sendFlowService.state.getClone(); params.data = search; sendFlowService.start(params, function onError() { diff --git a/src/js/services/opencap.service.js b/src/js/services/opencap.service.js index f087be4ec..bf5af4eff 100644 --- a/src/js/services/opencap.service.js +++ b/src/js/services/opencap.service.js @@ -2,7 +2,7 @@ (function() { angular.module('bitcoincom.services').factory('opencapService', function($q, $http) { - function getAddress(alias, coin) { + function getAddress(alias) { let aliasData = validateAlias(alias); if (aliasData.username === '' || aliasData.domain === '') { return $q((resolve, reject) => { @@ -16,7 +16,7 @@ .then(function(response) { deferred.resolve( parseSRV(response.data) - .then(data => getAddresses(alias, coin, data.host, data.dnssec)) + .then(data => getAddresses(alias, data.host, data.dnssec)) .catch(function(error) { return $q((resolve, reject) => { reject(error); @@ -54,12 +54,12 @@ }); }; - var getAddresses = function(alias, coin, host, dnssec) { + var getAddresses = function(alias, host, dnssec) { let deferred = $q.defer(); $http .get(`https://${host}/v1/addresses?alias=${alias}`) .then(function(response) { - deferred.resolve(parseAddresses(response.data, coin, dnssec).then()); + deferred.resolve(parseAddresses(response.data, dnssec).then()); }) .catch(function(response) { deferred.reject('Address not found for the specified alias'); @@ -67,7 +67,8 @@ return deferred.promise; }; - var parseAddresses = function(respData, coin, dnssec) { + var parseAddresses = function(respData, dnssec) { + let addresses = {} return $q((resolve, reject) => { for (let i = 0; i < respData.length; i++) { if (respData[i].address_type === 'undefined') { @@ -76,15 +77,21 @@ if (respData[i].address === 'undefined') { continue; } - if (coin == 'bch' && (respData[i].address_type == 200 || respData[i].address_type == 201)) { - return resolve({ address: respData[i].address, dnssec }); + // Take the last BCH address we hit, shouldn't matter which one + if (respData[i].address_type == 200 || respData[i].address_type == 201 || respData[i].address_type == 202) { + addresses.bch = respData[i].address; } - if (coin == 'btc' && (respData[i].address_type == 100 || respData[i].address_type == 101)) { - return resolve({ address: respData[i].address, dnssec }); + // Take the last BTC address we hit, shouldn't matter which one + if (respData[i].address_type == 100 || respData[i].address_type == 101) { + addresses.btc = respData[i].address; } } - return reject('Error contacting opencap server, no response'); + if (addresses.btc === 'undefined' && addresses.btc === 'undefined'){ + return reject('Error contacting opencap server, no response'); + } + + return resolve({addresses, dnssec}); }); }; diff --git a/www/templates/popoverOpencapSend.html b/www/templates/popoverOpencapSend.html new file mode 100644 index 000000000..9d6d2482a --- /dev/null +++ b/www/templates/popoverOpencapSend.html @@ -0,0 +1,21 @@ + +
+
+ Alias found! +
+
+
+ {{opencapAddresses.bch}} + +
+
+ {{opencapAddresses.btc}} + +
+ + DNSSEC not used + +
+
+
+ \ No newline at end of file diff --git a/www/views/tab-send.html b/www/views/tab-send.html index 6258e72a0..fb37baa12 100644 --- a/www/views/tab-send.html +++ b/www/views/tab-send.html @@ -33,9 +33,9 @@

{{fromWallet.name}}

- + ng-focus="searchInFocus()" ng-blur="searchBlurred()" id="search-input">
@@ -63,38 +63,6 @@

{{fromWallet.name}}

-
-
-
-
- -
-
-
- -
-
-
-
-
- -
-
-
- -
-
- -
-
From 7749479db279a5c5214734d4f739b470329485c0 Mon Sep 17 00:00:00 2001 From: lane-c-wagner Date: Sun, 6 Jan 2019 22:48:34 -0700 Subject: [PATCH 05/11] no arrows --- src/js/controllers/tab-send.controller.js | 4 ++-- src/js/services/opencap.service.js | 14 ++++++++------ 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/js/controllers/tab-send.controller.js b/src/js/controllers/tab-send.controller.js index 4362bb6f8..4ebf75339 100644 --- a/src/js/controllers/tab-send.controller.js +++ b/src/js/controllers/tab-send.controller.js @@ -81,7 +81,7 @@ angular.module('copayApp.controllers').controller('tabSendController', function( $scope.resolveOpencapAlias = function(alias){ opencapService.getAddress(alias) - .then(result => { + .then(function(result) { if (typeof $scope.fromWallet !== 'undefined'){ if ($scope.fromWallet.coin === 'bch'){ result.addresses = {bch: result.addresses.bch}; @@ -99,7 +99,7 @@ angular.module('copayApp.controllers').controller('tabSendController', function( popover.show(angular.element(document.querySelector('#search-input'))) }); }) - .catch(status => { + .catch(function(status) { // do nothing because they may have been typing }); } diff --git a/src/js/services/opencap.service.js b/src/js/services/opencap.service.js index bf5af4eff..dbe399c99 100644 --- a/src/js/services/opencap.service.js +++ b/src/js/services/opencap.service.js @@ -5,7 +5,7 @@ function getAddress(alias) { let aliasData = validateAlias(alias); if (aliasData.username === '' || aliasData.domain === '') { - return $q((resolve, reject) => { + return $q(function(resolve, reject) { return reject('Invalid OpenCAP alias'); }); } @@ -16,10 +16,12 @@ .then(function(response) { deferred.resolve( parseSRV(response.data) - .then(data => getAddresses(alias, data.host, data.dnssec)) + .then(function(data){ + return getAddresses(alias, data.host, data.dnssec) + }) .catch(function(error) { - return $q((resolve, reject) => { - reject(error); + return $q(function(resolve, reject) { + return reject(error); }); }) ); @@ -31,7 +33,7 @@ } var parseSRV = function(respData) { - return $q((resolve, reject) => { + return $q(function(resolve, reject) { let dnssec = respData.AD; if (typeof respData.Answer === 'undefined') { @@ -69,7 +71,7 @@ var parseAddresses = function(respData, dnssec) { let addresses = {} - return $q((resolve, reject) => { + return $q(function(resolve, reject) { for (let i = 0; i < respData.length; i++) { if (respData[i].address_type === 'undefined') { continue; From cd580cde4a8d53bbfbb665f6dc54fa5cf86084ec Mon Sep 17 00:00:00 2001 From: lane-c-wagner Date: Sun, 6 Jan 2019 22:55:15 -0700 Subject: [PATCH 06/11] no var functions --- src/js/controllers/tab-send.controller.js | 2 +- src/js/services/opencap.service.js | 24 +++++++++++------------ 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/js/controllers/tab-send.controller.js b/src/js/controllers/tab-send.controller.js index 4ebf75339..19fb849b9 100644 --- a/src/js/controllers/tab-send.controller.js +++ b/src/js/controllers/tab-send.controller.js @@ -94,7 +94,7 @@ angular.module('copayApp.controllers').controller('tabSendController', function( $scope.opencapAddresses = result.addresses; $scope.opencapDnssec = result.dnssec; $ionicPopover.fromTemplateUrl('templates/popoverOpencapSend.html', {scope: $scope}) - .then(function(popover) { + .then(function onThen(popover) { $scope.popover = popover; popover.show(angular.element(document.querySelector('#search-input'))) }); diff --git a/src/js/services/opencap.service.js b/src/js/services/opencap.service.js index dbe399c99..bd5a82419 100644 --- a/src/js/services/opencap.service.js +++ b/src/js/services/opencap.service.js @@ -5,7 +5,7 @@ function getAddress(alias) { let aliasData = validateAlias(alias); if (aliasData.username === '' || aliasData.domain === '') { - return $q(function(resolve, reject) { + return $q(function onQ(resolve, reject) { return reject('Invalid OpenCAP alias'); }); } @@ -13,14 +13,14 @@ let deferred = $q.defer(); $http .get(`https://dns.google.com/resolve?name=_opencap._tcp.${aliasData.domain}&type=SRV`) - .then(function(response) { + .then(function onThen(response) { deferred.resolve( parseSRV(response.data) - .then(function(data){ + .then(function onThen(data){ return getAddresses(alias, data.host, data.dnssec) }) - .catch(function(error) { - return $q(function(resolve, reject) { + .catch(function onCatch(error) { + return $q(function onQ(resolve, reject) { return reject(error); }); }) @@ -32,8 +32,8 @@ return deferred.promise; } - var parseSRV = function(respData) { - return $q(function(resolve, reject) { + function parseSRV(respData) { + return $q(function onQ(resolve, reject) { let dnssec = respData.AD; if (typeof respData.Answer === 'undefined') { @@ -56,22 +56,22 @@ }); }; - var getAddresses = function(alias, host, dnssec) { + function getAddresses(alias, host, dnssec) { let deferred = $q.defer(); $http .get(`https://${host}/v1/addresses?alias=${alias}`) - .then(function(response) { + .then(function onThen(response) { deferred.resolve(parseAddresses(response.data, dnssec).then()); }) - .catch(function(response) { + .catch(function onCatch(response) { deferred.reject('Address not found for the specified alias'); }); return deferred.promise; }; - var parseAddresses = function(respData, dnssec) { + function parseAddresses(respData, dnssec) { let addresses = {} - return $q(function(resolve, reject) { + return $q(function onQ(resolve, reject) { for (let i = 0; i < respData.length; i++) { if (respData[i].address_type === 'undefined') { continue; From 1d9e897ef2727de842c50633f9be5b55e539683f Mon Sep 17 00:00:00 2001 From: lane-c-wagner Date: Sun, 6 Jan 2019 23:03:25 -0700 Subject: [PATCH 07/11] missed one --- src/js/services/opencap.service.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/js/services/opencap.service.js b/src/js/services/opencap.service.js index bd5a82419..b5b5797bb 100644 --- a/src/js/services/opencap.service.js +++ b/src/js/services/opencap.service.js @@ -26,7 +26,7 @@ }) ); }) - .catch(function(response) { + .catch(function onCatch(response) { deferred.reject('Couldn\'t find srv record for the provided domain'); }); return deferred.promise; From 091990b60038963100e300640e8e1158230ea443 Mon Sep 17 00:00:00 2001 From: lane-c-wagner Date: Wed, 13 Feb 2019 10:24:25 -0700 Subject: [PATCH 08/11] merge latest conflicts --- src/js/controllers/tab-send.controller.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/js/controllers/tab-send.controller.js b/src/js/controllers/tab-send.controller.js index e9f96457b..aa65637c0 100644 --- a/src/js/controllers/tab-send.controller.js +++ b/src/js/controllers/tab-send.controller.js @@ -1,6 +1,6 @@ 'use strict'; -angular.module('copayApp.controllers').controller('tabSendController', function(bitcoinUriService, externalLinkService, $scope, $log, $timeout, $ionicScrollDelegate, addressbookService, profileService, lodash, $state, walletService, platformInfo, sendFlowService, gettextCatalog, configService, $ionicPopup, $ionicNavBarDelegate, clipboardService, incomingDataService) { +angular.module('copayApp.controllers').controller('tabSendController', function(bitcoinUriService, externalLinkService, $scope, $log, $timeout, $ionicScrollDelegate, addressbookService, profileService, lodash, $state, walletService, platformInfo, sendFlowService, gettextCatalog, configService, $ionicPopup, $ionicNavBarDelegate, clipboardService, incomingDataService, ionicToast, opencapService) { var clipboardHasAddress = false; var clipboardHasContent = false; var originalList; From 16aa33e2d402086c825251ad17a3ba39ff394ecf Mon Sep 17 00:00:00 2001 From: Angel Mortega Date: Thu, 28 Mar 2019 16:32:33 +0900 Subject: [PATCH 09/11] Set package dependencies versions to fixed versions. --- app-template/package-template.json | 74 +++++++++++++++--------------- 1 file changed, 37 insertions(+), 37 deletions(-) diff --git a/app-template/package-template.json b/app-template/package-template.json index 7f912f96f..2edad2b8f 100644 --- a/app-template/package-template.json +++ b/app-template/package-template.json @@ -53,39 +53,39 @@ "npm": "3" }, "dependencies": { - "adm-zip": "^0.4.7", + "adm-zip": "0.4.13", "angular": "1.4.6", "angular-mocks": "1.4.10", - "bezier-easing": "^2.0.3", + "bezier-easing": "2.1.0", "bhttp": "1.2.1", - "bitauth": "^0.2.1", + "bitauth": "0.2.1", "bitcore-wallet-client": "https://github.com/Bitcoin-com/bitcore-wallet-client.git", - "bower": "^1.7.9", - "cordova-custom-config": "^3.0.5", + "bower": "1.8.8", + "cordova-custom-config": "3.0.14", "cordova-plugin-qrscanner-no-android": "https://github.com/Bitcoin-com/cordova-plugin-qrscanner-no-android.git", - "cordova-plugin-vibration": "^3.0.1", - "cordova-plugin-camera-preview": "^0.10.0", - "coveralls": "^2.11.9", - "express": "^4.11.2", + "cordova-plugin-vibration": "3.0.1", + "cordova-plugin-camera-preview": "0.10.0", + "coveralls": "2.13.3", + "express": "4.16.4", "fs": "0.0.2", - "fs-extra": "^0.30.0", - "grunt-angular-gettext": "^2.2.3", - "grunt-browserify": "^5.0.0", - "grunt-cli": "^1.2.0", - "grunt-curl": "^2.4.1", - "grunt-zip": "^0.17.1", - "grunt-contrib-compress": "^1.3.0", - "grunt-contrib-concat": "^1.0.1", - "grunt-contrib-copy": "^1.0.0", - "grunt-contrib-uglify": "^2.0.0", - "grunt-contrib-watch": "^1.0.0", - "grunt-exec": "^1.0.0", - "grunt-nw-builder": "^2.0.3", - "grunt-sass": "^1.2.0", - "load-grunt-tasks": "^3.5.0", - "shelljs": "^0.3.0", - "android-versions": "^1.2.1", - "bitcoincashjs-fork": "^1.0.3" + "fs-extra": "0.30.0", + "grunt-angular-gettext": "2.4.1", + "grunt-browserify": "5.3.0", + "grunt-cli": "1.3.2", + "grunt-curl": "2.5.1", + "grunt-zip": "0.17.1", + "grunt-contrib-compress": "1.4.3", + "grunt-contrib-concat": "1.0.1", + "grunt-contrib-copy": "1.0.0", + "grunt-contrib-uglify": "2.3.0", + "grunt-contrib-watch": "1.1.0", + "grunt-exec": "1.0.1", + "grunt-nw-builder": "2.0.3", + "grunt-sass": "1.2.1", + "load-grunt-tasks": "3.5.2", + "shelljs": "0.3.0", + "android-versions": "1.4.0", + "bitcoincashjs-fork": "1.0.3" }, "scripts": { "apply:bitcoincom": "npm i fs-extra && cd app-template && node apply.js bitcoincom && npm i && cordova prepare && cd ../ && ./fix-asn1.sh", @@ -137,16 +137,16 @@ "watch": "grunt watch" }, "devDependencies": { - "cordova": "^6.4.0", - "grunt": "^1.0.1", - "ionic": "^3.6.0", - "jasmine-core": "^3.1.0", - "karma": "^2.0.2", - "karma-chrome-launcher": "^2.2.0", - "karma-jasmine": "^1.1.2", - "trash-cli": "^1.4.0", - "lodash": "^4.17.4", - "pre-commit": "^1.1.3" + "cordova": "6.5.0", + "grunt": "1.0.4", + "ionic": "3.20.1", + "jasmine-core": "3.3.0", + "karma": "2.0.5", + "karma-chrome-launcher": "2.2.0", + "karma-jasmine": "1.1.2", + "trash-cli": "1.4.0", + "lodash": "4.17.11", + "pre-commit": "1.2.2" }, "pre-commit": "unstage-package" } From ea19d109e96baf39f6ba4f26046e477b14fd6026 Mon Sep 17 00:00:00 2001 From: Angel Mortega Date: Fri, 29 Mar 2019 08:58:51 +0900 Subject: [PATCH 10/11] Revert "Set package dependencies versions to fixed versions." This reverts commit 16aa33e2d402086c825251ad17a3ba39ff394ecf. --- app-template/package-template.json | 74 +++++++++++++++--------------- 1 file changed, 37 insertions(+), 37 deletions(-) diff --git a/app-template/package-template.json b/app-template/package-template.json index 2edad2b8f..7f912f96f 100644 --- a/app-template/package-template.json +++ b/app-template/package-template.json @@ -53,39 +53,39 @@ "npm": "3" }, "dependencies": { - "adm-zip": "0.4.13", + "adm-zip": "^0.4.7", "angular": "1.4.6", "angular-mocks": "1.4.10", - "bezier-easing": "2.1.0", + "bezier-easing": "^2.0.3", "bhttp": "1.2.1", - "bitauth": "0.2.1", + "bitauth": "^0.2.1", "bitcore-wallet-client": "https://github.com/Bitcoin-com/bitcore-wallet-client.git", - "bower": "1.8.8", - "cordova-custom-config": "3.0.14", + "bower": "^1.7.9", + "cordova-custom-config": "^3.0.5", "cordova-plugin-qrscanner-no-android": "https://github.com/Bitcoin-com/cordova-plugin-qrscanner-no-android.git", - "cordova-plugin-vibration": "3.0.1", - "cordova-plugin-camera-preview": "0.10.0", - "coveralls": "2.13.3", - "express": "4.16.4", + "cordova-plugin-vibration": "^3.0.1", + "cordova-plugin-camera-preview": "^0.10.0", + "coveralls": "^2.11.9", + "express": "^4.11.2", "fs": "0.0.2", - "fs-extra": "0.30.0", - "grunt-angular-gettext": "2.4.1", - "grunt-browserify": "5.3.0", - "grunt-cli": "1.3.2", - "grunt-curl": "2.5.1", - "grunt-zip": "0.17.1", - "grunt-contrib-compress": "1.4.3", - "grunt-contrib-concat": "1.0.1", - "grunt-contrib-copy": "1.0.0", - "grunt-contrib-uglify": "2.3.0", - "grunt-contrib-watch": "1.1.0", - "grunt-exec": "1.0.1", - "grunt-nw-builder": "2.0.3", - "grunt-sass": "1.2.1", - "load-grunt-tasks": "3.5.2", - "shelljs": "0.3.0", - "android-versions": "1.4.0", - "bitcoincashjs-fork": "1.0.3" + "fs-extra": "^0.30.0", + "grunt-angular-gettext": "^2.2.3", + "grunt-browserify": "^5.0.0", + "grunt-cli": "^1.2.0", + "grunt-curl": "^2.4.1", + "grunt-zip": "^0.17.1", + "grunt-contrib-compress": "^1.3.0", + "grunt-contrib-concat": "^1.0.1", + "grunt-contrib-copy": "^1.0.0", + "grunt-contrib-uglify": "^2.0.0", + "grunt-contrib-watch": "^1.0.0", + "grunt-exec": "^1.0.0", + "grunt-nw-builder": "^2.0.3", + "grunt-sass": "^1.2.0", + "load-grunt-tasks": "^3.5.0", + "shelljs": "^0.3.0", + "android-versions": "^1.2.1", + "bitcoincashjs-fork": "^1.0.3" }, "scripts": { "apply:bitcoincom": "npm i fs-extra && cd app-template && node apply.js bitcoincom && npm i && cordova prepare && cd ../ && ./fix-asn1.sh", @@ -137,16 +137,16 @@ "watch": "grunt watch" }, "devDependencies": { - "cordova": "6.5.0", - "grunt": "1.0.4", - "ionic": "3.20.1", - "jasmine-core": "3.3.0", - "karma": "2.0.5", - "karma-chrome-launcher": "2.2.0", - "karma-jasmine": "1.1.2", - "trash-cli": "1.4.0", - "lodash": "4.17.11", - "pre-commit": "1.2.2" + "cordova": "^6.4.0", + "grunt": "^1.0.1", + "ionic": "^3.6.0", + "jasmine-core": "^3.1.0", + "karma": "^2.0.2", + "karma-chrome-launcher": "^2.2.0", + "karma-jasmine": "^1.1.2", + "trash-cli": "^1.4.0", + "lodash": "^4.17.4", + "pre-commit": "^1.1.3" }, "pre-commit": "unstage-package" } From 6122cfa48aa273fec17e48ce49502376d3f8e167 Mon Sep 17 00:00:00 2001 From: lane-c-wagner Date: Fri, 29 Mar 2019 19:56:45 -0600 Subject: [PATCH 11/11] linting --- src/js/controllers/tab-send.controller.js | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/src/js/controllers/tab-send.controller.js b/src/js/controllers/tab-send.controller.js index 2430e3eb2..12da93cb8 100644 --- a/src/js/controllers/tab-send.controller.js +++ b/src/js/controllers/tab-send.controller.js @@ -24,17 +24,13 @@ angular.module('copayApp.controllers').controller('tabSendController', function , ionicToast , opencapService ) { + var clipboardHasAddress = false; var clipboardHasContent = false; var originalList; - var isBuyBitcoinAllowed = false; $scope.displayBalanceAsFiat = true; $scope.walletSelectorTitleForce = true; - moonPayService.getCountryByIpAddress().then(function onGetCountryByIpAddress(user) { - isBuyBitcoinAllowed = user.isAllowed; - }); - $scope.addContact = function () { $state.go('tabs.send.addressbook'); }; @@ -280,12 +276,8 @@ angular.module('copayApp.controllers').controller('tabSendController', function }; $scope.buyBitcoin = function () { - if (isBuyBitcoinAllowed) { - moonPayService.start(); - } else { - var os = platformInfo.isAndroid ? 'android' : platformInfo.isIOS ? 'ios' : 'desktop'; - externalLinkService.open('https://purchase.bitcoin.com/?utm_source=WalletApp&utm_medium=' + os); - } + var os = platformInfo.isAndroid ? 'android' : platformInfo.isIOS ? 'ios' : 'desktop'; + externalLinkService.open('https://purchase.bitcoin.com/?utm_source=WalletApp&utm_medium=' + os); }; $scope.$on("$ionicView.beforeEnter", function (event, data) {