diff --git a/src/lib/utils/hooks/useCurationLists.ts b/src/lib/utils/hooks/useCurationLists.ts index cd75fba04..a166549a9 100644 --- a/src/lib/utils/hooks/useCurationLists.ts +++ b/src/lib/utils/hooks/useCurationLists.ts @@ -47,6 +47,10 @@ export function useCurationLists() { : CONFIG.enableCurationLists ? CONFIG.offerCurationList : undefined, - isError: sellerBlacklist.isError + isError: sellerBlacklist.isError, + isLoading: sellerBlacklist.isLoading, + isFetched: sellerBlacklist.isFetched, + isFetching: sellerBlacklist.isFetching, + lastSellerIdFetched: sellerBlacklist.lastSellerIdFetched }; } diff --git a/src/lib/utils/hooks/useSellerBlacklist.ts b/src/lib/utils/hooks/useSellerBlacklist.ts index 700faee0a..f4d2c49c9 100644 --- a/src/lib/utils/hooks/useSellerBlacklist.ts +++ b/src/lib/utils/hooks/useSellerBlacklist.ts @@ -17,6 +17,10 @@ export function useSellerBlacklist( ): { isSuccess: boolean; isError: boolean; + isLoading: boolean; + isFetched: boolean; + isFetching: boolean; + lastSellerIdFetched: string | undefined; curatedSellerIds: string[] | undefined; } { const { config } = useConfigContext(); @@ -27,11 +31,13 @@ export function useSellerBlacklist( ["all-sellers", props, subgraphUrl], async () => { const maxSellerPerReq = 1000; - const fetched = await accounts.subgraph.getSellers(subgraphUrl, { - sellersFirst: maxSellerPerReq, - sellersOrderBy: subgraph.Seller_OrderBy.SELLERID, - sellersOrderDirection: subgraph.OrderDirection.ASC - }); + const fetched = ( + await accounts.subgraph.getSellers(subgraphUrl, { + sellersFirst: maxSellerPerReq, + sellersOrderBy: subgraph.Seller_OrderBy.SELLERID, + sellersOrderDirection: subgraph.OrderDirection.ASC + }) + ).map((seller) => seller.id); let loop = fetched.length === maxSellerPerReq; let sellersSkip = maxSellerPerReq; while (loop) { @@ -41,10 +47,11 @@ export function useSellerBlacklist( sellersOrderBy: subgraph.Seller_OrderBy.SELLERID, sellersOrderDirection: subgraph.OrderDirection.ASC }); - fetched.push(...toAdd); + fetched.push(...toAdd.map((seller) => seller.id)); loop = toAdd.length === maxSellerPerReq; sellersSkip += maxSellerPerReq; } + return fetched; }, { @@ -71,9 +78,9 @@ export function useSellerBlacklist( return useMemo(() => { const sellerIdList = blacklist.isSuccess && blacklist.data && allSellers.isSuccess - ? allSellers.data - .filter((seller) => !blacklist.data?.includes(seller.id)) - .map((seller) => seller.id) + ? allSellers.data.filter( + (sellerId) => !blacklist.data?.includes(sellerId) + ) : []; if ( props.allowConnectedSeller && @@ -86,7 +93,11 @@ export function useSellerBlacklist( return { isSuccess: blacklist.isSuccess, isError: blacklist.isError, - curatedSellerIds: sellerIdList + curatedSellerIds: sellerIdList, + isLoading: blacklist.isLoading, + isFetched: blacklist.isFetched, + isFetching: blacklist.isFetching, + lastSellerIdFetched: allSellers.data?.at(-1) }; }, [ allSellers, @@ -95,6 +106,9 @@ export function useSellerBlacklist( blacklist.isSuccess, blacklist.isError, blacklist.data, + blacklist.isLoading, + blacklist.isFetched, + blacklist.isFetching, props.allowConnectedSeller ]); } diff --git a/src/lib/utils/hooks/useSellers.ts b/src/lib/utils/hooks/useSellers.ts index 55d974205..1174e920a 100644 --- a/src/lib/utils/hooks/useSellers.ts +++ b/src/lib/utils/hooks/useSellers.ts @@ -20,6 +20,9 @@ export const useSellerCurationListFn = () => { const isSellerInCurationList = useCallback( (sellerID: string) => { + if (curationLists?.isLoading) { + return undefined; + } if (curationLists?.sellerCurationList && sellerID !== "") { return curationLists.sellerCurationList.includes(sellerID as string); } else if (!curationLists?.enableCurationLists) { diff --git a/src/pages/create-product/CreateProduct.tsx b/src/pages/create-product/CreateProduct.tsx index 0b3aa712c..3089b1850 100644 --- a/src/pages/create-product/CreateProduct.tsx +++ b/src/pages/create-product/CreateProduct.tsx @@ -1,8 +1,10 @@ import * as Sentry from "@sentry/browser"; import { useConfigContext } from "components/config/ConfigContext"; import Button from "components/ui/Button"; +import Loading from "components/ui/Loading"; import { BosonRoutes } from "lib/routing/routes"; import { removeItemInStorage } from "lib/utils/hooks/localstorage/useLocalStorage"; +import { useCurationLists } from "lib/utils/hooks/useCurationLists"; import { useKeepQueryParamsNavigate } from "lib/utils/hooks/useKeepQueryParamsNavigate"; import { useCallback, useEffect, useMemo, useState } from "react"; import { ErrorBoundary } from "react-error-boundary"; @@ -73,8 +75,9 @@ function CreateProduct() { const [createdOffersIds, setCreatedOffersIds] = useState([]); const [isDraftModalClosed, setDraftModalClosed] = useState(false); const { showModal, modalTypes, hideModal } = useModal(); - const { sellers } = useCurrentSellers(); + const { sellers, isLoading: sellersLoading } = useCurrentSellers(); const seller = sellers?.[0]; + const curationLists = useCurationLists(); const checkIfSellerIsInCurationList = useSellerCurationListFn(); const isSellerCurated = !!seller && checkIfSellerIsInCurationList(seller.id); @@ -147,6 +150,16 @@ function CreateProduct() { // eslint-disable-next-line react-hooks/exhaustive-deps }, [createdOffersIds, removeLandingQueryParams, nextStepResult]); + if ( + sellersLoading || + curationLists.isFetching || + (curationLists.lastSellerIdFetched !== undefined && + seller && + Number(curationLists.lastSellerIdFetched) < Number(seller.id)) + ) { + return ; + } + if (!!seller && !isSellerCurated) { return ; }