remove hard coded vega wallet auth values

This commit is contained in:
Matthew Russell 2022-02-28 14:58:34 -08:00
parent 77214d5427
commit 4bcafea969

View File

@ -1,3 +1,4 @@
import { useState } from 'react';
import { useForm } from 'react-hook-form'; import { useForm } from 'react-hook-form';
import { RestConnector } from '.'; import { RestConnector } from '.';
@ -15,17 +16,13 @@ export function RestConnectorForm({
connector, connector,
onAuthenticate, onAuthenticate,
}: RestConnectorFormProps) { }: RestConnectorFormProps) {
const [error, setError] = useState<Error | null>(null);
const { const {
register, register,
handleSubmit, handleSubmit,
formState: { errors }, formState: { errors },
} = useForm<FormFields>({ } = useForm<FormFields>();
// TODO: Remove default values
defaultValues: {
wallet: 'matt',
passphrase: '123',
},
});
async function onSubmit(fields: FormFields) { async function onSubmit(fields: FormFields) {
try { try {
@ -40,30 +37,45 @@ export function RestConnectorForm({
throw new Error('Authentication failed'); throw new Error('Authentication failed');
} }
} catch (err) { } catch (err) {
console.error(err); if (err instanceof Error) {
setError(err);
} else if (typeof err === 'string') {
setError(new Error(err));
} else {
setError(new Error('Something went wrong'));
}
} }
} }
return ( return (
<form onSubmit={handleSubmit(onSubmit)}> <form onSubmit={handleSubmit(onSubmit)}>
<div style={{ marginBottom: 10 }}> <div className="mb-12">
<input <input
className="w-full px-8 py-2 border-black border" className="w-full px-8 py-2 border-black border"
{...register('wallet', { required: 'Required' })} {...register('wallet', { required: 'Required' })}
type="text" type="text"
placeholder="Wallet" placeholder="Wallet"
/> />
{errors.wallet?.message && <div>{errors.wallet.message}</div>} {errors.wallet?.message && (
<div className="mt-4 text-sm text-intent-danger">
{errors.wallet.message}
</div>
)}
</div> </div>
<div style={{ marginBottom: 10 }}> <div className="mb-12">
<input <input
className="w-full px-8 py-2 border-black border" className="w-full px-8 py-2 border-black border"
{...register('passphrase', { required: 'Required' })} {...register('passphrase', { required: 'Required' })}
type="text" type="password"
placeholder="Passphrase" placeholder="Passphrase"
/> />
{errors.passphrase?.message && <div>{errors.passphrase.message}</div>} {errors.passphrase?.message && (
<div className="mt-4 text-sm text-intent-danger">
{errors.passphrase.message}
</div>
)}
</div> </div>
{error && <div className="mb-12 text-intent-danger">{error.message}</div>}
<button type="submit" className="rounded-sm bg-pink text-white py-4 px-8"> <button type="submit" className="rounded-sm bg-pink text-white py-4 px-8">
Connect Connect
</button> </button>