fix(trading): order stopped misleading message (#4455)

This commit is contained in:
m.ray 2023-08-02 13:52:07 +03:00 committed by GitHub
parent 45283161aa
commit fde49e5446
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 230 additions and 213 deletions

View File

@ -7,7 +7,8 @@ import {
} from './utils'; } from './utils';
import * as Types from '@vegaprotocol/types'; import * as Types from '@vegaprotocol/types';
describe('getOrderToastTitle', () => { describe('WithdrawalsTable', () => {
describe('getOrderToastTitle', () => {
it('should return the correct title', () => { it('should return the correct title', () => {
expect(getOrderToastTitle(Types.OrderStatus.STATUS_ACTIVE)).toBe( expect(getOrderToastTitle(Types.OrderStatus.STATUS_ACTIVE)).toBe(
'Order submitted' 'Order submitted'
@ -15,9 +16,9 @@ describe('getOrderToastTitle', () => {
expect(getOrderToastTitle(Types.OrderStatus.STATUS_FILLED)).toBe( expect(getOrderToastTitle(Types.OrderStatus.STATUS_FILLED)).toBe(
'Order filled' 'Order filled'
); );
expect(getOrderToastTitle(Types.OrderStatus.STATUS_PARTIALLY_FILLED)).toBe( expect(
'Order partially filled' getOrderToastTitle(Types.OrderStatus.STATUS_PARTIALLY_FILLED)
); ).toBe('Order partially filled');
expect(getOrderToastTitle(Types.OrderStatus.STATUS_PARKED)).toBe( expect(getOrderToastTitle(Types.OrderStatus.STATUS_PARKED)).toBe(
'Order parked' 'Order parked'
); );
@ -35,9 +36,9 @@ describe('getOrderToastTitle', () => {
); );
expect(getOrderToastTitle(undefined)).toBe(undefined); expect(getOrderToastTitle(undefined)).toBe(undefined);
}); });
}); });
describe('getOrderToastIntent', () => { describe('getOrderToastIntent', () => {
it('should return the correct intent', () => { it('should return the correct intent', () => {
expect(getOrderToastIntent(Types.OrderStatus.STATUS_PARKED)).toBe( expect(getOrderToastIntent(Types.OrderStatus.STATUS_PARKED)).toBe(
Intent.Warning Intent.Warning
@ -45,14 +46,14 @@ describe('getOrderToastIntent', () => {
expect(getOrderToastIntent(Types.OrderStatus.STATUS_EXPIRED)).toBe( expect(getOrderToastIntent(Types.OrderStatus.STATUS_EXPIRED)).toBe(
Intent.Warning Intent.Warning
); );
expect(getOrderToastIntent(Types.OrderStatus.STATUS_PARTIALLY_FILLED)).toBe( expect(
Intent.Warning getOrderToastIntent(Types.OrderStatus.STATUS_PARTIALLY_FILLED)
); ).toBe(Intent.Warning);
expect(getOrderToastIntent(Types.OrderStatus.STATUS_REJECTED)).toBe( expect(getOrderToastIntent(Types.OrderStatus.STATUS_REJECTED)).toBe(
Intent.Danger Intent.Danger
); );
expect(getOrderToastIntent(Types.OrderStatus.STATUS_STOPPED)).toBe( expect(getOrderToastIntent(Types.OrderStatus.STATUS_STOPPED)).toBe(
Intent.Danger Intent.Warning
); );
expect(getOrderToastIntent(Types.OrderStatus.STATUS_FILLED)).toBe( expect(getOrderToastIntent(Types.OrderStatus.STATUS_FILLED)).toBe(
Intent.Success Intent.Success
@ -65,9 +66,9 @@ describe('getOrderToastIntent', () => {
); );
expect(getOrderToastIntent(undefined)).toBe(undefined); expect(getOrderToastIntent(undefined)).toBe(undefined);
}); });
}); });
describe('getRejectionReason', () => { describe('getRejectionReason', () => {
it('should return the correct rejection reason for insufficient asset balance', () => { it('should return the correct rejection reason for insufficient asset balance', () => {
expect( expect(
getRejectionReason({ getRejectionReason({
@ -102,9 +103,9 @@ describe('getRejectionReason', () => {
'Your Fill or Kill (FOK) order was not filled and it has been stopped' 'Your Fill or Kill (FOK) order was not filled and it has been stopped'
); );
}); });
}); });
describe('timeInForceLabel', () => { describe('timeInForceLabel', () => {
it('should return the correct label for time in force', () => { it('should return the correct label for time in force', () => {
expect(timeInForceLabel(Types.OrderTimeInForce.TIME_IN_FORCE_FOK)).toBe( expect(timeInForceLabel(Types.OrderTimeInForce.TIME_IN_FORCE_FOK)).toBe(
`Fill or Kill (FOK)` `Fill or Kill (FOK)`
@ -126,4 +127,5 @@ describe('timeInForceLabel', () => {
); );
expect(timeInForceLabel('')).toBe(''); expect(timeInForceLabel('')).toBe('');
}); });
});
}); });

View File

@ -36,7 +36,7 @@ export const getRejectionReason = (
default: default:
return order.rejectionReason return order.rejectionReason
? t(Schema.OrderRejectionReasonMapping[order.rejectionReason]) ? t(Schema.OrderRejectionReasonMapping[order.rejectionReason])
: null; : '';
} }
}; };
@ -79,9 +79,9 @@ export const getOrderToastIntent = (
case Schema.OrderStatus.STATUS_PARKED: case Schema.OrderStatus.STATUS_PARKED:
case Schema.OrderStatus.STATUS_EXPIRED: case Schema.OrderStatus.STATUS_EXPIRED:
case Schema.OrderStatus.STATUS_PARTIALLY_FILLED: case Schema.OrderStatus.STATUS_PARTIALLY_FILLED:
case Schema.OrderStatus.STATUS_STOPPED:
return Intent.Warning; return Intent.Warning;
case Schema.OrderStatus.STATUS_REJECTED: case Schema.OrderStatus.STATUS_REJECTED:
case Schema.OrderStatus.STATUS_STOPPED:
return Intent.Danger; return Intent.Danger;
case Schema.OrderStatus.STATUS_FILLED: case Schema.OrderStatus.STATUS_FILLED:
case Schema.OrderStatus.STATUS_ACTIVE: case Schema.OrderStatus.STATUS_ACTIVE:

View File

@ -52,6 +52,7 @@ import type { Side } from '@vegaprotocol/types';
import { OrderStatusMapping } from '@vegaprotocol/types'; import { OrderStatusMapping } from '@vegaprotocol/types';
import { Size } from '@vegaprotocol/datagrid'; import { Size } from '@vegaprotocol/datagrid';
import { useWithdrawalApprovalDialog } from './withdrawal-approval-dialog'; import { useWithdrawalApprovalDialog } from './withdrawal-approval-dialog';
import * as Schema from '@vegaprotocol/types';
const intentMap: { [s in VegaTxStatus]: Intent } = { const intentMap: { [s in VegaTxStatus]: Intent } = {
Default: Intent.Primary, Default: Intent.Primary,
@ -508,17 +509,27 @@ const VegaTxCompleteToastsContent = ({ tx }: VegaTxToastContentProps) => {
} }
if (tx.order && tx.order.rejectionReason) { if (tx.order && tx.order.rejectionReason) {
const rejectionReason = const rejectionReason = getRejectionReason(tx.order);
getRejectionReason(tx.order) || tx.order.rejectionReason || '';
return ( return (
<> <>
<ToastHeading>{getOrderToastTitle(tx.order.status)}</ToastHeading> <ToastHeading>{getOrderToastTitle(tx.order.status)}</ToastHeading>
{rejectionReason ? ( {rejectionReason ? (
<p> <p>
{t('Your order has been rejected because: %s', [rejectionReason])} {t('Your order has been %s because: %s', [
tx.order.status === Schema.OrderStatus.STATUS_STOPPED
? 'stopped'
: 'rejected',
rejectionReason,
])}
</p> </p>
) : ( ) : (
<p>{t('Your order has been rejected.')}</p> <p>
{t('Your order has been %s.', [
tx.order.status === Schema.OrderStatus.STATUS_STOPPED
? 'stopped'
: 'rejected',
])}
</p>
)} )}
{tx.txHash && ( {tx.txHash && (
<p className="break-all"> <p className="break-all">

View File

@ -18,7 +18,8 @@ const generateJsx = (props: TypedDataAgGrid<WithdrawalFieldsFragment>) => (
</MockedProvider> </MockedProvider>
); );
describe('renders the correct columns', () => { describe('Withdrawals', () => {
describe('renders the correct columns', () => {
it('incomplete withdrawal', async () => { it('incomplete withdrawal', async () => {
const withdrawal = generateWithdrawal(); const withdrawal = generateWithdrawal();
await act(async () => { await act(async () => {
@ -69,7 +70,9 @@ describe('renders the correct columns', () => {
'1.00', '1.00',
'123456…123456', '123456…123456',
getTimeFormat().format(new Date(withdrawal.createdTimestamp as string)), getTimeFormat().format(new Date(withdrawal.createdTimestamp as string)),
getTimeFormat().format(new Date(withdrawal.withdrawnTimestamp as string)), getTimeFormat().format(
new Date(withdrawal.withdrawnTimestamp as string)
),
'Completed', 'Completed',
'0x1234…121314', '0x1234…121314',
]; ];
@ -77,9 +80,9 @@ describe('renders the correct columns', () => {
expect(cell).toHaveTextContent(expectedValues[i]); expect(cell).toHaveTextContent(expectedValues[i]);
}); });
}); });
}); });
describe('StatusCell', () => { describe('StatusCell', () => {
let props: { data: WithdrawalFieldsFragment }; let props: { data: WithdrawalFieldsFragment };
let withdrawal: WithdrawalFieldsFragment; let withdrawal: WithdrawalFieldsFragment;
@ -123,4 +126,5 @@ describe('StatusCell', () => {
expect(screen.getByText('Rejected')).toBeInTheDocument(); expect(screen.getByText('Rejected')).toBeInTheDocument();
}); });
});
}); });