Fix bug in scanned url parsing

This commit is contained in:
Sosthene 2024-10-12 13:01:18 +02:00
parent edef1428c3
commit 755828c495
2 changed files with 24 additions and 8 deletions

View File

@ -58,13 +58,29 @@ docReady(function () {
var resultContainer = document.getElementById('qr-reader-results');
var lastResult, countResults = 0;
function onScanSuccess(decodedText, decodedResult) {
// if (decodedText !== lastResult) {
++countResults;
lastResult = decodedText;
// Handle on success condition with the decoded message.
console.log(`Scan result ${decodedText}`, decodedResult);
service.sendPairingTx(decodedText)
// }
try {
// 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(

View File

@ -21,7 +21,7 @@ try {
const queryString = window.location.search;
const urlParams = new URLSearchParams(queryString)
const pairingAddress = urlParams.get('address')
const pairingAddress = urlParams.get('sp_address')
if(pairingAddress) {
await services.sendPairingTx(pairingAddress)
}