Adds bitcoincash URL support
This commit is contained in:
parent
2e4c1d6abd
commit
823814817d
8 changed files with 45 additions and 26 deletions
|
|
@ -66,6 +66,7 @@
|
|||
<plugin name="cordova-plugin-customurlscheme" spec="https://github.com/cmgustavo/Custom-URL-scheme.git">
|
||||
<variable name="URL_SCHEME" value="bitcoin" />
|
||||
<variable name="SECOND_URL_SCHEME" value="*APPURI*" />
|
||||
<variable name="THIRD_URL_SCHEME" value="bitcoincash" />
|
||||
</plugin>
|
||||
<plugin name="cordova-custom-config" spec="~3.0.5" />
|
||||
<plugin name="cordova-plugin-queries-schemes" spec="~0.1.5" />
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ angular.module('copayApp.controllers').controller('addressbookAddController', fu
|
|||
$timeout(function() {
|
||||
var form = addressbookForm;
|
||||
if (data && form) {
|
||||
data = data.replace('bitcoin:', '');
|
||||
data = data.replace(/^bitcoin[cash]*:/, '');
|
||||
form.address.$setViewValue(data);
|
||||
form.address.$isValid = true;
|
||||
form.address.$render();
|
||||
|
|
|
|||
|
|
@ -63,12 +63,16 @@ angular.module('copayApp.controllers').controller('customAmountController', func
|
|||
|
||||
$scope.shareAddress = function() {
|
||||
if (!platformInfo.isCordova) return;
|
||||
var data = 'bitcoin:' + $scope.address + '?amount=' + $scope.amountBtc + '&coin=' + $scope.wallet.coin;
|
||||
var protocol = 'bitcoin';
|
||||
if ($scope.wallet.coin == 'bch') protocol += 'cash';
|
||||
var data = protocol + ':' + $scope.address + '?amount=' + $scope.amountBtc;
|
||||
window.plugins.socialsharing.share(data, null, null, null);
|
||||
}
|
||||
|
||||
$scope.copyToClipboard = function() {
|
||||
return 'bitcoin:' + $scope.address + '?amount=' + $scope.amountBtc + '&coin=' + $scope.wallet.coin;
|
||||
var protocol = 'bitcoin';
|
||||
if ($scope.wallet.coin == 'bch') protocol += 'cash';
|
||||
return protocol + ':' + $scope.address + '?amount=' + $scope.amountBtc;
|
||||
};
|
||||
|
||||
});
|
||||
|
|
|
|||
|
|
@ -137,6 +137,8 @@ angular.module('copayApp.controllers').controller('tabReceiveController', functi
|
|||
|
||||
$scope.shareAddress = function() {
|
||||
if (!$scope.isCordova) return;
|
||||
window.plugins.socialsharing.share('bitcoin:' + $scope.addr, null, null, null);
|
||||
var protocol = 'bitcoin';
|
||||
if ($scope.wallet.coin == 'bch') protocol += 'cash';
|
||||
window.plugins.socialsharing.share(protocol + ':' + $scope.addr, null, null, null);
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -69,8 +69,8 @@ angular.module('copayApp.services').factory('incomingData', function($log, $stat
|
|||
}, 100);
|
||||
}
|
||||
// data extensions for Payment Protocol with non-backwards-compatible request
|
||||
if ((/^bitcoin:\?r=[\w+]/).exec(data)) {
|
||||
data = decodeURIComponent(data.replace('bitcoin:?r=', ''));
|
||||
if ((/^bitcoin[cash]*:\?r=[\w+]/).exec(data)) {
|
||||
data = decodeURIComponent(data.replace(/bitcoin[cash]*:?r=/, ''));
|
||||
$state.go('tabs.send', {}, {
|
||||
'reload': true,
|
||||
'notify': $state.current.name == 'tabs.send' ? false : true
|
||||
|
|
@ -84,27 +84,38 @@ angular.module('copayApp.services').factory('incomingData', function($log, $stat
|
|||
|
||||
data = sanitizeUri(data);
|
||||
|
||||
// BIP21
|
||||
if (bitcore.URI.isValid(data)) {
|
||||
var parsed = new bitcore.URI(data);
|
||||
|
||||
var addr = parsed.address ? parsed.address.toString() : '';
|
||||
var message = parsed.message;
|
||||
|
||||
var amount = parsed.amount ? parsed.amount : '';
|
||||
var coin = parsed.extras && parsed.extras.coin ? parsed.extras.coin : '';
|
||||
|
||||
if (parsed.r) {
|
||||
payproService.getPayProDetails(parsed.r, function(err, details) {
|
||||
if (err) {
|
||||
if (addr && amount) goSend(addr, amount, message, coin);
|
||||
else popupService.showAlert(gettextCatalog.getString('Error'), err);
|
||||
} else handlePayPro(details);
|
||||
});
|
||||
} else {
|
||||
goSend(addr, amount, message, coin);
|
||||
// Bitcoin or Bitcoin Cash URL
|
||||
if ((/^bitcoin[cash]*:/).exec(data)) {
|
||||
var coin = 'btc';
|
||||
if ((/^bitcoincash*:/).exec(data)) {
|
||||
coin = 'bch';
|
||||
data = data.replace(/bitcoincash*:/, 'bitcoin:');
|
||||
}
|
||||
console.log('[incomingData.js:93]', coin, data); //TODO/
|
||||
if (bitcore.URI.isValid(data)) {
|
||||
var parsed = new bitcore.URI(data);
|
||||
|
||||
var addr = parsed.address ? parsed.address.toString() : '';
|
||||
var message = parsed.message;
|
||||
|
||||
var amount = parsed.amount ? parsed.amount : '';
|
||||
|
||||
if (parsed.r) {
|
||||
payproService.getPayProDetails(parsed.r, function(err, details) {
|
||||
if (err) {
|
||||
if (addr && amount) goSend(addr, amount, message, coin);
|
||||
else popupService.showAlert(gettextCatalog.getString('Error'), err);
|
||||
} else handlePayPro(details);
|
||||
});
|
||||
} else {
|
||||
goSend(addr, amount, message, coin);
|
||||
}
|
||||
return true;
|
||||
|
||||
} else {
|
||||
$log.error('Invalid Bitcoin URL');
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
||||
// Plain URL
|
||||
} else if (/^https?:\/\//.test(data)) {
|
||||
|
|
|
|||
|
|
@ -57,10 +57,10 @@ angular.module('copayApp.services').factory('openURLService', function($rootScop
|
|||
|
||||
// This event is sent to an existent instance of Copay (only for standalone apps)
|
||||
gui.App.on('open', function(pathData) {
|
||||
if (pathData.indexOf('bitcoin:') != -1) {
|
||||
if (pathData.indexOf(/^bitcoin[cash]*:/) != -1) {
|
||||
$log.debug('Bitcoin URL found');
|
||||
handleOpenURL({
|
||||
url: pathData.substring(pathData.indexOf('bitcoin:'))
|
||||
url: pathData.substring(pathData.indexOf(/^bitcoin[cash]*:/))
|
||||
});
|
||||
} else if (pathData.indexOf(appConfigService.name + '://') != -1) {
|
||||
$log.debug(appConfigService.name + ' URL found');
|
||||
|
|
@ -84,6 +84,7 @@ angular.module('copayApp.services').factory('openURLService', function($rootScop
|
|||
if (navigator.registerProtocolHandler) {
|
||||
$log.debug('Registering Browser handlers base:' + base);
|
||||
navigator.registerProtocolHandler('bitcoin', url, 'Copay Bitcoin Handler');
|
||||
navigator.registerProtocolHandler('web+bitcoincash', url, 'Copay Bitcoin Cash Handler');
|
||||
navigator.registerProtocolHandler('web+copay', url, 'Copay Wallet Handler');
|
||||
navigator.registerProtocolHandler('web+bitpay', url, 'BitPay Wallet Handler');
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@
|
|||
<ion-content scroll="false">
|
||||
<div class="address" ng-if="address && amountBtc">
|
||||
<div class="qr-code" copy-to-clipboard="copyToClipboard()">
|
||||
<qrcode size="220" data="bitcoin:{{address + '?amount=' + amountBtc + '&coin=' + coin}}" color="#334"></qrcode>
|
||||
<qrcode size="220" data="bitcoin{{ wallet.coin == 'bch' ? 'cash' : '' }}:{{address + '?amount=' + amountBtc}}" color="#334"></qrcode>
|
||||
</div>
|
||||
<div class="info">
|
||||
<div class="item single-line" copy-to-clipboard="address">
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@
|
|||
<span translate>Show address</span>
|
||||
</button>
|
||||
</span>
|
||||
<qrcode ng-if="addr" size="220" data="bitcoin:{{addr}}" color="#334"></qrcode>
|
||||
<qrcode ng-if="addr" size="220" data="bitcoin{{ wallet.coin == 'bch' ? 'cash' : ''}}:{{addr}}" color="#334"></qrcode>
|
||||
<div class="address-label">
|
||||
<span class="ellipsis">{{addr}}</span>
|
||||
<ion-spinner ng-show="!addr" class="spinner-dark" icon="crescent"></ion-spinner>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue