-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(wallet): ask for user password on certain card actions (#1770)
Ask for password on certain card actions
- Loading branch information
1 parent
64b6ac4
commit fc4cc3a
Showing
10 changed files
with
231 additions
and
99 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
77 changes: 77 additions & 0 deletions
77
packages/wallet/frontend/src/components/dialogs/PasswordDialog.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,77 @@ | ||
import { | ||
Dialog, | ||
DialogPanel, | ||
DialogTitle, | ||
Transition, | ||
TransitionChild | ||
} from '@headlessui/react' | ||
import { Fragment } from 'react' | ||
import type { DialogProps } from '@/lib/types/dialog' | ||
import { useZodForm } from '@/lib/hooks/useZodForm' | ||
import { passwordSchema } from '@/lib/api/user' | ||
import { Form } from '@/ui/forms/Form' | ||
import { Input } from '@/ui/forms/Input' | ||
import { Button } from '@/ui/Button' | ||
|
||
type PasswordDialogProps = Pick<DialogProps, 'onClose'> & { | ||
title: string | ||
onSubmit: (password: string) => Promise<void> | ||
} | ||
|
||
export const PasswordDialog = ({ | ||
title, | ||
onClose, | ||
onSubmit | ||
}: PasswordDialogProps) => { | ||
const form = useZodForm({ | ||
schema: passwordSchema | ||
}) | ||
return ( | ||
<Transition show={true} as={Fragment} appear={true}> | ||
<Dialog as="div" className="relative z-10" onClose={onClose}> | ||
<TransitionChild | ||
as={Fragment} | ||
leave="ease-in duration-200" | ||
leaveFrom="opacity-100" | ||
leaveTo="opacity-0" | ||
> | ||
<div className="fixed inset-0 bg-green-modal/75 transition-opacity dark:bg-black/75" /> | ||
</TransitionChild> | ||
|
||
<div className="fixed inset-0 z-10 overflow-y-auto"> | ||
<div className="flex min-h-full items-center justify-center p-4"> | ||
<TransitionChild | ||
as={Fragment} | ||
leave="ease-in duration-200" | ||
leaveFrom="opacity-100 translate-y-0" | ||
leaveTo="opacity-0 translate-y-4" | ||
> | ||
<DialogPanel className="relative w-full max-w-sm space-y-4 overflow-hidden rounded-lg bg-white p-8 shadow-xl dark:bg-purple"> | ||
<DialogTitle as="h3" className="text-center text-2xl font-bold"> | ||
{title} | ||
</DialogTitle> | ||
<Form | ||
form={form} | ||
onSubmit={async (data) => { | ||
await onSubmit(data.password) | ||
}} | ||
> | ||
<Input | ||
required | ||
type="password" | ||
{...form.register('password')} | ||
error={form.formState.errors.password?.message} | ||
label="Password" | ||
/> | ||
<Button type="submit" intent="primary" aria-label={title}> | ||
Submit | ||
</Button> | ||
</Form> | ||
</DialogPanel> | ||
</TransitionChild> | ||
</div> | ||
</div> | ||
</Dialog> | ||
</Transition> | ||
) | ||
} |
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.