fix(trading): throttle deal ticket submit (#3282)
This commit is contained in:
parent
c3da31146f
commit
4595db07b0
@ -1,6 +1,6 @@
|
|||||||
import { t } from '@vegaprotocol/i18n';
|
import { t } from '@vegaprotocol/i18n';
|
||||||
import * as Schema from '@vegaprotocol/types';
|
import * as Schema from '@vegaprotocol/types';
|
||||||
import { memo, useCallback, useEffect, useState } from 'react';
|
import { memo, useCallback, useEffect, useState, useRef } from 'react';
|
||||||
import { Controller } from 'react-hook-form';
|
import { Controller } from 'react-hook-form';
|
||||||
import { DealTicketAmount } from './deal-ticket-amount';
|
import { DealTicketAmount } from './deal-ticket-amount';
|
||||||
import { DealTicketButton } from './deal-ticket-button';
|
import { DealTicketButton } from './deal-ticket-button';
|
||||||
@ -75,6 +75,8 @@ export const DealTicket = ({
|
|||||||
handleSubmit,
|
handleSubmit,
|
||||||
} = useOrderForm(market.id);
|
} = useOrderForm(market.id);
|
||||||
|
|
||||||
|
const lastSubmitTime = useRef(0);
|
||||||
|
|
||||||
const asset = market.tradableInstrument.instrument.product.settlementAsset;
|
const asset = market.tradableInstrument.instrument.product.settlementAsset;
|
||||||
|
|
||||||
const { accountBalance: marginAccountBalance } = useMarketAccountBalance(
|
const { accountBalance: marginAccountBalance } = useMarketAccountBalance(
|
||||||
@ -146,6 +148,10 @@ export const DealTicket = ({
|
|||||||
|
|
||||||
const onSubmit = useCallback(
|
const onSubmit = useCallback(
|
||||||
(order: OrderSubmission) => {
|
(order: OrderSubmission) => {
|
||||||
|
const now = new Date().getTime();
|
||||||
|
if (lastSubmitTime.current && now - lastSubmitTime.current < 1000) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
submit(
|
submit(
|
||||||
normalizeOrderSubmission(
|
normalizeOrderSubmission(
|
||||||
order,
|
order,
|
||||||
@ -153,6 +159,7 @@ export const DealTicket = ({
|
|||||||
market.positionDecimalPlaces
|
market.positionDecimalPlaces
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
lastSubmitTime.current = now;
|
||||||
},
|
},
|
||||||
[submit, market.decimalPlaces, market.positionDecimalPlaces]
|
[submit, market.decimalPlaces, market.positionDecimalPlaces]
|
||||||
);
|
);
|
||||||
|
Loading…
Reference in New Issue
Block a user