- {t(
- 'Your order has been rejected because: %s',
- getRejectionReason(tx.order) || ''
- )}
-
+ {rejectionReason ? (
+
+ {t('Your order has been rejected because: %s', [rejectionReason])}
+
+ ) : (
+
{t('Your order has been rejected.')}
+ )}
{tx.txHash && (
{
walletNoConnectionCodes.includes(tx.error.code);
if (orderRejection) {
label = t('Order rejected');
- errorMessage = t(
- 'Your order has been rejected because: %s',
- orderRejection
- );
+ errorMessage = t('Your order has been rejected because: %s', [
+ orderRejection,
+ ]);
}
if (walletError) {
label = t('Wallet disconnected');
diff --git a/libs/deal-ticket/src/components/deal-ticket/deal-ticket.spec.tsx b/libs/deal-ticket/src/components/deal-ticket/deal-ticket.spec.tsx
index 71b99cf2b..8b1403c70 100644
--- a/libs/deal-ticket/src/components/deal-ticket/deal-ticket.spec.tsx
+++ b/libs/deal-ticket/src/components/deal-ticket/deal-ticket.spec.tsx
@@ -107,6 +107,50 @@ describe('DealTicket', () => {
);
});
+ it('should use local storage state for initial values reduceOnly and postOnly', () => {
+ const expectedOrder = {
+ marketId: market.id,
+ type: Schema.OrderType.TYPE_LIMIT,
+ side: Schema.Side.SIDE_SELL,
+ size: '0.1',
+ price: '300.22',
+ timeInForce: Schema.OrderTimeInForce.TIME_IN_FORCE_IOC,
+ persist: true,
+ reduceOnly: true,
+ postOnly: false,
+ };
+
+ useOrderStore.setState({
+ orders: {
+ [expectedOrder.marketId]: expectedOrder,
+ },
+ });
+
+ render(generateJsx());
+
+ // Assert correct defaults are used from store
+ expect(
+ screen
+ .getByTestId(`order-type-${Schema.OrderType.TYPE_LIMIT}`)
+ .querySelector('input')
+ ).toBeChecked();
+ expect(
+ screen.queryByTestId('order-side-SIDE_SELL')?.querySelector('input')
+ ).toBeChecked();
+ expect(
+ screen.queryByTestId('order-side-SIDE_BUY')?.querySelector('input')
+ ).not.toBeChecked();
+ expect(screen.getByTestId('order-size')).toHaveDisplayValue(
+ expectedOrder.size
+ );
+ expect(screen.getByTestId('order-tif')).toHaveValue(
+ expectedOrder.timeInForce
+ );
+ expect(screen.getByTestId('order-price')).toHaveDisplayValue(
+ expectedOrder.price
+ );
+ });
+
it('handles TIF select box dependent on order type', async () => {
render(generateJsx());
diff --git a/libs/deal-ticket/src/components/deal-ticket/deal-ticket.tsx b/libs/deal-ticket/src/components/deal-ticket/deal-ticket.tsx
index 8b6779123..e784f293c 100644
--- a/libs/deal-ticket/src/components/deal-ticket/deal-ticket.tsx
+++ b/libs/deal-ticket/src/components/deal-ticket/deal-ticket.tsx
@@ -1,6 +1,6 @@
import { t } from '@vegaprotocol/i18n';
import * as Schema from '@vegaprotocol/types';
-import { memo, useCallback, useEffect, useState, useRef } from 'react';
+import { memo, useCallback, useEffect, useState, useRef, useMemo } from 'react';
import { Controller } from 'react-hook-form';
import { DealTicketAmount } from './deal-ticket-amount';
import { DealTicketButton } from './deal-ticket-button';
@@ -16,10 +16,12 @@ import {
useVegaWalletDialogStore,
} from '@vegaprotocol/wallet';
import {
+ Checkbox,
ExternalLink,
InputError,
Intent,
Notification,
+ Tooltip,
TinyScroll,
} from '@vegaprotocol/ui-toolkit';
@@ -146,6 +148,16 @@ export const DealTicket = ({
clearErrors,
]);
+ const disablePostOnlyCheckbox = useMemo(() => {
+ const disabled = order
+ ? [
+ Schema.OrderTimeInForce.TIME_IN_FORCE_IOC,
+ Schema.OrderTimeInForce.TIME_IN_FORCE_FOK,
+ ].includes(order.timeInForce)
+ : true;
+ return disabled;
+ }, [order]);
+
const onSubmit = useCallback(
(order: OrderSubmission) => {
const now = new Date().getTime();
@@ -239,7 +251,7 @@ export const DealTicket = ({
value={order.timeInForce}
orderType={order.type}
onSelect={(timeInForce) => {
- update({ timeInForce });
+ update({ timeInForce, postOnly: false, reduceOnly: false });
// Set tif value for the given order type, so that when switching
// types we know the last used TIF for the given order type
setLastTIF((curr) => ({
@@ -276,6 +288,65 @@ export const DealTicket = ({
)}
/>
)}
+
+ (
+ {
+ update({ postOnly: !order.postOnly, reduceOnly: false });
+ }}
+ label={
+
+ {disablePostOnlyCheckbox
+ ? t(
+ '"Post only" can not be used on "Fill or Kill" or "Immediate or Cancel" orders.'
+ )
+ : t(
+ '"Post only" will ensure the order is not filled immediately but is placed on the order book as a passive order. When the order is processed it is either stopped (if it would not be filled immediately), or placed in the order book as a passive order until the price taker matches with it.'
+ )}
+
+ }
+ >
+ {t('Post only')}
+
+ }
+ />
+ )}
+ />
+ (
+ {
+ update({ postOnly: false, reduceOnly: !order.reduceOnly });
+ }}
+ label={
+
+ {t(
+ '"Reduce only" will ensure that this order will not increase the size of an open position. When the order is matched, it will only trade enough volume to bring your open volume towards 0 but never change the direction of your position. If applied to a limit order that is not instantly filled, the order will be stopped.'
+ )}
+
+ }
+ >
+ {t('Reduce only')}
+
+ }
+ />
+ )}
+ />
+