feat: reselct field so that GTC is default on limit (#995)

* feat: reselct field so that GTC is default on limit

* feat: set value when switching order type

* fix: deal ticket test

* fix: revert TIF selector file
This commit is contained in:
m.ray 2022-08-10 14:45:36 +02:00 committed by GitHub
parent 24a20f48e1
commit 1a1ab4db65
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 3 deletions

2
.gitignore vendored
View File

@ -21,7 +21,7 @@
# IDE - VSCode
.vscode/*
!.vscode/settings.json
.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json

View File

@ -163,7 +163,7 @@ describe('DealTicket', () => {
// Change back to limit and check we are still on FOK
fireEvent.click(screen.getByTestId('order-type-TYPE_LIMIT'));
expect(screen.getByTestId('order-tif')).toHaveValue(
VegaWalletOrderTimeInForce.FOK
VegaWalletOrderTimeInForce.GTC
);
});
});

View File

@ -39,6 +39,7 @@ export const DealTicket = ({
handleSubmit,
watch,
formState: { errors },
setValue,
} = useForm<Order>({
mode: 'onChange',
defaultValues: getDefaultOrder(market),
@ -71,7 +72,17 @@ export const DealTicket = ({
name="type"
control={control}
render={({ field }) => (
<TypeSelector value={field.value} onSelect={field.onChange} />
<TypeSelector
value={field.value}
onSelect={(type) => {
if (type === VegaWalletOrderType.Limit) {
setValue('timeInForce', VegaWalletOrderTimeInForce.GTC);
} else {
setValue('timeInForce', VegaWalletOrderTimeInForce.IOC);
}
field.onChange(type);
}}
/>
)}
/>
<Controller