import { Button, FormGroup, Input, InputError } from '@vegaprotocol/ui-toolkit'; import { useState } from 'react'; import { useForm } from 'react-hook-form'; import { RestConnector } from '.'; interface FormFields { wallet: string; passphrase: string; } interface RestConnectorFormProps { connector: RestConnector; onAuthenticate: () => void; } export function RestConnectorForm({ connector, onAuthenticate, }: RestConnectorFormProps) { const [error, setError] = useState(''); const { register, handleSubmit, formState: { errors }, } = useForm(); async function onSubmit(fields: FormFields) { try { setError(''); const res = await connector.authenticate({ wallet: fields.wallet, passphrase: fields.passphrase, }); if (res.success) { onAuthenticate(); } else { throw res.error; } } catch (err) { if (err instanceof TypeError) { setError('Wallet not running at http://localhost:1789'); } else if (err instanceof Error) { setError('Authentication failed'); } else { setError('Something went wrong'); } } } return (
{errors.wallet?.message && ( {errors.wallet.message} )} {errors.passphrase?.message && ( {errors.passphrase.message} )} {error && (

{error}

)}
); }