add a minimum delay
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import React from 'react'
|
import React, {useEffect, useRef} from 'react'
|
||||||
import {StyleSheet} from 'react-native'
|
import {StyleSheet} from 'react-native'
|
||||||
import {WebView, type WebViewNavigation} from 'react-native-webview'
|
import {WebView, type WebViewNavigation} from 'react-native-webview'
|
||||||
import {type ShouldStartLoadRequest} from 'react-native-webview/lib/WebViewTypes'
|
import {type ShouldStartLoadRequest} from 'react-native-webview/lib/WebViewTypes'
|
||||||
@@ -17,6 +17,8 @@ const ALLOWED_HOSTS = [
|
|||||||
'e9755d3e012b.ngrok.app',
|
'e9755d3e012b.ngrok.app',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
const MIN_DELAY = 3_500
|
||||||
|
|
||||||
export function CaptchaWebView({
|
export function CaptchaWebView({
|
||||||
url,
|
url,
|
||||||
stateParam,
|
stateParam,
|
||||||
@@ -30,6 +32,17 @@ export function CaptchaWebView({
|
|||||||
onSuccess: (code: string) => void
|
onSuccess: (code: string) => void
|
||||||
onError: (error: unknown) => 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(() => {
|
const redirectHost = React.useMemo(() => {
|
||||||
if (!state?.serviceUrl) return 'bsky.app'
|
if (!state?.serviceUrl) return 'bsky.app'
|
||||||
|
|
||||||
@@ -62,8 +75,17 @@ export function CaptchaWebView({
|
|||||||
return
|
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
|
wasSuccessful.current = true
|
||||||
|
const now = Date.now()
|
||||||
|
const timeTaken = now - startedAt.current
|
||||||
|
if (timeTaken < MIN_DELAY) {
|
||||||
|
successTo.current = setTimeout(() => {
|
||||||
onSuccess(code)
|
onSuccess(code)
|
||||||
|
}, MIN_DELAY - timeTaken)
|
||||||
|
} else {
|
||||||
|
onSuccess(code)
|
||||||
|
}
|
||||||
},
|
},
|
||||||
[redirectHost, stateParam, onSuccess, onError],
|
[redirectHost, stateParam, onSuccess, onError],
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -92,8 +92,6 @@ function StepCaptchaInner({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(newUrl.href)
|
|
||||||
|
|
||||||
return newUrl.href
|
return newUrl.href
|
||||||
}, [
|
}, [
|
||||||
state.serviceUrl,
|
state.serviceUrl,
|
||||||
|
|||||||
Reference in New Issue
Block a user