Skip to content

Commit

Permalink
Merge pull request #55 from wwWallet/verification-polling
Browse files Browse the repository at this point in the history
replaced automatic form submission with polling for verification status
  • Loading branch information
kkmanos authored Aug 23, 2024
2 parents 302fa3c + 67fe370 commit 82ec39d
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 14 deletions.
44 changes: 41 additions & 3 deletions public/js/presentation-request.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,43 @@
const form = document.getElementById("PresentationRequestForm");

setTimeout(() => {
form.submit();
}, 6000);
const path = window.location.pathname;

const pathSegments = path.split('/');

const nonEmptySegments = pathSegments.filter(segment => segment !== '');
const presentationDefinitionId = nonEmptySegments[nonEmptySegments.length - 1];

document.addEventListener("DOMContentLoaded", function() {
const img = document.getElementById("qr-image");

img.addEventListener("click", function() {
img.classList.toggle("expanded");
});
});

setInterval(() => {

const state = form.elements['state'].value;

fetch('/verifier/public/definitions/presentation-request/' + presentationDefinitionId, {
method: 'POST',
body: JSON.stringify({ state }),
headers: {
'Content-Type': 'application/json'
}
}).then((response) => {
if (!response.ok) {
throw new Error(`HTTP error with status ${response.status}`);
}
return response.json();
})
.then((data) => {
const { url } = data;
if (url) {
window.location.href = url;
}
})
.catch((err) => {
console.error(err);
});
}, 3000);
10 changes: 9 additions & 1 deletion public/styles/scan-qr-verifier.css
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,12 @@

justify-content: center;
align-items: center;
}
}

.image-container {
cursor: pointer;
transition: transform 0.3s;
width: 50vw; /* Initial width is 50% of the viewport width */
height: auto; /* Maintain aspect ratio */
max-width: 400px; /* Maximum initial width */
}
12 changes: 2 additions & 10 deletions src/verifier/verifierRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,20 +134,12 @@ verifierRouter.use('/public/definitions/selectable-presentation-request/:present
verifierRouter.use('/public/definitions/presentation-request/:presentation_definition_id', async (req, res) => {
const presentation_definition_id = req.params.presentation_definition_id;
if (req.body.state && req.method == "POST") {
console.log("Got state = ", req.body.state)
const { status } = await openidForPresentationReceivingService.getPresentationByState(req.body.state as string);
if (status) {
return res.redirect(`/verifier/success?state=${req.body.state}`);
return res.send({ url: `/verifier/success?state=${req.body.state}` });
}
else {
return res.render('verifier/QR.pug', {
state: req.body.state,
wwwalletURL: config.wwwalletURL,
authorizationRequestURL: req.body.authorizationRequestURL,
authorizationRequestQR: req.body.authorizationRequestQR,
lang: req.lang,
locale: locale[req.lang],
})
return res.send({ });
}
}

Expand Down

0 comments on commit 82ec39d

Please sign in to comment.