From 26493ca9d587b175b9e2cb4bc07096074e8fa9aa Mon Sep 17 00:00:00 2001 From: Madalina Raicu Date: Thu, 2 Mar 2023 19:52:50 +0000 Subject: [PATCH] fix: unsubscribe from watch order input --- .../components/deal-ticket/deal-ticket.tsx | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) 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 6f2d39d66..f72e2535b 100644 --- a/libs/deal-ticket/src/components/deal-ticket/deal-ticket.tsx +++ b/libs/deal-ticket/src/components/deal-ticket/deal-ticket.tsx @@ -37,6 +37,7 @@ import { usePersistedOrderStoreSubscription, } from '@vegaprotocol/orders'; import { OrderType } from '@vegaprotocol/types'; +import isNumber from 'lodash/isNumber'; export type TransactionStatus = 'default' | 'pending'; @@ -82,14 +83,17 @@ export const DealTicket = ({ const order = watch(); - watch((orderData) => { - const persistable = !( - orderData.type === OrderType.TYPE_LIMIT && orderData.price === '' - ); - if (persistable) { - setPersistedOrder(orderData as DealTicketFormFields); - } - }); + useEffect(() => { + const { unsubscribe } = watch((orderData) => { + const persistable = !( + orderData.type === OrderType.TYPE_LIMIT && orderData.price === '' + ); + if (persistable) { + setPersistedOrder(orderData as DealTicketFormFields); + } + }); + return () => unsubscribe(); + }, [setPersistedOrder, watch]); usePersistedOrderStoreSubscription(market.id, (storedOrder) => { if (order.price !== storedOrder.price) {