-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #362 from algorandfoundation/use-wallet-prompt
feat: use a custom form to prompt for KMD password and mnemonic
- Loading branch information
Showing
4 changed files
with
114 additions
and
34 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { useCallback } from 'react' | ||
import { zfd } from 'zod-form-data' | ||
import { z } from 'zod' | ||
import { Form } from '@/features/forms/components/form' | ||
import { FormActions } from '@/features/forms/components/form-actions' | ||
import { SubmitButton } from '@/features/forms/components/submit-button' | ||
import { CancelButton } from '@/features/forms/components/cancel-button' | ||
|
||
type Props = { | ||
message: string | ||
type: 'text' | 'password' | ||
onSubmit: (value: string | null) => void | ||
onCancel: () => void | ||
} | ||
|
||
const schema = zfd.formData({ | ||
value: zfd.text(z.string().optional()), | ||
}) | ||
|
||
export function PromptForm({ message, type, onSubmit, onCancel }: Props) { | ||
const submit = useCallback( | ||
async (values: z.infer<typeof schema>) => { | ||
onSubmit(values.value ?? '') | ||
}, | ||
[onSubmit] | ||
) | ||
|
||
return ( | ||
<Form | ||
schema={schema} | ||
onSubmit={submit} | ||
formAction={ | ||
<FormActions> | ||
<CancelButton onClick={onCancel} className="w-28" /> | ||
<SubmitButton className="w-28">Save</SubmitButton> | ||
</FormActions> | ||
} | ||
> | ||
{(helper) => | ||
type === 'text' ? helper.textField({ label: message, field: 'value' }) : helper.passwordField({ label: message, field: 'value' }) | ||
} | ||
</Form> | ||
) | ||
} |
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