From a4005a91badfea70f883ec944933df8b90e9d676 Mon Sep 17 00:00:00 2001 From: Yuri Date: Wed, 13 Mar 2024 18:03:25 +0100 Subject: [PATCH] don't try to fetch metadatas until we have all uris --- .../src/lib/hooks/use-get-composed-state.ts | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/packages/rmrk-hooks/src/lib/hooks/use-get-composed-state.ts b/packages/rmrk-hooks/src/lib/hooks/use-get-composed-state.ts index 012b9e7..f2d0eb7 100644 --- a/packages/rmrk-hooks/src/lib/hooks/use-get-composed-state.ts +++ b/packages/rmrk-hooks/src/lib/hooks/use-get-composed-state.ts @@ -89,6 +89,8 @@ export const useGetComposedState = ( slotParts, ] = equippableDataResponse || []; + const fixedMetadataUris = fixedParts?.map((p) => p.metadataURI); + const { isLoading: isLoadingFixedPartsMetadatas, isError: isErrorFixedPartsMetadatas, @@ -96,12 +98,16 @@ export const useGetComposedState = ( data: fixedPartsWithMetadatas, } = useFetchMetadataAndAddToEntities( { - metadataUris: fixedParts?.map((p) => p.metadataURI), + metadataUris: fixedMetadataUris, }, - { enabled: enabled && enabledMetadataFetch }, + { enabled: enabled && enabledMetadataFetch && !!fixedMetadataUris }, fixedParts?.map((p) => ({ z: p.z })), ); + const slotMetadataUris = slotParts?.map( + (p) => p.childAssetMetadata || p.partMetadata, + ); + const { isLoading: isLoadingSlotPartsMetadatas, isError: isErrorSlotPartsMetadatas, @@ -109,11 +115,9 @@ export const useGetComposedState = ( data: slotPartsWithMetadatas, } = useFetchMetadataAndAddToEntities( { - metadataUris: slotParts?.map( - (p) => p.childAssetMetadata || p.partMetadata, - ), + metadataUris: slotMetadataUris, }, - { enabled: enabled && enabledMetadataFetch }, + { enabled: enabled && enabledMetadataFetch && !!slotMetadataUris }, slotParts?.map((p) => ({ z: p.z })), );