diff --git a/src/screens/Signup/StepCaptcha/CaptchaWebView.tsx b/src/screens/Signup/StepCaptcha/CaptchaWebView.tsx index 2be37ba24f..1db6eb8168 100644 --- a/src/screens/Signup/StepCaptcha/CaptchaWebView.tsx +++ b/src/screens/Signup/StepCaptcha/CaptchaWebView.tsx @@ -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() + + 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], ) diff --git a/src/screens/Signup/StepCaptcha/index.tsx b/src/screens/Signup/StepCaptcha/index.tsx index a3518de6e8..d984faf711 100644 --- a/src/screens/Signup/StepCaptcha/index.tsx +++ b/src/screens/Signup/StepCaptcha/index.tsx @@ -92,8 +92,6 @@ function StepCaptchaInner({ } } - console.log(newUrl.href) - return newUrl.href }, [ state.serviceUrl,