Scanning or pasting ordinary URL gives the option to open it in a browser.

This commit is contained in:
Brendon Duncan 2018-08-30 19:56:18 +12:00
commit 918451f3da
5 changed files with 71 additions and 18 deletions

View file

@ -3865,4 +3865,12 @@ msgstr ""
#: src/js/controllers/tab-scan.js:121
msgid "Testnet is not supported."
msgstr ""
#: www/views/includes/incomingDataMenu.html:81
msgid "URL"
msgstr ""
#: www/views/includes/incomingDataMenu.html:90
msgid "Open in web browser"
msgstr ""

View file

@ -93,6 +93,7 @@
returns:
{
amount: '',
bareUrl: '',
coin: '',
copayInvitation: '',
isValid: false,
@ -163,6 +164,9 @@
addressAndParams = colonSplit[1];
console.log('No prefix.');
} else if (/^https?$/.test(colonSplit[1])) {
addressAndParams = trimmed;
} else {
// Something with a colon in the middle that we don't recognise
return parsed;
@ -253,6 +257,7 @@
var privateKeyForUncompressedPublicKeyTestnetRe = /^9[1-9A-HJ-NP-Za-km-z]{50}$/;
var privateKeyForCompressedPublicKeyRe = /^[KL][1-9A-HJ-NP-Za-km-z]{51}$/;
var privateKeyForCompressedPublicKeyTestnetRe = /^[c][1-9A-HJ-NP-Za-km-z]{51}$/;
var urlRe = /^https?:\/\/.+/;
var bitpayAddrMainnet = bitpayAddrOnMainnet(address);
var cashAddrTestnet = cashAddrOnTestnet(addressLowerCase);
@ -322,6 +327,10 @@
} else if (privateKeyEncryptedRe.test(address)) {
parsed.privateKey = { encrypted: address };
parsed.isValid = true;
} else if (urlRe.test(address)) {
parsed.bareUrl = trimmed;
parsed.isValid = true;
}
} else {

View file

@ -343,11 +343,20 @@ fdescribe('bitcoinUriService', function() {
expect(parsed.isValid).toBe(false);
});
it('URL only', function() {
it('URL only, http', function() {
var parsed = bitcoinUriService.parse('https://www.google.com');
var parsed = bitcoinUriService.parse('http://paperwallet.bitcoin.com');
expect(parsed.isValid).toBe(false);
expect(parsed.isValid).toBe(true);
expect(parsed.bareUrl).toBe('http://paperwallet.bitcoin.com');
});
it('URL only, https with query', function() {
var parsed = bitcoinUriService.parse('https://purse.io/?one=two&three=four');
expect(parsed.isValid).toBe(true);
expect(parsed.bareUrl).toBe('https://purse.io/?one=two&three=four');
});
});

View file

@ -1,6 +1,6 @@
'use strict';
angular.module('copayApp.services').factory('incomingData', function(bitcoinUriService, $log, $state, $timeout, $ionicHistory, bitcore, bitcoreCash, $rootScope, payproService, scannerService, sendFlowService, appConfigService, popupService, gettextCatalog, bitcoinCashJsService) {
angular.module('copayApp.services').factory('incomingData', function(externalLinkService, bitcoinUriService, $log, $state, $timeout, $ionicHistory, bitcore, bitcoreCash, $rootScope, payproService, scannerService, sendFlowService, appConfigService, popupService, gettextCatalog, bitcoinCashJsService) {
var root = {};
@ -251,20 +251,23 @@ angular.module('copayApp.services').factory('incomingData', function(bitcoinUriS
);
return true;
// Plain URL
} else if (/^https?:\/\//.test(data)) {
payproService.getPayProDetails(data, coin, function(err, details) {
if (err) {
if ($state.includes('tabs.scan')) {
root.showMenu({
data: data,
type: 'url'
});
}
return;
}
handlePayPro(details);
return true;
});
} else if (allParsed.bareUrl) {
if ($state.includes('tabs.scan')) {
root.showMenu({
data: allParsed.bareUrl,
type: 'url'
});
} else {
externalLinkService.open(
allParsed.bareUrl,
true,
gettextCatalog.getString('Open in web browser'),
allParsed.bareUrl
);
}
return true;
// Plain Address
} else if (bitcore.Address.isValid(data, 'livenet') || bitcore.Address.isValid(data, 'testnet')) {
if ($state.includes('tabs.scan')) {

View file

@ -76,4 +76,28 @@
</a>
</div>
<div ng-if="type === 'url'">
<div class="incoming-data-menu__item head">
<div class="incoming-data-menu__header" translate>URL</div>
<div class="incoming-data-menu__url">
<div class="incoming-data-menu__url__text" style="border: 0;">
{{data}}
</div>
</div>
</div>
<a class="incoming-data-menu__item item item-icon-right" ng-click="goToUrl(data)">
<img src="img/icon-link-external.svg">
<div class="incoming-data-menu__item__text" translate>Open in web browser</div>
<i class="icon bp-arrow-right"></i>
</a>
<a class="incoming-data-menu__item item item-icon-right" copy-to-clipboard="data">
<img src="img/icon-paperclip.svg">
<div class="incoming-data-menu__item__text" translate>Copy to clipboard</div>
<i class="icon bp-arrow-right"></i>
</a>
<a class="incoming-data-menu__cancel item" ng-click="hide()" translate>
Cancel
</a>
</div>
</action-sheet>