Add native QR scanner to send form
This commit is contained in:
parent
e121d0acb6
commit
19f57e614c
3 changed files with 33 additions and 7 deletions
|
|
@ -692,6 +692,9 @@
|
|||
<input type="text" id="address" name="address" ng-disabled="loading"
|
||||
placeholder="Send to" ng-model="address" valid-address required>
|
||||
</div>
|
||||
<div class="small-2 columns" ng-hide="!isCordova">
|
||||
<a class="postfix button secondary" ng-click="scannerIntent()"><i class="fi-camera"></i></a>
|
||||
</div>
|
||||
<div class="small-2 columns" ng-hide="showScanner || !isHttp">
|
||||
<a class="postfix button secondary" ng-click="openScanner()"><i class="fi-camera"></i></a>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@ angular.module('copayApp.controllers').controller('SendController',
|
|||
|
||||
// Detect protocol
|
||||
$scope.isHttp = ($window.location.protocol.indexOf('http') === 0);
|
||||
$scope.isCordova = typeof(window.cordova) != 'undefined';
|
||||
|
||||
navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia;
|
||||
window.URL = window.URL || window.webkitURL || window.mozURL || window.msURL;
|
||||
|
|
@ -194,6 +195,25 @@ angular.module('copayApp.controllers').controller('SendController',
|
|||
}, 500);
|
||||
};
|
||||
|
||||
$scope.scannerIntent = function() {
|
||||
cordova.plugins.barcodeScanner.scan(
|
||||
function onSuccess(result) {
|
||||
if (result.cancelled) return;
|
||||
|
||||
var bip21 = copay.Structure.parseBitcoinURI(result.text);
|
||||
$scope.address = bip21.address;
|
||||
|
||||
if (bip21.amount) {
|
||||
$scope.amount = bip21.amount * bitcore.util.COIN * satToUnit;
|
||||
}
|
||||
|
||||
$rootScope.$digest();
|
||||
},
|
||||
function onError(error) {
|
||||
alert('Scanning error');
|
||||
});
|
||||
}
|
||||
|
||||
$scope.toggleAddressBookEntry = function(key) {
|
||||
var w = $rootScope.wallet;
|
||||
w.toggleAddressBookEntry(key);
|
||||
|
|
|
|||
|
|
@ -59,13 +59,16 @@ Structure.parseBitcoinURI = function(uri) {
|
|||
data = splitDots[1];
|
||||
var splitQuestion = data.split('?');
|
||||
ret.address = splitQuestion[0];
|
||||
var search = splitQuestion[1];
|
||||
data = JSON.parse('{"' + search.replace(/&/g, '","').replace(/=/g, '":"') + '"}',
|
||||
function(key, value) {
|
||||
return key === "" ? value : decodeURIComponent(value);
|
||||
});
|
||||
ret.amount = parseFloat(data.amount);
|
||||
ret.message = data.message;
|
||||
|
||||
if (splitQuestion.length > 1) {
|
||||
var search = splitQuestion[1];
|
||||
data = JSON.parse('{"' + search.replace(/&/g, '","').replace(/=/g, '":"') + '"}',
|
||||
function(key, value) {
|
||||
return key === "" ? value : decodeURIComponent(value);
|
||||
});
|
||||
ret.amount = parseFloat(data.amount);
|
||||
ret.message = data.message;
|
||||
}
|
||||
|
||||
return ret;
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue