From bc1ee958d6f13dff4825ece5a5b5800f0ceb65ba Mon Sep 17 00:00:00 2001 From: LautaroPetaccio Date: Mon, 23 Dec 2024 15:11:42 -0300 Subject: [PATCH] fix: Check one by one --- src/ports/trades/utils.ts | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/src/ports/trades/utils.ts b/src/ports/trades/utils.ts index dc91d8a..17671f6 100644 --- a/src/ports/trades/utils.ts +++ b/src/ports/trades/utils.ts @@ -57,20 +57,18 @@ export async function isValidEstateTrade(trade: TradeCreation): Promise } const assets = [...trade.sent, ...trade.received] - const areEstatesFingerprintsValid = await Promise.all( - assets.map(async asset => { - // Only check if the asset is an estate - if (asset.contractAddress.toLowerCase() === estateContract.address.toLowerCase()) { - return ( - !isBytesEmpty(asset.extra) && - (await isEstateFingerprintValid(estateContract.address, (asset as ERC721TradeAsset)?.tokenId, trade.chainId, asset.extra)) - ) - } - return true - }) - ) + // Checks trades one by one to prevent unnecessary checks. This should be changed when implementing bundles or the cart system. + for (const asset of assets) { + // Only check if the asset is an estate + if (asset.contractAddress.toLowerCase() === estateContract.address.toLowerCase()) { + return ( + !isBytesEmpty(asset.extra) && + (await isEstateFingerprintValid(estateContract.address, (asset as ERC721TradeAsset)?.tokenId, trade.chainId, asset.extra)) + ) + } + } - return areEstatesFingerprintsValid.every(Boolean) + return true } export async function validateTradeByType(trade: TradeCreation, client: IPgComponent): Promise {