2022-03-31 01:08:25 +00:00
|
|
|
import { t } from '@vegaprotocol/react-helpers';
|
2022-03-08 18:23:01 +00:00
|
|
|
import { Button, FormGroup, Input, InputError } from '@vegaprotocol/ui-toolkit';
|
2022-03-08 18:57:07 +00:00
|
|
|
import { useState } from 'react';
|
2022-02-22 06:40:55 +00:00
|
|
|
import { useForm } from 'react-hook-form';
|
2022-03-30 09:49:48 +00:00
|
|
|
import type { RestConnector } from '.';
|
2022-02-22 06:40:55 +00:00
|
|
|
|
|
|
|
interface FormFields {
|
|
|
|
wallet: string;
|
|
|
|
passphrase: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
interface RestConnectorFormProps {
|
2022-02-22 23:06:35 +00:00
|
|
|
connector: RestConnector;
|
|
|
|
onAuthenticate: () => void;
|
2022-02-22 06:40:55 +00:00
|
|
|
}
|
|
|
|
|
2022-02-22 23:06:35 +00:00
|
|
|
export function RestConnectorForm({
|
|
|
|
connector,
|
|
|
|
onAuthenticate,
|
|
|
|
}: RestConnectorFormProps) {
|
2022-03-08 18:23:01 +00:00
|
|
|
const [error, setError] = useState('');
|
2022-02-28 22:58:34 +00:00
|
|
|
|
2022-02-22 23:06:35 +00:00
|
|
|
const {
|
|
|
|
register,
|
|
|
|
handleSubmit,
|
|
|
|
formState: { errors },
|
2022-02-28 22:58:34 +00:00
|
|
|
} = useForm<FormFields>();
|
2022-02-22 06:40:55 +00:00
|
|
|
|
|
|
|
async function onSubmit(fields: FormFields) {
|
|
|
|
try {
|
2022-03-08 18:23:01 +00:00
|
|
|
setError('');
|
|
|
|
const res = await connector.authenticate({
|
2022-02-22 06:40:55 +00:00
|
|
|
wallet: fields.wallet,
|
|
|
|
passphrase: fields.passphrase,
|
|
|
|
});
|
|
|
|
|
2022-03-08 18:23:01 +00:00
|
|
|
if (res.success) {
|
2022-02-22 23:06:35 +00:00
|
|
|
onAuthenticate();
|
2022-02-22 06:40:55 +00:00
|
|
|
} else {
|
2022-03-08 18:23:01 +00:00
|
|
|
throw res.error;
|
2022-02-22 06:40:55 +00:00
|
|
|
}
|
|
|
|
} catch (err) {
|
2022-03-08 18:23:01 +00:00
|
|
|
if (err instanceof TypeError) {
|
2022-03-31 01:08:25 +00:00
|
|
|
setError(t('Wallet not running at http://localhost:1789'));
|
2022-03-08 18:23:01 +00:00
|
|
|
} else if (err instanceof Error) {
|
2022-03-31 01:08:25 +00:00
|
|
|
setError(t('Authentication failed'));
|
2022-02-28 22:58:34 +00:00
|
|
|
} else {
|
2022-03-31 01:08:25 +00:00
|
|
|
setError(t('Something went wrong'));
|
2022-02-28 22:58:34 +00:00
|
|
|
}
|
2022-02-22 06:40:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2022-03-10 23:42:55 +00:00
|
|
|
<form onSubmit={handleSubmit(onSubmit)} data-testid="rest-connector-form">
|
2022-03-31 01:08:25 +00:00
|
|
|
<FormGroup label={t('Wallet')} labelFor="wallet">
|
2022-03-08 18:13:52 +00:00
|
|
|
<Input
|
2022-03-31 01:08:25 +00:00
|
|
|
{...register('wallet', { required: t('Required') })}
|
2022-03-08 18:23:01 +00:00
|
|
|
id="wallet"
|
2022-02-22 06:40:55 +00:00
|
|
|
type="text"
|
2022-03-08 18:23:01 +00:00
|
|
|
autoFocus={true}
|
2022-02-22 06:40:55 +00:00
|
|
|
/>
|
2022-02-28 22:58:34 +00:00
|
|
|
{errors.wallet?.message && (
|
Test/deal ticket tests (#161)
* scaffold dealticket package, remove trading views from react-helpers
* add deal ticket component, add intent utils, expand dialog and form group styles
* add splash component, show market not found message if market doesnt exist
* tidy up error handling
* add handleError method for vega tx hook
* add better testname for provider test, flesh out tests a bit more for deal ticket
* Add unit tests for useVegaTransaction and useOrderSubmit hooks
* add wrapper component for order dialog styles
* add vega styled loader to ui toolkit and use in order dialog
* add title prop to order dialog
* split limit and market tickets into own files
* add button radio component
* revert dialog styles
* move splash component to ui-toolkit, add story
* convert intent to enum
* Make button always type=button unless type prop is passed
* inline filter logic for tif selector
* add date-fns, add datetime to helpers
* add order types to wallet package, make price undefined if order type is market
* use enums in deal ticket logic
* tidy up order state by moving submit and transaction hooks out of deal ticket
* add comment for dialog styles
* remove decimal from price input
* add types package, delete old generated types from trading project
* rename types package to graphql
* update generate command to point to correct locations
* fix use order submit test
* BDD and navigation tests passing
* Remove commented steps
* Steps up to placing order
* Date picker and date-fns update
* Vega connector wallet tests
* Passing up to request sent, updated date picker
* Tests for sell orders and errors
* Update market feature
* Fix failing tests
* Update wallet login
* Readded tx hash assertion and remaining tests
* Add CI wallet import
* Update .github/workflows/cypress.yml
Co-authored-by: Dexter Edwards <dexter.edwards93@gmail.com>
* Resolved PR comments
* Fix yaml error
* Attempt to fix failing tests in CI
* Run Cypress in Chrome
* Add reload if public key error displayed
* Fix wallet name
* Add force click and waits
* Increase timeout for deal ticket page
* Removed network list from yaml and using input error id
* Increase timeout to 8 seconds
* Re add deleted test id
Co-authored-by: Matthew Russell <mattrussell36@gmail.com>
Co-authored-by: Dexter Edwards <dexter.edwards93@gmail.com>
2022-04-04 15:11:27 +00:00
|
|
|
<InputError
|
|
|
|
data-testid="input-wallet-error"
|
|
|
|
intent="danger"
|
|
|
|
className="mt-4"
|
|
|
|
>
|
2022-03-10 23:42:55 +00:00
|
|
|
{errors.wallet.message}
|
|
|
|
</InputError>
|
2022-02-28 22:58:34 +00:00
|
|
|
)}
|
2022-03-08 18:23:01 +00:00
|
|
|
</FormGroup>
|
2022-03-31 01:08:25 +00:00
|
|
|
<FormGroup label={t('Passphrase')} labelFor="passphrase">
|
2022-03-08 18:13:52 +00:00
|
|
|
<Input
|
2022-03-31 01:08:25 +00:00
|
|
|
{...register('passphrase', { required: t('Required') })}
|
2022-03-08 18:23:01 +00:00
|
|
|
id="passphrase"
|
2022-02-28 22:58:34 +00:00
|
|
|
type="password"
|
2022-02-22 06:40:55 +00:00
|
|
|
/>
|
2022-02-28 22:58:34 +00:00
|
|
|
{errors.passphrase?.message && (
|
2022-03-10 23:42:55 +00:00
|
|
|
<InputError intent="danger" className="mt-4">
|
|
|
|
{errors.passphrase.message}
|
|
|
|
</InputError>
|
2022-02-28 22:58:34 +00:00
|
|
|
)}
|
2022-03-08 18:23:01 +00:00
|
|
|
</FormGroup>
|
2022-03-10 23:42:55 +00:00
|
|
|
{error && (
|
|
|
|
<p className="text-intent-danger mb-12" data-testid="form-error">
|
|
|
|
{error}
|
|
|
|
</p>
|
|
|
|
)}
|
2022-03-08 18:13:52 +00:00
|
|
|
<Button variant="primary" type="submit">
|
2022-03-31 01:08:25 +00:00
|
|
|
{t('Connect')}
|
2022-03-08 18:13:52 +00:00
|
|
|
</Button>
|
2022-02-22 06:40:55 +00:00
|
|
|
</form>
|
|
|
|
);
|
|
|
|
}
|