9941c9bfaa
* fix: deposits tests, also convert to basic cypress * add new home tests which test redirect to trading page and markets page * chore: replace portfolio page feature with raw cypress * chore: replace market page feature with raw cypress tests * chore: replace home page tests with global.ts for wallet connections * chore: add raw cypress withdrawals tests with mocks * fix: complete withdrawals prompt and add assertion for it * chore: remove unnecessary cypress envs now that we are mocking assets * chore: ignore lint errors temporarily * chore: add mock for deposit page query, add wait for mocked queries to resolve * fix: order of waiting for withdraw page query * fix: validate vega wallet connection * chore: remove rest of page objects and convert trading page feature to regular cypress * fix: assertion on transaction dialog after withdrawal * chore: split withdraw and withdrawals pages into separate files * chore: split trading tests into own files, connect wallet once for deal ticket * feat: convert home page tests to raw cypress
91 lines
2.3 KiB
TypeScript
91 lines
2.3 KiB
TypeScript
import { t } from '@vegaprotocol/react-helpers';
|
|
import { Button, FormGroup, Input, InputError } from '@vegaprotocol/ui-toolkit';
|
|
import { useState } from 'react';
|
|
import { useForm } from 'react-hook-form';
|
|
import type { 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<FormFields>();
|
|
|
|
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(t('Wallet not running at http://localhost:1789'));
|
|
} else if (err instanceof Error) {
|
|
setError(t('Authentication failed'));
|
|
} else {
|
|
setError(t('Something went wrong'));
|
|
}
|
|
}
|
|
}
|
|
|
|
return (
|
|
<form onSubmit={handleSubmit(onSubmit)} data-testid="rest-connector-form">
|
|
<FormGroup label={t('Wallet')} labelFor="wallet">
|
|
<Input
|
|
{...register('wallet', { required: t('Required') })}
|
|
id="wallet"
|
|
type="text"
|
|
autoFocus={true}
|
|
/>
|
|
{errors.wallet?.message && (
|
|
<InputError intent="danger" className="mt-4">
|
|
{errors.wallet.message}
|
|
</InputError>
|
|
)}
|
|
</FormGroup>
|
|
<FormGroup label={t('Passphrase')} labelFor="passphrase">
|
|
<Input
|
|
{...register('passphrase', { required: t('Required') })}
|
|
id="passphrase"
|
|
type="password"
|
|
/>
|
|
{errors.passphrase?.message && (
|
|
<InputError intent="danger" className="mt-4">
|
|
{errors.passphrase.message}
|
|
</InputError>
|
|
)}
|
|
</FormGroup>
|
|
{error && (
|
|
<p className="text-danger mb-12" data-testid="form-error">
|
|
{error}
|
|
</p>
|
|
)}
|
|
<Button variant="primary" type="submit">
|
|
{t('Connect')}
|
|
</Button>
|
|
</form>
|
|
);
|
|
}
|