Fix bug in scanned url parsing
This commit is contained in:
parent
edef1428c3
commit
755828c495
@ -58,13 +58,29 @@ docReady(function () {
|
|||||||
var resultContainer = document.getElementById('qr-reader-results');
|
var resultContainer = document.getElementById('qr-reader-results');
|
||||||
var lastResult, countResults = 0;
|
var lastResult, countResults = 0;
|
||||||
function onScanSuccess(decodedText, decodedResult) {
|
function onScanSuccess(decodedText, decodedResult) {
|
||||||
// if (decodedText !== lastResult) {
|
++countResults;
|
||||||
++countResults;
|
lastResult = decodedText;
|
||||||
lastResult = decodedText;
|
// Handle on success condition with the decoded message.
|
||||||
// Handle on success condition with the decoded message.
|
console.log(`Scan result ${decodedText}`, decodedResult);
|
||||||
console.log(`Scan result ${decodedText}`, decodedResult);
|
try {
|
||||||
service.sendPairingTx(decodedText)
|
// Attempt to parse the decoded text as a URL
|
||||||
// }
|
const scannedUrl = new URL(decodedText);
|
||||||
|
|
||||||
|
// Extract the 'sp_address' parameter
|
||||||
|
const spAddress = scannedUrl.searchParams.get('sp_address');
|
||||||
|
|
||||||
|
if (spAddress) {
|
||||||
|
// Call the sendPairingTx function with the extracted sp_address
|
||||||
|
service.sendPairingTx(spAddress);
|
||||||
|
} else {
|
||||||
|
console.error('The scanned URL does not contain the sp_address parameter.');
|
||||||
|
alert('Invalid QR code: sp_address parameter missing.');
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
// Handle cases where decodedText is not a valid URL
|
||||||
|
console.error('Scanned text is not a valid URL:', error);
|
||||||
|
alert('Invalid QR code: Unable to parse URL.');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var html5QrcodeScanner = new Html5QrcodeScanner(
|
var html5QrcodeScanner = new Html5QrcodeScanner(
|
||||||
|
@ -21,7 +21,7 @@ try {
|
|||||||
|
|
||||||
const queryString = window.location.search;
|
const queryString = window.location.search;
|
||||||
const urlParams = new URLSearchParams(queryString)
|
const urlParams = new URLSearchParams(queryString)
|
||||||
const pairingAddress = urlParams.get('address')
|
const pairingAddress = urlParams.get('sp_address')
|
||||||
if(pairingAddress) {
|
if(pairingAddress) {
|
||||||
await services.sendPairingTx(pairingAddress)
|
await services.sendPairingTx(pairingAddress)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user