Skip to content

Commit

Permalink
Display gate modal only for standalone dapp
Browse files Browse the repository at this point in the history
  • Loading branch information
r-czajkowski committed Oct 31, 2024
1 parent a1bb763 commit 3657727
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions dapp/src/hooks/useGatingDApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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])
}

0 comments on commit 3657727

Please sign in to comment.