Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replaced automatic form submission with polling for verification status #55

Merged
merged 1 commit into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading