-
Notifications
You must be signed in to change notification settings - Fork 75
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
Handle Declined proof (abandoned state callback) #406
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -136,6 +136,7 @@ | |
.header-desc.success, | ||
.header-desc.pending, | ||
.header-desc.expired, | ||
.header-desc.abandoned, | ||
.header-desc.failed { | ||
display: none; | ||
border-radius: 0.5rem; | ||
|
@@ -166,6 +167,9 @@ | |
.header-desc.success { | ||
background-color: #dff0d8; | ||
} | ||
.header-desc.abandoned { | ||
background-color: #f2dede; | ||
} | ||
.header-desc a { | ||
line-height: 1rem; | ||
} | ||
|
@@ -216,6 +220,18 @@ <h1>Scan with a Digital Wallet</h1> | |
</div> | ||
</div> | ||
|
||
<div class="header-desc abandoned"> | ||
<div class="qr-code-image">{{add_asset("circle-x.svg")}}</div> | ||
<div class="qr-code-desc"> | ||
<b>Proof declined</b> | ||
</br> | ||
<a href="javascript:window.location.reload(true)" | ||
title="Refresh QR code." | ||
>Try again.</a | ||
> | ||
</div> | ||
</div> | ||
|
||
<div class="header-desc pending"> | ||
<div class="qr-code-image">{{add_asset("hourglass.svg")}}</div> | ||
<div class="qr-code-desc"> | ||
|
@@ -273,93 +289,27 @@ <h1>Scan with a Digital Wallet</h1> | |
socket.connect(); | ||
|
||
const toggleState = (state) => { | ||
const intro = document.querySelector(".intro"); | ||
const success = document.querySelector(".success"); | ||
const pending = document.querySelector(".pending"); | ||
const failed = document.querySelector(".failed"); | ||
const expired = document.querySelector(".expired"); | ||
const qrcode = document.querySelector(".qr-code"); | ||
const scannedMask = document.querySelector(".scanned-mask"); | ||
const refreshButton = document.getElementById("refresh-button"); | ||
|
||
switch (state) { | ||
case "intro": | ||
// Header elements | ||
intro.style.display = "grid"; | ||
success.style.display = "none"; | ||
pending.style.display = "none"; | ||
failed.style.display = "none"; | ||
expired.style.display = "none"; | ||
|
||
// Button elements | ||
refreshButton.style.display = "none"; | ||
|
||
// Turn off the spinner | ||
qrcode.classList.remove("pending"); | ||
setUiElements(".intro", false, false, false); | ||
break; | ||
case "verified": | ||
// Header elements | ||
intro.style.display = "none"; | ||
success.style.display = "grid"; | ||
pending.style.display = "none"; | ||
failed.style.display = "none"; | ||
expired.style.display = "none"; | ||
|
||
// Button elements | ||
refreshButton.style.display = "none"; | ||
scannedMask.style.display = "flex"; | ||
|
||
// Turn off the spinner | ||
qrcode.classList.remove("pending"); | ||
|
||
setUiElements(".success", false, true, false); | ||
setTimeout(() => { | ||
window.location.replace("{{callback_url}}", { method: "POST" }); | ||
}, 2000); | ||
break; | ||
case "failed": | ||
// Header elements | ||
intro.style.display = "none"; | ||
success.style.display = "none"; | ||
pending.style.display = "none"; | ||
failed.style.display = "grid"; | ||
expired.style.display = "none"; | ||
|
||
// Button elements | ||
refreshButton.style.display = "flex"; | ||
scannedMask.style.display = "none"; | ||
|
||
// Turn off the spinner | ||
qrcode.classList.remove("pending"); | ||
setUiElements(".failed", true, false, false); | ||
break; | ||
case "pending": | ||
// Header elements | ||
intro.style.display = "none"; | ||
success.style.display = "none"; | ||
pending.style.display = "grid"; | ||
failed.style.display = "none"; | ||
expired.style.display = "none"; | ||
|
||
// Button elements | ||
refreshButton.style.display = "none"; | ||
scannedMask.style.display = "flex"; | ||
|
||
// Turn on the spinner | ||
qrcode.classList.add("pending"); | ||
setUiElements(".pending", false, true, true); | ||
break; | ||
case "expired": | ||
// Header elements | ||
intro.style.display = "none"; | ||
success.style.display = "none"; | ||
pending.style.display = "none"; | ||
failed.style.display = "none"; | ||
expired.style.display = "grid"; | ||
|
||
// Button elements | ||
refreshButton.style.display = "flex"; | ||
scannedMask.style.display = "none"; | ||
|
||
// Turn off the spinner | ||
qrcode.classList.remove("pending"); | ||
setUiElements(".expired", true, false, false); | ||
break; | ||
case "abandoned": | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. New state |
||
setUiElements(".abandoned", true, false, false); | ||
break; | ||
} | ||
}; | ||
|
@@ -368,6 +318,29 @@ <h1>Scan with a Digital Wallet</h1> | |
location.reload(true); | ||
}); | ||
|
||
/** | ||
* Set the UI elements based on the current state | ||
*/ | ||
const setUiElements = (state, showRefresh, showScanned, setSpinner) => { | ||
const stateElement = document.querySelector(state); | ||
const qrcode = document.querySelector(".qr-code"); | ||
const scannedMask = document.querySelector(".scanned-mask"); | ||
const refreshButton = document.getElementById("refresh-button"); | ||
|
||
// set all elements to display: none and display the current state | ||
document.querySelectorAll(".header-desc").forEach((el) => { | ||
el.style.display = "none"; | ||
}); | ||
stateElement.style.display = "grid"; | ||
|
||
// set the refresh and/or scanned overlays | ||
refreshButton.style.display = showRefresh ? "flex" : "none"; | ||
scannedMask.style.display = showScanned ? "flex" : "none"; | ||
|
||
// add or remove 'pending' class from qrcode based on setSpinner | ||
qrcode.classList.toggle("pending", setSpinner); | ||
} | ||
|
||
let timer; | ||
|
||
/** | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I refactored all this away to the setUiElements function below to generalize.