Skip to content

Commit

Permalink
refactor: optimize getSellOrdersCredits
Browse files Browse the repository at this point in the history
  • Loading branch information
r41ph committed Jan 8, 2025
1 parent 953f527 commit 014992a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 15 deletions.
11 changes: 3 additions & 8 deletions web-marketplace/src/pages/BuyCredits/BuyCredits.Form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
11 changes: 4 additions & 7 deletions web-marketplace/src/pages/BuyCredits/BuyCredits.utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
};

Expand Down

0 comments on commit 014992a

Please sign in to comment.