From 014992a2b29b2a04d7ae01aadb38ed82a7ce411a Mon Sep 17 00:00:00 2001 From: r41ph Date: Wed, 8 Jan 2025 13:24:16 +0000 Subject: [PATCH] refactor: optimize getSellOrdersCredits --- .../src/pages/BuyCredits/BuyCredits.Form.tsx | 11 +++-------- .../src/pages/BuyCredits/BuyCredits.utils.tsx | 11 ++++------- 2 files changed, 7 insertions(+), 15 deletions(-) diff --git a/web-marketplace/src/pages/BuyCredits/BuyCredits.Form.tsx b/web-marketplace/src/pages/BuyCredits/BuyCredits.Form.tsx index c3a022ff8b..d52ecf43a1 100644 --- a/web-marketplace/src/pages/BuyCredits/BuyCredits.Form.tsx +++ b/web-marketplace/src/pages/BuyCredits/BuyCredits.Form.tsx @@ -267,19 +267,14 @@ export const BuyCreditsForm = ({ ) => { if (project) { const sellOrders = await refetchSellOrders(); - const creditsInAllSellOrders = getSellOrdersCredits( - sellOrders, - project.id, - ); + const creditsInAllSellOrders = getSellOrdersCredits(sellOrders); const creditsToBuy = data?.creditsAmount; const requestedSellOrders = findMatchingSellOrders( data, sellOrders?.map(normalizeToUISellOrderInfo), ); - const creditsInRequestedSellOrders = getSellOrdersCredits( - requestedSellOrders, - project.id, - ); + const creditsInRequestedSellOrders = + getSellOrdersCredits(requestedSellOrders); const sellCanProceed = creditsToBuy && creditsToBuy <= creditsInRequestedSellOrders; diff --git a/web-marketplace/src/pages/BuyCredits/BuyCredits.utils.tsx b/web-marketplace/src/pages/BuyCredits/BuyCredits.utils.tsx index 7b1c12e0d4..3357012ca1 100644 --- a/web-marketplace/src/pages/BuyCredits/BuyCredits.utils.tsx +++ b/web-marketplace/src/pages/BuyCredits/BuyCredits.utils.tsx @@ -163,15 +163,12 @@ export const getWarningModalContent = ( export const getSellOrdersCredits = ( sellOrders: UISellOrderInfo[] | SellOrderInfoExtented[] | undefined, - projectId: string, ) => { return ( - sellOrders - ?.filter(sellOrder => sellOrder?.batchDenom?.startsWith(projectId)) - .reduce( - (credits, sellOrder) => credits + Number(sellOrder.quantity), - 0, - ) || 0 + sellOrders?.reduce( + (credits, sellOrder) => credits + Number(sellOrder.quantity), + 0, + ) || 0 ); };