Merge pull request #312 from Bitcoin-com/wallet/task/500
Upgrade the bitcoin uri service and its integration
This commit is contained in:
commit
480cfe43ca
4 changed files with 66 additions and 15 deletions
|
|
@ -3849,4 +3849,20 @@ msgstr ""
|
|||
|
||||
#: src/js/services/incomingData.js:129
|
||||
msgid "This invoice is no longer accepting payments"
|
||||
msgstr ""
|
||||
|
||||
#: src/js/controllers/tab-scan.js:120
|
||||
msgid "Scan Failed"
|
||||
msgstr ""
|
||||
|
||||
#: src/js/controllers/tab-scan.js:121
|
||||
msgid "Data not recognised."
|
||||
msgstr ""
|
||||
|
||||
#: src/js/controllers/tab-scan.js:121
|
||||
msgid "Unsupported"
|
||||
msgstr ""
|
||||
|
||||
#: src/js/controllers/tab-scan.js:121
|
||||
msgid "Testnet is not supported."
|
||||
msgstr ""
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('copayApp.controllers').controller('tabScanController', function($scope, $log, $timeout, scannerService, incomingData, $state, $ionicHistory, $rootScope, $ionicNavBarDelegate) {
|
||||
angular.module('copayApp.controllers').controller('tabScanController', function(bitcoinUriService, gettextCatalog, popupService, $scope, $log, $timeout, scannerService, incomingData, $state, $ionicHistory, $rootScope, $ionicNavBarDelegate) {
|
||||
|
||||
var scannerStates = {
|
||||
unauthorized: 'unauthorized',
|
||||
|
|
@ -111,7 +111,27 @@ angular.module('copayApp.controllers').controller('tabScanController', function(
|
|||
// Sometimes (testing in Chrome, when reading QR Code) data is an object
|
||||
// that has a string data.result.
|
||||
contents = contents.result || contents;
|
||||
incomingData.redir(contents);
|
||||
|
||||
var parsed = bitcoinUriService.parse(contents);
|
||||
var title = '';
|
||||
var msg = '';
|
||||
if (parsed.isValid) {
|
||||
if (parsed.testnet) {
|
||||
title = gettextCatalog.getString('Unsupported');
|
||||
msg = gettextCatalog.getString('Testnet is not supported.');
|
||||
popupService.showAlert(title, msg, function onAlertShown() {
|
||||
scannerService.resumePreview();
|
||||
});
|
||||
} else {
|
||||
incomingData.redir(contents);
|
||||
}
|
||||
} else {
|
||||
title = gettextCatalog.getString('Scan Failed');
|
||||
msg = gettextCatalog.getString('Data not recognised.');
|
||||
popupService.showAlert(title, msg, function onAlertShown() {
|
||||
scannerService.resumePreview();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
$rootScope.$on('incomingDataMenu.menuHidden', function() {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('copayApp.controllers').controller('tabSendController', function($scope, $rootScope, $log, $timeout, $ionicScrollDelegate, $ionicLoading, addressbookService, profileService, lodash, $state, walletService, incomingData, popupService, platformInfo, sendFlowService, bwcError, gettextCatalog, scannerService, configService, bitcoinCashJsService, $ionicPopup, $ionicNavBarDelegate, clipboardService) {
|
||||
angular.module('copayApp.controllers').controller('tabSendController', function(bitcoinUriService, $scope, $rootScope, $log, $timeout, $ionicScrollDelegate, $ionicLoading, addressbookService, profileService, lodash, $state, walletService, incomingData, popupService, platformInfo, sendFlowService, bwcError, gettextCatalog, scannerService, configService, bitcoinCashJsService, $ionicPopup, $ionicNavBarDelegate, clipboardService) {
|
||||
var clipboardHasAddress = false;
|
||||
var clipboardHasContent = false;
|
||||
var originalList;
|
||||
|
|
@ -39,7 +39,9 @@ angular.module('copayApp.controllers').controller('tabSendController', function(
|
|||
|
||||
$scope.clipboardHasAddress = false;
|
||||
$scope.clipboardHasContent = false;
|
||||
if ((text.indexOf('bitcoincash:') === 0 || text[0] === 'C' || text[0] === 'H' || text[0] === 'p' || text[0] === 'q') && text.replace('bitcoincash:', '').length === 42) { // CashAddr
|
||||
var parsed = bitcoinUriService.parse(text);
|
||||
console.log('parsed', parsed);
|
||||
if (parsed.isValid && parsed.publicAddress && parsed.coin === 'bch' && !parsed.testnet) { // CashAddr
|
||||
$scope.clipboardHasAddress = true;
|
||||
} else if ((text[0] === "1" || text[0] === "3" || text.substring(0, 3) === "bc1") && text.length >= 26 && text.length <= 35) { // Legacy Addresses
|
||||
$scope.clipboardHasAddress = true;
|
||||
|
|
|
|||
|
|
@ -13,6 +13,14 @@ angular.module('copayApp.services').factory('incomingData', function(bitcoinUriS
|
|||
var noPrefixInAddress = 0;
|
||||
var allParsed = bitcoinUriService.parse(data);
|
||||
|
||||
if (allParsed.isValid && allParsed.testnet) {
|
||||
popupService.showAlert(
|
||||
gettextCatalog.getString('Unsupported'),
|
||||
gettextCatalog.getString('Testnet is not supported.')
|
||||
);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (data.toLowerCase().indexOf('bitcoin') < 0) {
|
||||
noPrefixInAddress = 1;
|
||||
}
|
||||
|
|
@ -115,7 +123,7 @@ angular.module('copayApp.services').factory('incomingData', function(bitcoinUriS
|
|||
}, 100);
|
||||
}
|
||||
// data extensions for Payment Protocol with non-backwards-compatible request
|
||||
if (allParsed.isValid && allParsed.coin && allParsed.url) {
|
||||
if (allParsed.isValid && allParsed.coin && allParsed.url && !allParsed.testnet) {
|
||||
var coin = allParsed.coin;
|
||||
data = allParsed.url;
|
||||
if (allParsed.coin == 'bch') {
|
||||
|
|
@ -168,28 +176,33 @@ angular.module('copayApp.services').factory('incomingData', function(bitcoinUriS
|
|||
}
|
||||
return true;
|
||||
// Cash URI
|
||||
} else if (allParsed.isValid && allParsed.publicAddress && allParsed.publicAddress.cashAddr) {
|
||||
var coin = 'bch';
|
||||
|
||||
} else if (allParsed.isValid && allParsed.coin === 'bch' && allParsed.publicAddress && !allParsed.testnet) {
|
||||
var prefix = allParsed.testnet ? 'bchtest:' : 'bitcoincash:';
|
||||
addr = bitcoinCashJsService.readAddress(prefix + allParsed.publicAddress.cashAddr).legacy;
|
||||
var message = parsed.message;
|
||||
var addrIn = allParsed.publicAddress.legacy || allParsed.publicAddress.bitpay || prefix + allParsed.publicAddress.cashAddr;
|
||||
originalAddress = allParsed.publicAddress.cashAddr || allParsed.publicAddress.legacy || allParsed.publicAddress.bitpay;
|
||||
|
||||
var amount = parsed.amount ? parsed.amount : '';
|
||||
var addresses = bitcoinCashJsService.readAddress(addrIn);
|
||||
if (!addresses) {
|
||||
return false;
|
||||
}
|
||||
addr = addresses.legacy;
|
||||
var message = allParsed.message;
|
||||
|
||||
var amount = allParsed.amount ? allParsed.amount : '';
|
||||
|
||||
// paypro not yet supported on cash
|
||||
if (allParsed.url) {
|
||||
payproService.getPayProDetails(allParsed.url, coin, function(err, details) {
|
||||
payproService.getPayProDetails(allParsed.url, allParsed.coin, function(err, details) {
|
||||
if (err) {
|
||||
if (addr && amount)
|
||||
goSend(addr, amount, message, coin, serviceId, serviceData);
|
||||
goSend(addr, amount, message, allParsed.coin, serviceId, serviceData);
|
||||
else
|
||||
popupService.showAlert(gettextCatalog.getString('Error'), err);
|
||||
}
|
||||
handlePayPro(details, coin);
|
||||
handlePayPro(details, allParsed.coin);
|
||||
});
|
||||
} else {
|
||||
goSend(addr, amount, message, coin, serviceId, serviceData);
|
||||
goSend(addr, amount, message, allParsed.coin, serviceId, serviceData);
|
||||
}
|
||||
return true;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue