add a minimum delay

This commit is contained in:
Hailey
2025-08-05 08:32:24 -07:00
parent b4661b28ed
commit 47ca4d5728
2 changed files with 24 additions and 4 deletions
@@ -1,4 +1,4 @@
import React from 'react'
import React, {useEffect, useRef} from 'react'
import {StyleSheet} from 'react-native'
import {WebView, type WebViewNavigation} from 'react-native-webview'
import {type ShouldStartLoadRequest} from 'react-native-webview/lib/WebViewTypes'
@@ -17,6 +17,8 @@ const ALLOWED_HOSTS = [
'e9755d3e012b.ngrok.app',
]
const MIN_DELAY = 3_500
export function CaptchaWebView({
url,
stateParam,
@@ -30,6 +32,17 @@ export function CaptchaWebView({
onSuccess: (code: string) => void
onError: (error: unknown) => void
}) {
const startedAt = useRef(Date.now())
const successTo = useRef<NodeJS.Timeout>()
useEffect(() => {
return () => {
if (successTo) {
clearTimeout(successTo.current)
}
}
}, [])
const redirectHost = React.useMemo(() => {
if (!state?.serviceUrl) return 'bsky.app'
@@ -62,8 +75,17 @@ export function CaptchaWebView({
return
}
// We want to delay the completion of this screen ever so slightly so that it doesn't appear to be a glitch if it completes too fast
wasSuccessful.current = true
onSuccess(code)
const now = Date.now()
const timeTaken = now - startedAt.current
if (timeTaken < MIN_DELAY) {
successTo.current = setTimeout(() => {
onSuccess(code)
}, MIN_DELAY - timeTaken)
} else {
onSuccess(code)
}
},
[redirectHost, stateParam, onSuccess, onError],
)
-2
View File
@@ -92,8 +92,6 @@ function StepCaptchaInner({
}
}
console.log(newUrl.href)
return newUrl.href
}, [
state.serviceUrl,