Skip to content

Commit

Permalink
refactor(popup/ErrorKeyRevoked): remove react-hook-form (#705)
Browse files Browse the repository at this point in the history
  • Loading branch information
sidvishnoi authored Nov 11, 2024
1 parent 48caf57 commit 5cbe5db
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 25 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
"loglevel": "^1.9.2",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-hook-form": "^7.53.0",
"react-router-dom": "^6.26.2",
"safe-buffer": "5.2.1",
"tailwind-merge": "^2.5.2",
Expand Down
13 changes: 0 additions & 13 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 16 additions & 11 deletions src/popup/components/ErrorKeyRevoked.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React from 'react';
import { useForm } from 'react-hook-form';
import { AnimatePresence, m } from 'framer-motion';
import { WarningSign } from '@/popup/components/Icons';
import { Button } from '@/popup/components/ui/Button';
Expand Down Expand Up @@ -129,26 +128,29 @@ const ReconnectScreen = ({
reconnectWallet,
onReconnect,
}: ReconnectScreenProps) => {
type Errors = Record<'root', null | { message: string }>;

const t = useTranslation();
const {
handleSubmit,
formState: { errors, isSubmitting },
clearErrors,
setError,
} = useForm({ criteriaMode: 'firstError', mode: 'onSubmit' });

const [isSubmitting, setIsSubmitting] = React.useState(false);
const [errors, setErrors] = React.useState<Errors>({
root: null,
});

const requestReconnect = async () => {
clearErrors();
setErrors({ root: null });
try {
setIsSubmitting(true);
const res = await reconnectWallet();
if (res.success) {
onReconnect?.();
} else {
setError('root', { message: res.message });
setErrors({ root: { message: res.message } });
}
} catch (error) {
setError('root', { message: error.message });
setErrors({ root: { message: error.message } });
}
setIsSubmitting(false);
};

return (
Expand All @@ -157,7 +159,10 @@ const ReconnectScreen = ({
animate={{ opacity: 1 }}
exit={{ opacity: 0 }}
className="flex flex-col items-stretch gap-4"
onSubmit={handleSubmit(requestReconnect)}
onSubmit={(ev) => {
ev.preventDefault();
requestReconnect();
}}
>
<div className="space-y-1 text-sm">
<p className="px-2">
Expand Down

0 comments on commit 5cbe5db

Please sign in to comment.