diff --git a/src/html/home.js b/src/html/home.js
index 0ad4963..31fd59b 100644
--- a/src/html/home.js
+++ b/src/html/home.js
@@ -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)
- // }
+ ++countResults;
+ lastResult = decodedText;
+ // Handle on success condition with the decoded message.
+ console.log(`Scan result ${decodedText}`, decodedResult);
+ 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(
diff --git a/src/index.ts b/src/index.ts
index 3688414..2000ab7 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -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)
}