diff --git a/apps/deploy-web/src/components/turnstile/Turnstile.tsx b/apps/deploy-web/src/components/turnstile/Turnstile.tsx index 333f20109..e7566034d 100644 --- a/apps/deploy-web/src/components/turnstile/Turnstile.tsx +++ b/apps/deploy-web/src/components/turnstile/Turnstile.tsx @@ -7,31 +7,56 @@ import { Turnstile as ReactTurnstile, TurnstileInstance } from "@marsidev/react- import classnames from "classnames"; import { browserEnvConfig } from "@src/config/browser-env.config"; +import { useWhen } from "@src/hooks/useWhen"; -type TurnstileStatus = "uninitialized" | "solved" | "interactive" | "expired" | "error" | "dismissed"; +type TurnstileStatus = "uninitialized" | "solved" | "interactive" | "expired" | "error" | "dismissed" | "retrying"; -const VISIBILITY_STATUSES: TurnstileStatus[] = ["uninitialized", "interactive", "error"]; +const VISIBILITY_STATUSES: TurnstileStatus[] = ["interactive", "error", "retrying"]; export const Turnstile: FC = () => { const turnstileRef = useRef(); const [status, setStatus] = useState("uninitialized"); const [isTimingOut, setIsTimingOut] = useState(false); - const isVisible = useMemo(() => !!browserEnvConfig.NEXT_PUBLIC_TURNSTILE_ENABLED && VISIBILITY_STATUSES.includes(status), [status]); + const [isVisible, setIsVisible] = useState(false); + const [shouldHide, setShouldHide] = useState(true); const hasActions = useMemo(() => isTimingOut || status === "error", [isTimingOut, status]); useEffect(() => { - if (isVisible) { - const timeout = setTimeout(() => { - setIsTimingOut(true); - }, 5000); + if (!browserEnvConfig.NEXT_PUBLIC_TURNSTILE_ENABLED) { + setIsVisible(false); + } - return () => clearTimeout(timeout); + if (VISIBILITY_STATUSES.includes(status)) { + setIsVisible(true); + setShouldHide(false); + } else if (isVisible && status === "dismissed") { + setShouldHide(true); + } else if (isVisible) { + setTimeout(() => setShouldHide(true), 1000); } - }, [isVisible]); + }, [isVisible, status]); + + useWhen(isVisible, () => { + setTimeout(() => setIsTimingOut(true), 5000); + }); + + useWhen(shouldHide, () => { + setTimeout(() => setIsVisible(false), 400); + }); return browserEnvConfig.NEXT_PUBLIC_TURNSTILE_ENABLED ? ( <> -
+

We are verifying you are a human. This may take a few seconds

Reviewing the security of your connection before proceeding

@@ -39,7 +64,17 @@ export const Turnstile: FC = () => { setStatus("error")} + onError={() => + setStatus(prevStatus => { + if (prevStatus === "retrying") { + return "error"; + } + + turnstileRef.current?.reset(); + + return "retrying"; + }) + } onExpire={() => setStatus("expired")} onSuccess={() => setStatus("solved")} onBeforeInteractive={() => setStatus("interactive")} diff --git a/package-lock.json b/package-lock.json index 4889855f9..d39576a0d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -33,7 +33,7 @@ }, "apps/api": { "name": "@akashnetwork/console-api", - "version": "2.46.0", + "version": "2.50.0", "license": "Apache-2.0", "dependencies": { "@akashnetwork/akash-api": "^1.3.0", @@ -229,7 +229,7 @@ }, "apps/deploy-web": { "name": "@akashnetwork/console-web", - "version": "2.29.0", + "version": "2.30.1", "license": "Apache-2.0", "dependencies": { "@akashnetwork/akash-api": "^1.3.0",