|
|
|
@ -1,8 +1,15 @@
@@ -1,8 +1,15 @@
|
|
|
|
|
import { useState } from "react"; |
|
|
|
|
import { useCallback, useEffect, useState } from "react"; |
|
|
|
|
import { GoogleReCaptcha, useGoogleReCaptcha } from "react-google-recaptcha-v3"; |
|
|
|
|
import { useAsyncFn } from "react-use"; |
|
|
|
|
|
|
|
|
|
import { Button } from "@/components/Button"; |
|
|
|
|
import { Input } from "@/components/player/internals/ContextMenu/Input"; |
|
|
|
|
import { Icon, Icons } from "@/components/Icon"; |
|
|
|
|
import { |
|
|
|
|
LargeCard, |
|
|
|
|
LargeCardButtons, |
|
|
|
|
LargeCardText, |
|
|
|
|
} from "@/components/layout/LargeCard"; |
|
|
|
|
import { AuthInputBox } from "@/components/text-inputs/AuthInputBox"; |
|
|
|
|
import { useAuth } from "@/hooks/auth/useAuth"; |
|
|
|
|
import { AccountProfile } from "@/pages/parts/auth/AccountCreatePart"; |
|
|
|
|
|
|
|
|
@ -16,10 +23,17 @@ export function VerifyPassphrase(props: VerifyPassphraseProps) {
@@ -16,10 +23,17 @@ export function VerifyPassphrase(props: VerifyPassphraseProps) {
|
|
|
|
|
const [mnemonic, setMnemonic] = useState(""); |
|
|
|
|
const { register, restore } = useAuth(); |
|
|
|
|
|
|
|
|
|
const { executeRecaptcha } = useGoogleReCaptcha(); |
|
|
|
|
|
|
|
|
|
const [result, execute] = useAsyncFn( |
|
|
|
|
async (inputMnemonic: string) => { |
|
|
|
|
const recaptchaToken = executeRecaptcha |
|
|
|
|
? await executeRecaptcha() |
|
|
|
|
: undefined; |
|
|
|
|
|
|
|
|
|
if (!props.mnemonic || !props.userData) |
|
|
|
|
throw new Error("invalid input data"); |
|
|
|
|
throw new Error("Data is not valid"); |
|
|
|
|
if (!recaptchaToken) throw new Error("ReCaptcha validation failed"); |
|
|
|
|
if (inputMnemonic !== props.mnemonic) |
|
|
|
|
throw new Error("Passphrase doesn't match"); |
|
|
|
|
|
|
|
|
@ -28,6 +42,7 @@ export function VerifyPassphrase(props: VerifyPassphraseProps) {
@@ -28,6 +42,7 @@ export function VerifyPassphrase(props: VerifyPassphraseProps) {
|
|
|
|
|
await register({ |
|
|
|
|
mnemonic: inputMnemonic, |
|
|
|
|
userData: props.userData, |
|
|
|
|
recaptchaToken, |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
// TODO import (and sort out conflicts)
|
|
|
|
@ -40,12 +55,29 @@ export function VerifyPassphrase(props: VerifyPassphraseProps) {
@@ -40,12 +55,29 @@ export function VerifyPassphrase(props: VerifyPassphraseProps) {
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
return ( |
|
|
|
|
<div> |
|
|
|
|
<p>verify passphrase</p> |
|
|
|
|
<Input value={mnemonic} onInput={setMnemonic} /> |
|
|
|
|
{result.loading ? <p>Loading...</p> : null} |
|
|
|
|
{result.error ? <p>error: {result.error.toString()}</p> : null} |
|
|
|
|
<Button onClick={() => execute(mnemonic)}>Register</Button> |
|
|
|
|
</div> |
|
|
|
|
<LargeCard> |
|
|
|
|
<LargeCardText |
|
|
|
|
icon={<Icon icon={Icons.CIRCLE_CHECK} />} |
|
|
|
|
title="Enter your passphrase" |
|
|
|
|
> |
|
|
|
|
If you've already lost it, how will you ever be able to take care |
|
|
|
|
of a child? |
|
|
|
|
</LargeCardText> |
|
|
|
|
<AuthInputBox |
|
|
|
|
label="Your passphrase" |
|
|
|
|
value={mnemonic} |
|
|
|
|
onChange={setMnemonic} |
|
|
|
|
/> |
|
|
|
|
{result.error ? ( |
|
|
|
|
<p className="mt-3 text-authentication-errorText"> |
|
|
|
|
{result.error.message} |
|
|
|
|
</p> |
|
|
|
|
) : null} |
|
|
|
|
<LargeCardButtons> |
|
|
|
|
<Button theme="purple" onClick={() => execute(mnemonic)}> |
|
|
|
|
Register |
|
|
|
|
</Button> |
|
|
|
|
</LargeCardButtons> |
|
|
|
|
</LargeCard> |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|