-
Notifications
You must be signed in to change notification settings - Fork 166
LG-8875 / LG-8877: Try to avoid race condition in document-capture-welcome #7842
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
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
78f7a70
"Convert" document-capture-welcome to typescript
matthinz bccec54
Rework camera check to block form submission
matthinz 4d974a9
Disable submit buttons while we wait
matthinz 96cbc3e
TEMP: Allow injecting delay into hasCamera()
matthinz 07e62a6
Update app/javascript/packs/document-capture-welcome.ts
matthinz 8abca7c
Use SpinnerButtonComponent for welcome/agreement
matthinz 6c41607
Simplify cameraCheckPromise usage
matthinz 646af3e
Wrap agreement spinner button in <div>
matthinz cb0426a
changelog: User-Facing Improvements, Identity verification, help prev…
matthinz 988ff88
Log event from frontend for mobile/camera checks
matthinz 7720607
Refactor perf measuring slightly
matthinz 2af508a
Add spin_on_click to SpinnerButtonComponent
matthinz 1ec5f33
Toggle spinner on form submission
matthinz c0f6958
await trackEvent that could occur during form submission
matthinz 1ccc816
Add idv_mobile_device_and_camera_check to AnalyticsEvents
matthinz 010f6e5
Revert "TEMP: Allow injecting delay into hasCamera()"
matthinz aacca64
Don't use performance.measure()
matthinz 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 hidden or 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 hidden or 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 hidden or 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 was deleted.
Oops, something went wrong.
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| import { trackEvent } from '@18f/identity-analytics'; | ||
| import { hasCamera, isCameraCapableMobile } from '@18f/identity-device'; | ||
|
|
||
| const GRACE_TIME_FOR_CAMERA_CHECK_MS = 2000; | ||
| const DEVICE_CHECK_EVENT = 'IdV: Mobile device and camera check'; | ||
|
|
||
| function delay(ms: number): Promise<void> { | ||
| return new Promise((resolve) => setTimeout(resolve, ms)); | ||
| } | ||
|
|
||
| async function measure<T>(func: () => Promise<T>): Promise<{ result: T; duration: number }> { | ||
| const start = performance.now(); | ||
| const result = await func(); | ||
| const duration = performance.now() - start; | ||
| return { result, duration }; | ||
| } | ||
|
|
||
| function addFormInputsForMobileDeviceCapabilities() { | ||
| const form = document.querySelector<HTMLFormElement>('.js-consent-continue-form'); | ||
|
|
||
| if (!form) { | ||
| return; | ||
| } | ||
|
|
||
| if (!isCameraCapableMobile()) { | ||
| trackEvent(DEVICE_CHECK_EVENT, { | ||
| is_camera_capable_mobile: false, | ||
| }); | ||
| return; | ||
| } | ||
|
|
||
| // The check for a camera on the device is async -- kick it off here and intercept | ||
| // submit() to ensure that it completes in time. | ||
| const cameraCheckPromise = measure(hasCamera).then( | ||
| async ({ result: cameraPresent, duration }) => { | ||
| if (!cameraPresent) { | ||
| // Signal to the backend that this is a mobile device, but no camera is present | ||
| const ncInput = document.createElement('input'); | ||
| ncInput.type = 'hidden'; | ||
| ncInput.name = 'no_camera'; | ||
| form.appendChild(ncInput); | ||
| } | ||
|
|
||
| // Signal to the backend that this is a mobile device, and this user should skip the | ||
| // "hybrid handoff" step. | ||
| const input = document.createElement('input'); | ||
| input.type = 'hidden'; | ||
| input.name = 'skip_upload'; | ||
| form.appendChild(input); | ||
|
|
||
| await trackEvent(DEVICE_CHECK_EVENT, { | ||
| is_camera_capable_mobile: true, | ||
| camera_present: !!cameraPresent, | ||
| grace_time: GRACE_TIME_FOR_CAMERA_CHECK_MS, | ||
| duration: Math.floor(duration), | ||
| }); | ||
| }, | ||
| ); | ||
|
|
||
| form.addEventListener('submit', (event) => { | ||
| event.preventDefault(); | ||
|
|
||
| for (const spinner of form.querySelectorAll('lg-spinner-button')) { | ||
| spinner.toggleSpinner(true); | ||
| } | ||
|
|
||
| Promise.race([delay(GRACE_TIME_FOR_CAMERA_CHECK_MS), cameraCheckPromise]).then(() => | ||
matthinz marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| form.submit(), | ||
| ); | ||
| }); | ||
| } | ||
|
|
||
| addFormInputsForMobileDeviceCapabilities(); | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
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.
(You'll want to compare this file with the .js version above, as I converted it to Typescript)