fix(deal-ticket): prevent empty call estimate position (#4950)

This commit is contained in:
Maciek 2023-10-02 18:26:10 +02:00 committed by GitHub
parent 8efadda98c
commit 6c5cd85d96
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 3 deletions

View File

@ -264,7 +264,11 @@ export const DealTicket = ({
orders,
collateralAvailable:
marginAccountBalance || generalAccountBalance ? balance : undefined,
skip: !normalizedOrder,
skip:
!normalizedOrder ||
(normalizedOrder.type !== Schema.OrderType.TYPE_MARKET &&
(!normalizedOrder.price || normalizedOrder.price === '0')) ||
normalizedOrder.size === '0',
});
const assetSymbol = getAsset(market).symbol;

View File

@ -30,9 +30,11 @@ export const usePositionEstimate = ({
fetchPolicy: 'no-cache',
});
useEffect(() => {
if (data) {
if (skip) {
setEstimates(undefined);
} else if (data) {
setEstimates(data);
}
}, [data]);
}, [data, skip]);
return estimates;
};