Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/lib/utils/hooks/useCurationLists.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
}
34 changes: 24 additions & 10 deletions src/lib/utils/hooks/useSellerBlacklist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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) {
Expand All @@ -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;
},
{
Expand All @@ -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 &&
Expand All @@ -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,
Expand All @@ -95,6 +106,9 @@ export function useSellerBlacklist(
blacklist.isSuccess,
blacklist.isError,
blacklist.data,
blacklist.isLoading,
blacklist.isFetched,
blacklist.isFetching,
props.allowConnectedSeller
]);
}
3 changes: 3 additions & 0 deletions src/lib/utils/hooks/useSellers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
15 changes: 14 additions & 1 deletion src/pages/create-product/CreateProduct.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -73,8 +75,9 @@ function CreateProduct() {
const [createdOffersIds, setCreatedOffersIds] = useState<string[]>([]);
const [isDraftModalClosed, setDraftModalClosed] = useState<boolean>(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);

Expand Down Expand Up @@ -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 <Loading />;
}

if (!!seller && !isSellerCurated) {
return <NotFound />;
}
Expand Down
Loading