-
Notifications
You must be signed in to change notification settings - Fork 232
OpenCAP sending feature added #409
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 5 commits
0993ab1
26bb49d
741fc13
c906747
45bcde9
31aa175
7749479
cd580cd
1d9e897
b179c33
091990b
16aa33e
ea19d10
adbe7b5
6122cfa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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, $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,6 +61,49 @@ angular.module('copayApp.controllers').controller('tabSendController', function( | |
| }); | ||
| }); | ||
|
|
||
| $scope.closePopover = function() { | ||
| $scope.popover.hide(); | ||
| }; | ||
|
|
||
| $scope.$on('$destroy', function() { | ||
| $scope.popover.remove(); | ||
| }); | ||
|
|
||
| $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 => { | ||
| 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}; | ||
| } | ||
| } | ||
|
|
||
| $scope.opencapAddresses = result.addresses; | ||
| $scope.opencapDnssec = result.dnssec; | ||
| $ionicPopover.fromTemplateUrl('templates/popoverOpencapSend.html', {scope: $scope}) | ||
| .then(function(popover) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now : |
||
| $scope.popover = popover; | ||
| popover.show(angular.element(document.querySelector('#search-input'))) | ||
| }); | ||
| }) | ||
| .catch(status => { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now : |
||
| // do nothing because they may have been typing | ||
| }); | ||
| } | ||
|
|
||
| $scope.findContact = function(search) { | ||
| if (!search || search.length < 1) { | ||
| $scope.list = originalList; | ||
|
|
@@ -70,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() { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,130 @@ | ||
| 'use strict'; | ||
|
|
||
| (function() { | ||
| angular.module('bitcoincom.services').factory('opencapService', function($q, $http) { | ||
| function getAddress(alias) { | ||
| let aliasData = validateAlias(alias); | ||
| if (aliasData.username === '' || aliasData.domain === '') { | ||
| return $q((resolve, reject) => { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now : |
||
| 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) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now : |
||
| deferred.resolve( | ||
| parseSRV(response.data) | ||
| .then(data => getAddresses(alias, data.host, data.dnssec)) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now : |
||
| .catch(function(error) { | ||
| return $q((resolve, reject) => { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now : |
||
| reject(error); | ||
| }); | ||
| }) | ||
| ); | ||
| }) | ||
| .catch(function(response) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now : |
||
| deferred.reject('Couldn\'t find srv record for the provided domain'); | ||
| }); | ||
| return deferred.promise; | ||
| } | ||
|
|
||
| var parseSRV = function(respData) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now : |
||
| return $q((resolve, reject) => { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now : |
||
| 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, host, dnssec) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now : |
||
| let deferred = $q.defer(); | ||
| $http | ||
| .get(`https://${host}/v1/addresses?alias=${alias}`) | ||
| .then(function(response) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now : |
||
| deferred.resolve(parseAddresses(response.data, dnssec).then()); | ||
| }) | ||
| .catch(function(response) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now : |
||
| deferred.reject('Address not found for the specified alias'); | ||
| }); | ||
| return deferred.promise; | ||
| }; | ||
|
|
||
| var parseAddresses = function(respData, dnssec) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now :
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think I got it all addressed |
||
| let addresses = {} | ||
| return $q((resolve, reject) => { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now : |
||
| for (let i = 0; i < respData.length; i++) { | ||
| if (respData[i].address_type === 'undefined') { | ||
| continue; | ||
| } | ||
| if (respData[i].address === 'undefined') { | ||
| continue; | ||
| } | ||
| // 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; | ||
| } | ||
| // 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; | ||
| } | ||
| } | ||
|
|
||
| if (addresses.btc === 'undefined' && addresses.btc === 'undefined'){ | ||
| return reject('Error contacting opencap server, no response'); | ||
| } | ||
|
|
||
| return resolve({addresses, dnssec}); | ||
| }); | ||
| }; | ||
|
|
||
| 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; | ||
| }); | ||
| })(); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| <ion-popover-view style="height: 0px"> | ||
| <div class="card" style="text-align: center"> | ||
| <div class="item item-heading"> | ||
| <span translate>Alias found!</span> | ||
| </div> | ||
| <div class="list"> | ||
| <div class="item" ng-if="opencapAddresses.bch"> | ||
| <span>{{opencapAddresses.bch}}</span> | ||
| <button ng-click="confirmOpenapAddress(opencapAddresses.bch, 'bch')" class="button button-standard button-primary button-outline" translate>Send BCH</button> | ||
| </div> | ||
| <div class="item" ng-if="opencapAddresses.btc"> | ||
| <span>{{opencapAddresses.btc}}</span> | ||
| <button ng-click="confirmOpenapAddress(opencapAddresses.btc, 'btc')" class="button button-standard button-primary button-outline" translate>Send BTC</button> | ||
| </div> | ||
| <span class="item" ng-if="!opencapDnssec" style="color: red; " translate> | ||
| DNSSEC not used | ||
| </span> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </ion-popover-view> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now :
=>: lambda expression is not supported for old javascript engine.Should be :