qr Scanner
This commit is contained in:
parent
d6a99781fa
commit
28235011fd
3 changed files with 54 additions and 111 deletions
|
|
@ -1,6 +1,6 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('copayApp.controllers').controller('tabSendController', function($scope, $ionicModal, $log, $timeout, addressbookService, profileService, lodash, $state, walletService, bitcore ) {
|
||||
angular.module('copayApp.controllers').controller('tabSendController', function($scope, $ionicModal, $log, $timeout, addressbookService, profileService, lodash, $state, walletService ) {
|
||||
|
||||
var originalList;
|
||||
|
||||
|
|
@ -51,60 +51,14 @@ angular.module('copayApp.controllers').controller('tabSendController', function(
|
|||
};
|
||||
|
||||
|
||||
var setFromUri = function(uri) {
|
||||
|
||||
function sanitizeUri(uri) {
|
||||
// Fixes when a region uses comma to separate decimals
|
||||
var regex = /[\?\&]amount=(\d+([\,\.]\d+)?)/i;
|
||||
var match = regex.exec(uri);
|
||||
if (!match || match.length === 0) {
|
||||
return uri;
|
||||
}
|
||||
var value = match[0].replace(',', '.');
|
||||
var newUri = uri.replace(regex, value);
|
||||
return newUri;
|
||||
};
|
||||
|
||||
// URI extensions for Payment Protocol with non-backwards-compatible request
|
||||
if ((/^bitcoin:\?r=[\w+]/).exec(uri)) {
|
||||
uri = decodeURIComponent(uri.replace('bitcoin:?r=', ''));
|
||||
setFromPayPro(uri, function(err) {
|
||||
if (err) {
|
||||
return err;
|
||||
}
|
||||
});
|
||||
} else {
|
||||
uri = sanitizeUri(uri);
|
||||
|
||||
if (!bitcore.URI.isValid(uri)) {
|
||||
return uri;
|
||||
}
|
||||
var parsed = new bitcore.URI(uri);
|
||||
|
||||
var addr = parsed.address ? parsed.address.toString() : '';
|
||||
var message = parsed.message;
|
||||
|
||||
var amount = parsed.amount ? parsed.amount : '';
|
||||
|
||||
if (parsed.r) {
|
||||
$state.go('send.confirm', {paypro: parsed.r})
|
||||
} else {
|
||||
if (amount) {
|
||||
$state.go('send.confirm', {toAmount: amount, toAddress: addr, description:message})
|
||||
} else {
|
||||
$state.go('send.amount', {toAddress: addr})
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
$scope.findContact = function(search, opts) {
|
||||
opts = opts || {};
|
||||
|
||||
if (search.indexOf('bitcoin:') === 0) {
|
||||
return setFromUri(search);
|
||||
if (!walletService.redirFromUri(search)) {
|
||||
$log.error(err);
|
||||
}
|
||||
} else if (/^https?:\/\//.test(search)) {
|
||||
return $state.go('send.confirm', {paypro: search})
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue