-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
9 changed files
with
145 additions
and
47 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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,75 @@ | ||
"use client"; | ||
|
||
import { FC, useEffect, useMemo, useRef, useState } from "react"; | ||
import { MdInfo } from "react-icons/md"; | ||
import { Button } from "@akashnetwork/ui/components"; | ||
import { Turnstile as ReactTurnstile, TurnstileInstance } from "@marsidev/react-turnstile"; | ||
import classnames from "classnames"; | ||
|
||
import { browserEnvConfig } from "@src/config/browser-env.config"; | ||
|
||
type TurnstileStatus = "uninitialized" | "solved" | "expired" | "error" | "dismissed"; | ||
|
||
const VISIBILITY_STATUSES: TurnstileStatus[] = ["uninitialized", "expired", "error"]; | ||
|
||
export const Turnstile: FC = () => { | ||
const turnstileRef = useRef<TurnstileInstance>(); | ||
const [status, setStatus] = useState<TurnstileStatus>("uninitialized"); | ||
const [isTimingOut, setIsTimingOut] = useState(false); | ||
const isVisible = useMemo(() => !!browserEnvConfig.NEXT_PUBLIC_TURNSTILE_SITE_KEY && VISIBILITY_STATUSES.includes(status), [status]); | ||
const hasActions = useMemo(() => isTimingOut || status === "error", [isTimingOut, status]); | ||
|
||
useEffect(() => { | ||
if (isVisible) { | ||
const timeout = setTimeout(() => { | ||
setIsTimingOut(true); | ||
}, 5000); | ||
|
||
return () => clearTimeout(timeout); | ||
} | ||
}, [isVisible]); | ||
|
||
return ( | ||
<> | ||
<div className={classnames({ hidden: !isVisible }, "fixed inset-0 z-[101] flex content-center items-center justify-center bg-white bg-opacity-90")}> | ||
<div className="flex flex-col items-center"> | ||
<h3 className="mb-2 text-2xl font-bold">We are verifying you are a human. This may take a few seconds</h3> | ||
<p className="mb-8">Reviewing the security of your connection before proceeding</p> | ||
<div className="h-[66px]"> | ||
<ReactTurnstile | ||
ref={turnstileRef} | ||
siteKey={browserEnvConfig.NEXT_PUBLIC_TURNSTILE_SITE_KEY} | ||
onError={() => setStatus("error")} | ||
onExpire={() => setStatus("expired")} | ||
onSuccess={() => setStatus("solved")} | ||
/> | ||
</div> | ||
{status === "error" && <p className="text-red-600">Some error occurred</p>} | ||
<div | ||
className={classnames( | ||
{ | ||
"invisible opacity-0": !hasActions, | ||
"visible opacity-100": hasActions | ||
}, | ||
"flex flex-col items-center transition-opacity duration-200" | ||
)} | ||
> | ||
<div className="my-8"> | ||
<Button onClick={turnstileRef.current?.reset} className="mr-4"> | ||
Retry | ||
</Button> | ||
<Button onClick={() => setStatus("dismissed")} variant="link"> | ||
Dismiss | ||
</Button> | ||
</div> | ||
|
||
<p> | ||
<MdInfo className="mr-1 inline text-xl text-muted-foreground" /> | ||
<small>dismissing the check might result into some features not working properly</small> | ||
</p> | ||
</div> | ||
</div> | ||
</div> | ||
</> | ||
); | ||
}; |
This file contains 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 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 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.