diff --git a/dapp/src/hooks/useGatingDApp.ts b/dapp/src/hooks/useGatingDApp.ts index 033d323b3..8a375c9b5 100644 --- a/dapp/src/hooks/useGatingDApp.ts +++ b/dapp/src/hooks/useGatingDApp.ts @@ -5,9 +5,11 @@ import { useQuery } from "@tanstack/react-query" import { acreApi } from "#/utils" import { useModal } from "./useModal" import useAccessCode from "./useAccessCode" +import useIsEmbed from "./useIsEmbed" export default function useGatingDApp() { const { encodedCode } = useAccessCode() + const { isEmbed } = useIsEmbed() const { openModal, closeModal, modalType } = useModal() const isMounted = useRef(false) const { data: isValid, isLoading } = useQuery({ @@ -17,26 +19,27 @@ export default function useGatingDApp() { }) useEffect(() => { - if (!featureFlags.GATING_DAPP_ENABLED) return - - // TODO: Add condition only for the standalone dApp - // if (!encodedCode && !sEmbed) return - if (!encodedCode) return + if (!featureFlags.GATING_DAPP_ENABLED || isEmbed || !encodedCode) return if (modalType === MODAL_TYPES.LOADING && !isLoading) { closeModal() if (!isValid) openModal(MODAL_TYPES.GATE) } - }, [closeModal, isValid, encodedCode, isLoading, modalType, openModal]) + }, [ + closeModal, + isValid, + encodedCode, + isLoading, + modalType, + openModal, + isEmbed, + ]) useEffect(() => { - if (!featureFlags.GATING_DAPP_ENABLED) return - - // TODO: Add condition only for the standalone dApp - // if (isMounted.current && !sEmbed) return - if (isMounted.current) return + if (!featureFlags.GATING_DAPP_ENABLED || isEmbed || isMounted.current) + return isMounted.current = true openModal(encodedCode ? MODAL_TYPES.LOADING : MODAL_TYPES.GATE) - }, [encodedCode, openModal]) + }, [encodedCode, openModal, isEmbed]) }