-
Notifications
You must be signed in to change notification settings - Fork 128
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
sim
committed
Jan 17, 2022
1 parent
bbaf9a7
commit c43a179
Showing
13 changed files
with
199 additions
and
66 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,25 @@ | ||
import { ButtonHTMLAttributes } from "react" | ||
import { Link, LinkProps } from "react-router-dom" | ||
import classNames from "classnames/bind" | ||
import styles from "./AuthButton.module.scss" | ||
|
||
const cx = classNames.bind(styles) | ||
|
||
interface Props extends ButtonHTMLAttributes<HTMLButtonElement> { | ||
interface ButtonAttrs extends ButtonHTMLAttributes<HTMLButtonElement> { | ||
active: boolean | ||
} | ||
|
||
interface LinkAttrs extends LinkProps { | ||
active: boolean | ||
} | ||
|
||
type Props = ButtonAttrs | LinkAttrs | ||
|
||
const AuthButton = ({ active, ...attrs }: Props) => { | ||
return ( | ||
<button | ||
{...attrs} | ||
type="button" | ||
className={cx(styles.button, { active }, attrs.className)} | ||
/> | ||
) | ||
const className = cx(styles.button, { active }, attrs.className) | ||
if (active) return <span {...attrs} className={className} /> | ||
if ("to" in attrs) return <Link {...attrs} className={className} /> | ||
return <button {...attrs} type="button" className={className} /> | ||
} | ||
|
||
export default AuthButton |
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 was deleted.
Oops, something went wrong.
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,56 @@ | ||
import { useTranslation } from "react-i18next" | ||
import { useNavigate, useParams } from "react-router-dom" | ||
import { useForm } from "react-hook-form" | ||
import { Form, FormItem } from "components/form" | ||
import { Input, Submit } from "components/form" | ||
import { testPassword, unlockWallet } from "../../scripts/keystore" | ||
import useAuth from "../../hooks/useAuth" | ||
|
||
interface Values { | ||
password: string | ||
} | ||
|
||
const UnlockForm = () => { | ||
const { t } = useTranslation() | ||
const { name } = useParams() | ||
const navigate = useNavigate() | ||
const { connect } = useAuth() | ||
|
||
if (!name) throw new Error("Invalid path") | ||
|
||
/* form */ | ||
const form = useForm<Values>({ mode: "onChange" }) | ||
const { register, handleSubmit, formState } = form | ||
const { errors, isValid } = formState | ||
|
||
/* submit */ | ||
const submit = ({ password }: Values) => { | ||
unlockWallet(name, password) | ||
connect(name) | ||
navigate("/wallet", { replace: true }) | ||
} | ||
|
||
return ( | ||
<Form onSubmit={handleSubmit(submit)}> | ||
<FormItem label={t("Password")} error={errors.password?.message}> | ||
<Input | ||
{...register("password", { | ||
validate: (password) => { | ||
try { | ||
testPassword({ name, password }) | ||
} catch { | ||
return "Incorrect password" | ||
} | ||
}, | ||
})} | ||
type="password" | ||
autoFocus | ||
/> | ||
</FormItem> | ||
|
||
<Submit disabled={!isValid} /> | ||
</Form> | ||
) | ||
} | ||
|
||
export default UnlockForm |
Oops, something went wrong.