use components from ui-toolkit, add form-group, adjust input widths
This commit is contained in:
parent
9bffb15c2a
commit
847d51e060
@ -1,9 +1,7 @@
|
|||||||
import { InjectedConnector, RestConnector } from '@vegaprotocol/react-helpers';
|
import { RestConnector } from '@vegaprotocol/react-helpers';
|
||||||
|
|
||||||
export const injected = new InjectedConnector();
|
|
||||||
export const rest = new RestConnector();
|
export const rest = new RestConnector();
|
||||||
|
|
||||||
export const Connectors = {
|
export const Connectors = {
|
||||||
injected,
|
|
||||||
rest,
|
rest,
|
||||||
};
|
};
|
||||||
|
@ -64,10 +64,9 @@ export class RestConnector implements VegaConnector {
|
|||||||
// Store the token, and other things for later
|
// Store the token, and other things for later
|
||||||
this.setConfig({ connector: 'rest', token: res.token });
|
this.setConfig({ connector: 'rest', token: res.token });
|
||||||
|
|
||||||
return true;
|
return { success: true, error: null };
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(err);
|
return { success: false, error: err };
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { Button, Input, InputError } from '@vegaprotocol/ui-toolkit';
|
import { Button, FormGroup, Input, InputError } from '@vegaprotocol/ui-toolkit';
|
||||||
import { useState } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
import { useForm } from 'react-hook-form';
|
import { useForm } from 'react-hook-form';
|
||||||
import { RestConnector } from '.';
|
import { RestConnector } from '.';
|
||||||
|
|
||||||
@ -17,7 +17,7 @@ export function RestConnectorForm({
|
|||||||
connector,
|
connector,
|
||||||
onAuthenticate,
|
onAuthenticate,
|
||||||
}: RestConnectorFormProps) {
|
}: RestConnectorFormProps) {
|
||||||
const [error, setError] = useState<Error | null>(null);
|
const [error, setError] = useState('');
|
||||||
|
|
||||||
const {
|
const {
|
||||||
register,
|
register,
|
||||||
@ -27,62 +27,56 @@ export function RestConnectorForm({
|
|||||||
|
|
||||||
async function onSubmit(fields: FormFields) {
|
async function onSubmit(fields: FormFields) {
|
||||||
try {
|
try {
|
||||||
const success = await connector.authenticate({
|
setError('');
|
||||||
|
const res = await connector.authenticate({
|
||||||
wallet: fields.wallet,
|
wallet: fields.wallet,
|
||||||
passphrase: fields.passphrase,
|
passphrase: fields.passphrase,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (success) {
|
if (res.success) {
|
||||||
onAuthenticate();
|
onAuthenticate();
|
||||||
} else {
|
} else {
|
||||||
throw new Error('Authentication failed');
|
throw res.error;
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (err instanceof Error) {
|
if (err instanceof TypeError) {
|
||||||
setError(err);
|
setError('Wallet not running at http://localhost:1789');
|
||||||
} else if (typeof err === 'string') {
|
} else if (err instanceof Error) {
|
||||||
setError(new Error(err));
|
setError('Authentication failed');
|
||||||
} else {
|
} else {
|
||||||
setError(new Error('Something went wrong'));
|
setError('Something went wrong');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<form onSubmit={handleSubmit(onSubmit)}>
|
<form onSubmit={handleSubmit(onSubmit)}>
|
||||||
<div className="mb-12">
|
<FormGroup label="Wallet" labelFor="wallet">
|
||||||
<Input
|
<Input
|
||||||
className="w-full px-12 py-4 border-black border"
|
|
||||||
{...register('wallet', { required: 'Required' })}
|
{...register('wallet', { required: 'Required' })}
|
||||||
|
id="wallet"
|
||||||
type="text"
|
type="text"
|
||||||
placeholder="Wallet"
|
autoFocus={true}
|
||||||
/>
|
/>
|
||||||
{errors.wallet?.message && (
|
{errors.wallet?.message && (
|
||||||
<InputError
|
<InputError intent="danger">{errors.wallet.message}</InputError>
|
||||||
intent="danger"
|
|
||||||
className="mt-4 text-sm text-intent-danger"
|
|
||||||
>
|
|
||||||
{errors.wallet.message}
|
|
||||||
</InputError>
|
|
||||||
)}
|
)}
|
||||||
</div>
|
</FormGroup>
|
||||||
<div className="mb-12">
|
<FormGroup label="Passphrase" labelFor="passphrase">
|
||||||
<Input
|
<Input
|
||||||
className="w-full px-12 py-4 border-black border"
|
|
||||||
{...register('passphrase', { required: 'Required' })}
|
{...register('passphrase', { required: 'Required' })}
|
||||||
|
id="passphrase"
|
||||||
type="password"
|
type="password"
|
||||||
placeholder="Passphrase"
|
|
||||||
/>
|
/>
|
||||||
{errors.passphrase?.message && (
|
{errors.passphrase?.message && (
|
||||||
<InputError
|
<InputError intent="danger">{errors.passphrase.message}</InputError>
|
||||||
intent="danger"
|
|
||||||
className="mt-4 text-sm text-intent-danger"
|
|
||||||
>
|
|
||||||
{errors.passphrase.message}
|
|
||||||
</InputError>
|
|
||||||
)}
|
)}
|
||||||
</div>
|
</FormGroup>
|
||||||
{error && <div className="mb-12 text-intent-danger">{error.message}</div>}
|
{error && (
|
||||||
|
<InputError intent="danger" className="mb-12">
|
||||||
|
{error}
|
||||||
|
</InputError>
|
||||||
|
)}
|
||||||
<Button variant="primary" type="submit">
|
<Button variant="primary" type="submit">
|
||||||
Connect
|
Connect
|
||||||
</Button>
|
</Button>
|
||||||
|
20
libs/ui-toolkit/src/components/form-group/index.tsx
Normal file
20
libs/ui-toolkit/src/components/form-group/index.tsx
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
import { ReactNode } from 'react';
|
||||||
|
|
||||||
|
interface FormGroupProps {
|
||||||
|
children: ReactNode;
|
||||||
|
label: string;
|
||||||
|
labelFor: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const FormGroup = ({ children, label, labelFor }: FormGroupProps) => {
|
||||||
|
return (
|
||||||
|
<div className="mb-12">
|
||||||
|
{label && (
|
||||||
|
<label className="block text-ui" htmlFor={labelFor}>
|
||||||
|
{label}
|
||||||
|
</label>
|
||||||
|
)}
|
||||||
|
{children}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
@ -14,7 +14,7 @@ export const InputError = ({
|
|||||||
}: InputErrorProps) => {
|
}: InputErrorProps) => {
|
||||||
const effectiveClassName = classNames(
|
const effectiveClassName = classNames(
|
||||||
[
|
[
|
||||||
'inline-flex',
|
'flex',
|
||||||
'items-center',
|
'items-center',
|
||||||
'box-border',
|
'box-border',
|
||||||
'h-28',
|
'h-28',
|
||||||
|
@ -22,8 +22,7 @@ export const inputClassNames = ({
|
|||||||
}) => {
|
}) => {
|
||||||
return classNames(
|
return classNames(
|
||||||
[
|
[
|
||||||
'inline-flex',
|
'flex items-center w-full',
|
||||||
'items-center',
|
|
||||||
'box-border',
|
'box-border',
|
||||||
'border',
|
'border',
|
||||||
'bg-clip-padding',
|
'bg-clip-padding',
|
||||||
|
@ -4,6 +4,7 @@ export { Button, AnchorButton } from './components/button';
|
|||||||
export { Callout } from './components/callout';
|
export { Callout } from './components/callout';
|
||||||
export { EthereumUtils };
|
export { EthereumUtils };
|
||||||
export { EtherscanLink } from './components/etherscan-link';
|
export { EtherscanLink } from './components/etherscan-link';
|
||||||
|
export { FormGroup } from './components/form-group';
|
||||||
export { Icon } from './components/icon';
|
export { Icon } from './components/icon';
|
||||||
export { Input } from './components/input';
|
export { Input } from './components/input';
|
||||||
export { InputError } from './components/input-error';
|
export { InputError } from './components/input-error';
|
||||||
|
Loading…
Reference in New Issue
Block a user