-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4ba357b
commit 132cf22
Showing
24 changed files
with
381 additions
and
36 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
24 changes: 24 additions & 0 deletions
24
account-kit/react/src/components/auth/card/loading/demoInput.tsx
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,24 @@ | ||
import type { InputHTMLAttributes } from "react"; | ||
import { Input } from "../../../input.js"; | ||
|
||
type DemoInputProps = Omit<InputHTMLAttributes<HTMLInputElement>, "ref">; | ||
|
||
/* | ||
* Input used for demoing new functionality. Should be replaced and deleted when | ||
* designs are ready. | ||
*/ | ||
export const DemoInput = (props: DemoInputProps) => { | ||
return ( | ||
<div className="relative"> | ||
<Input className="pointer-events-none" /> | ||
<Input | ||
{...props} | ||
className="absolute border-none bg-transparent left-0 top-0" | ||
style={{ | ||
transform: "rotate(10deg) scale(1.65)", | ||
transformOrigin: "0 50%", | ||
}} | ||
/> | ||
</div> | ||
); | ||
}; |
97 changes: 97 additions & 0 deletions
97
account-kit/react/src/components/auth/card/loading/otp.tsx
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,97 @@ | ||
import { useEffect, useState } from "react"; | ||
import { useSignerStatus } from "../../../../hooks/useSignerStatus.js"; | ||
import { EmailIllustration } from "../../../../icons/illustrations/email.js"; | ||
import { Spinner } from "../../../../icons/spinner.js"; | ||
import { ls } from "../../../../strings.js"; | ||
import { useAuthContext } from "../../context.js"; | ||
import { DemoInput } from "./demoInput.js"; | ||
import { Button } from "../../../button.js"; | ||
import { useAuthenticate } from "../../../../hooks/useAuthenticate.js"; | ||
import { ConnectionError } from "../error/connection-error.js"; | ||
|
||
// eslint-disable-next-line jsdoc/require-jsdoc | ||
export const LoadingOtp = () => { | ||
const { authStep } = useAuthContext("otp_verify"); | ||
const [otpCode, setOtpCode] = useState(""); | ||
const { setAuthStep } = useAuthContext(); | ||
|
||
const { authenticate } = useAuthenticate({ | ||
onMutate: () => { | ||
setAuthStep({ type: "otp_completing", email: authStep.email }); | ||
}, | ||
onError: (error: any) => { | ||
console.error(error); | ||
setAuthStep({ type: "otp_completing", email: authStep.email, error }); | ||
}, | ||
onSuccess: () => { | ||
setAuthStep({ type: "complete" }); | ||
}, | ||
}); | ||
|
||
return ( | ||
<div className="flex flex-col gap-5 items-center"> | ||
<div className="flex flex-col items-center justify-center h-12 w-12"> | ||
<EmailIllustration height="48" width="48" className="animate-pulse" /> | ||
</div> | ||
|
||
<h3 className="font-semibold text-lg">{ls.loadingEmail.title}</h3> | ||
<DemoInput | ||
value={otpCode} | ||
onChange={(event) => setOtpCode(event.currentTarget.value)} | ||
/> | ||
<Button | ||
onClick={() => { | ||
authenticate({ type: "otp", otpCode }); | ||
}} | ||
> | ||
Enter code | ||
</Button> | ||
<p className="text-fg-secondary text-center text-sm"> | ||
We sent a code to | ||
<br /> | ||
<span className="font-medium">{authStep.email}</span> | ||
</p> | ||
</div> | ||
); | ||
}; | ||
|
||
// eslint-disable-next-line jsdoc/require-jsdoc | ||
export const CompletingOtpAuth = () => { | ||
const { isConnected } = useSignerStatus(); | ||
const { authenticate } = useAuthenticate(); | ||
const { setAuthStep, authStep } = useAuthContext("otp_completing"); | ||
|
||
useEffect(() => { | ||
if (isConnected && authStep.createPasskeyAfter) { | ||
setAuthStep({ type: "passkey_create" }); | ||
} else if (isConnected) { | ||
setAuthStep({ type: "complete" }); | ||
} | ||
}, [authStep.createPasskeyAfter, isConnected, setAuthStep]); | ||
|
||
if (authStep.error) { | ||
return ( | ||
<ConnectionError | ||
connectionType="otp" | ||
handleTryAgain={() => { | ||
const { email } = authStep; | ||
setAuthStep({ type: "otp_verify", email }); | ||
authenticate({ type: "email", email, mode: "otp" }); | ||
}} | ||
handleUseAnotherMethod={() => setAuthStep({ type: "initial" })} | ||
/> | ||
); | ||
} | ||
|
||
return ( | ||
<div className="flex flex-col gap-5 items-center"> | ||
<div className="flex flex-col items-center justify-center h-12 w-12"> | ||
<Spinner /> | ||
</div> | ||
|
||
<p className="text-fg-secondary text-center text-sm"> | ||
{ls.completingOtp.body} | ||
</p> | ||
</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
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
Oops, something went wrong.